From 40a9f6cfff62a1fcb2a5dd37049190015759acb8 Mon Sep 17 00:00:00 2001 From: Pete Vilter Date: Fri, 18 Nov 2022 00:18:21 -0500 Subject: [PATCH] Adapt SnoopPrecompile to work for new julia API. Starting in https://github.com/JuliaLang/julia/pull/47615, we are changing the API for snoopi_deep, to allow for thread safe snooping in one thread while compiling in another. This commit changes SnoopPrecompile to work with the new API if it's available. Co-Authored-By: Pete Vilter --- SnoopPrecompile/src/SnoopPrecompile.jl | 32 ++++++++++++++++++-------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/SnoopPrecompile/src/SnoopPrecompile.jl b/SnoopPrecompile/src/SnoopPrecompile.jl index d0dcd6b3..eaf2d38b 100644 --- a/SnoopPrecompile/src/SnoopPrecompile.jl +++ b/SnoopPrecompile/src/SnoopPrecompile.jl @@ -5,6 +5,7 @@ export @precompile_all_calls, @precompile_setup const verbose = Ref(false) # if true, prints all the precompiles const have_inference_tracking = isdefined(Core.Compiler, :__set_measure_typeinf) const have_force_compile = isdefined(Base, :Experimental) && isdefined(Base.Experimental, Symbol("#@force_compile")) +const have_clear_and_fetch_timings = isdefined(Core.Compiler.Timings, :clear_and_fetch_timings) function precompile_roots(roots) @assert have_inference_tracking @@ -59,16 +60,29 @@ macro precompile_all_calls(ex::Expr) end end if have_inference_tracking - ex = quote - Core.Compiler.Timings.reset_timings() - Core.Compiler.__set_measure_typeinf(true) - try - $ex - finally - Core.Compiler.__set_measure_typeinf(false) - Core.Compiler.Timings.close_current_timer() + if have_clear_and_fetch_timings + # use new thread-safe timings API if it's available in this version of Julia + ex = quote + Core.Compiler.__set_measure_typeinf(true) + try + $ex + finally + Core.Compiler.__set_measure_typeinf(false) + end + $SnoopPrecompile.precompile_roots(Core.Compiler.Timings.clear_and_fetch_timings()) + end + else + ex = quote + Core.Compiler.Timings.reset_timings() + Core.Compiler.__set_measure_typeinf(true) + try + $ex + finally + Core.Compiler.__set_measure_typeinf(false) + Core.Compiler.Timings.close_current_timer() + end + $SnoopPrecompile.precompile_roots(Core.Compiler.Timings._timings[1].children) end - $SnoopPrecompile.precompile_roots(Core.Compiler.Timings._timings[1].children) end end return esc(quote