Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove try from at-time and close compile timer during throw #39133

Merged
merged 3 commits into from
Jan 7, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 4 additions & 0 deletions src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,10 @@ JL_CALLABLE(jl_f_typeassert)
JL_CALLABLE(jl_f_throw)
{
JL_NARGS(throw, 1, 1);
int tid = jl_threadid();
// @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[tid] = 0;
IanButterworth marked this conversation as resolved.
Show resolved Hide resolved
jl_throw(args[0]);
return jl_nothing;
}
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