From 0e5757497cde5088e03bd07a3f5b2d413fff352c Mon Sep 17 00:00:00 2001 From: Ian Date: Thu, 7 Jan 2021 11:06:36 -0500 Subject: [PATCH 1/3] remove compile time disable from throw_local --- src/task.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/task.c b/src/task.c index 0ab4075ac0067..0927b685cb5ce 100644 --- a/src/task.c +++ b/src/task.c @@ -584,9 +584,6 @@ static void JL_NORETURN throw_internal(jl_value_t *exception JL_MAYBE_UNROOTED) { jl_ptls_t ptls = jl_get_ptls_states(); 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 - jl_measure_compile_time[ptls->tid] = 0; if (ptls->safe_restore) jl_longjmp(*ptls->safe_restore, 1); // During startup From 893a4192dac19571f3d7bce5e7e15e04ea26a468 Mon Sep 17 00:00:00 2001 From: Ian Date: Thu, 7 Jan 2021 11:10:39 -0500 Subject: [PATCH 2/3] add tryfinally macro --- base/timing.jl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/base/timing.jl b/base/timing.jl index 976bda7962676..4d290fa855051 100644 --- a/base/timing.jl +++ b/base/timing.jl @@ -164,6 +164,14 @@ 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 +macro tryfinally(ex, fin) + Expr(:tryfinally, + :($(esc(ex))), + :($(esc(fin))) + ) +end + """ @time From fb8627ab84451c891643435f193ce2570158f29b Mon Sep 17 00:00:00 2001 From: Ian Date: Thu, 7 Jan 2021 11:11:01 -0500 Subject: [PATCH 3/3] use tryfinally macro to ensure compile timer is closed, while maintaining scope --- base/timing.jl | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/base/timing.jl b/base/timing.jl index 4d290fa855051..97aacb6113f06 100644 --- a/base/timing.jl +++ b/base/timing.jl @@ -211,9 +211,10 @@ macro time(ex) local stats = gc_num() local compile_elapsedtime = cumulative_compile_time_ns_before() local elapsedtime = time_ns() - local val = $(esc(ex)) - elapsedtime = time_ns() - elapsedtime - compile_elapsedtime = cumulative_compile_time_ns_after() - compile_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 @@ -257,9 +258,10 @@ macro timev(ex) local stats = gc_num() local compile_elapsedtime = cumulative_compile_time_ns_before() local elapsedtime = time_ns() - local val = $(esc(ex)) - elapsedtime = time_ns() - elapsedtime - compile_elapsedtime = cumulative_compile_time_ns_after() - compile_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