Skip to content

Commit

Permalink
don't report only-inferred methods as recompiles
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth committed Dec 28, 2024
1 parent b4e4ba7 commit 8152312
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/gf.c
Original file line number Diff line number Diff line change
Expand Up @@ -2863,7 +2863,13 @@ jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *mi, size_t

// Everything from here on is considered (user facing) compile time
uint64_t start = jl_typeinf_timing_begin();
int is_recompile = jl_atomic_load_relaxed(&mi->cache) != NULL;

// Is a recompile if there is cached code, and it was compiled (not only inferred) before
int is_recompile = 0;
jl_code_instance_t *codeinst_old = jl_atomic_load_relaxed(&mi->cache);
if ((codeinst_old != NULL) && (jl_atomic_load_relaxed(&codeinst_old->invoke) != NULL)) {
is_recompile = 1;
}

// This codeinst hasn't been previously inferred do that now
// jl_type_infer will internally do a cache lookup and jl_engine_reserve call
Expand Down
20 changes: 20 additions & 0 deletions test/cmdlineargs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,26 @@ let exename = `$(Base.julia_cmd()) --startup-file=no --color=no`
@test occursin(" ms =# precompile(Tuple{typeof(Main.foo), Int", _stderr)
end

# Base.@trace_compile (local version of the 2 above args)
let
io = IOBuffer()
v = writereadpipeline(
"""
f(x::Int) = 1
applyf(container) = f(container[1])
Base.@trace_compile @eval applyf([100])
Base.@trace_compile @eval applyf(Any[100])
f(::Bool) = 2
Base.@trace_compile @eval applyf([true])
Base.@trace_compile @eval applyf(Any[true])
""",
`$exename -i`,
stderr=io)
_stderr = String(take!(io))
@test length(findall(r"precompile\(", _stderr)) == 5
@test length(findall(r" # recompile", _stderr)) == 1
end

# --trace-dispatch
let
io = IOBuffer()
Expand Down

0 comments on commit 8152312

Please sign in to comment.