Skip to content

Commit 76037ed

Browse files
authored
quality improvement for recompile_invalidations (#36)
* quality improvement for recompile_invalidations The previous implementation was unnecessarily forcing compilation of the wrapper code for each use of the macro, and was assuming that hygiene rules do not apply to a gensym in a toplevel block and assuming that the internal tryfinally syntax is legal to generate directly. This change tries to avoid all of those assumptions, and should therefore also give better backtraces too. * Update invalidations.jl
1 parent 184a413 commit 76037ed

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/invalidations.jl

+15-11
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,21 @@ Recompile any invalidations that occur within the given expression. This is gene
88
by users in creating "Startup" packages to ensure that the code compiled by package authors is not invalidated.
99
"""
1010
macro recompile_invalidations(expr)
11-
list = gensym(:list)
12-
Expr(:toplevel,
13-
:($list = ccall(:jl_debug_method_invalidation, Any, (Cint,), 1)),
14-
Expr(:tryfinally,
15-
esc(expr),
16-
:(ccall(:jl_debug_method_invalidation, Any, (Cint,), 0))
17-
),
18-
:(if ccall(:jl_generating_output, Cint, ()) == 1
19-
foreach($PrecompileTools.precompile_mi, $PrecompileTools.invalidation_leaves($list))
20-
end)
21-
)
11+
# use QuoteNode instead of esc(Expr(:quote)) so that $ is not permitted as usual (instead of having this macro work like `@eval`)
12+
return :(recompile_invalidations($__module__, $(QuoteNode(expr))))
13+
end
14+
15+
function recompile_invalidations(__module__::Module, @nospecialize expr)
16+
list = ccall(:jl_debug_method_invalidation, Any, (Cint,), 1)
17+
try
18+
Core.eval(__module__, expr)
19+
finally
20+
ccall(:jl_debug_method_invalidation, Any, (Cint,), 0)
21+
end
22+
if ccall(:jl_generating_output, Cint, ()) == 1
23+
foreach(precompile_mi, invalidation_leaves(list))
24+
end
25+
nothing
2226
end
2327

2428
function invalidation_leaves(invlist)

0 commit comments

Comments
 (0)