diff --git a/base/timing.jl b/base/timing.jl index e229fbeb328e91..157fe288b9708f 100644 --- a/base/timing.jl +++ b/base/timing.jl @@ -164,6 +164,16 @@ function timev_print(elapsedtime, diff::GC_Diff, compile_time) padded_nonzero_print(diff.full_sweep, "full collections") end +# Like a try-finally block, except without introducing the try scope +# NOTE: This is deprecated and should not be used from user logic. A proper solution to +# this problem will be introduced in https://github.com/JuliaLang/julia/pull/39217 +macro __tryfinally(ex, fin) + Expr(:tryfinally, + :($(esc(ex))), + :($(esc(fin))) + ) +end + """ @time @@ -207,9 +217,10 @@ macro time(ex) local stats = gc_num() local elapsedtime = time_ns() local compile_elapsedtime = cumulative_compile_time_ns_before() - local val = $(esc(ex)) - compile_elapsedtime = cumulative_compile_time_ns_after() - compile_elapsedtime - elapsedtime = time_ns() - elapsedtime + local val = @__tryfinally($(esc(ex)), + (elapsedtime = time_ns() - elapsedtime; + compile_elapsedtime = cumulative_compile_time_ns_after() - compile_elapsedtime) + ) local diff = GC_Diff(gc_num(), stats) time_print(elapsedtime, diff.allocd, diff.total_time, gc_alloc_count(diff), compile_elapsedtime, true) val @@ -253,9 +264,10 @@ macro timev(ex) local stats = gc_num() local elapsedtime = time_ns() local compile_elapsedtime = cumulative_compile_time_ns_before() - local val = $(esc(ex)) - compile_elapsedtime = cumulative_compile_time_ns_after() - compile_elapsedtime - elapsedtime = time_ns() - elapsedtime + local val = @__tryfinally($(esc(ex)), + (elapsedtime = time_ns() - elapsedtime; + compile_elapsedtime = cumulative_compile_time_ns_after() - compile_elapsedtime) + ) local diff = GC_Diff(gc_num(), stats) timev_print(elapsedtime, diff, compile_elapsedtime) val diff --git a/src/task.c b/src/task.c index 52cd2dfc5bcbae..d7dda74f3ac99a 100644 --- a/src/task.c +++ b/src/task.c @@ -560,12 +560,6 @@ static void JL_NORETURN throw_internal(jl_task_t *ct, jl_value_t *exception JL_M assert(!jl_get_safe_restore()); jl_ptls_t ptls = ct->ptls; ptls->io_wait = 0; - // @time needs its compile timer disabled on error, - // and cannot use a try-finally as it would break scope for assignments - // We blindly disable compilation time tracking here, for all running Tasks, even though - // it may cause some incorrect measurements. This is a known bug, and is being tracked - // here: https://github.com/JuliaLang/julia/pull/39138 - jl_atomic_store_relaxed(&jl_measure_compile_time_enabled, 0); JL_GC_PUSH1(&exception); jl_gc_unsafe_enter(ptls); if (exception) {