diff --git a/src/gf.c b/src/gf.c index d220ad057176a..db86a8fa4d093 100644 --- a/src/gf.c +++ b/src/gf.c @@ -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 diff --git a/test/cmdlineargs.jl b/test/cmdlineargs.jl index 5df174694049d..577fd934a75a0 100644 --- a/test/cmdlineargs.jl +++ b/test/cmdlineargs.jl @@ -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("precompile(", _stderr)) == 5 + @test length(findall(" # recompile", _stderr)) == 1 + end + # --trace-dispatch let io = IOBuffer()