Skip to content

Commit

Permalink
Remove try from at-time and close compile timer during throw (#39133)
Browse files Browse the repository at this point in the history
* remove try from at-time and close compile timer during throw

* add scope tests for at-time and aat-timev

(cherry picked from commit 03957db)
  • Loading branch information
IanButterworth authored and KristofferC committed Jan 7, 2021
1 parent c981a57 commit 86eb245
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
18 changes: 6 additions & 12 deletions base/timing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,9 @@ macro time(ex)
local stats = gc_num()
local compile_elapsedtime = cumulative_compile_time_ns_before()
local elapsedtime = time_ns()
local val = try
$(esc(ex))
finally
elapsedtime = time_ns() - elapsedtime
compile_elapsedtime = cumulative_compile_time_ns_after() - compile_elapsedtime
end
local val = $(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
Expand Down Expand Up @@ -252,12 +249,9 @@ macro timev(ex)
local stats = gc_num()
local compile_elapsedtime = cumulative_compile_time_ns_before()
local elapsedtime = time_ns()
local val = try
$(esc(ex))
finally
elapsedtime = time_ns() - elapsedtime
compile_elapsedtime = cumulative_compile_time_ns_after() - compile_elapsedtime
end
local val = $(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
Expand Down
3 changes: 3 additions & 0 deletions src/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,9 @@ 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
Expand Down
13 changes: 13 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5080,6 +5080,19 @@ end
@test f17255(10000)[1]
GC.enable(true)

# PR #39133, ensure that @time evaluates in the same scope
function time_macro_scope()
@time time_macro_local_var = 1
time_macro_local_var
end
@test time_macro_scope() == 1

function timev_macro_scope()
@timev timev_macro_local_var = 1
timev_macro_local_var
end
@time timev_macro_scope() == 1

# issue #18710
bad_tvars() where {T} = 1
@test isa(which(bad_tvars, ()), Method)
Expand Down

0 comments on commit 86eb245

Please sign in to comment.