@@ -26,8 +26,13 @@ rather than recursed into via the interpreter.
26
26
"""
27
27
const compiled_modules = Set {Module} ()
28
28
29
- const junk = Base. IdSet {FrameData} () # to allow re-use of allocated memory (this is otherwise a bottleneck)
30
- recycle (frame) = push! (junk, frame. framedata) # using an IdSet ensures that a frame can't be added twice
29
+ const junk = FrameData[] # to allow re-use of allocated memory (this is otherwise a bottleneck)
30
+ const debug_recycle = Base. RefValue (false )
31
+ @noinline _check_frame_not_in_junk (frame) = @assert frame. framedata ∉ junk
32
+ @inline function recycle (frame)
33
+ debug_recycle[] && _check_frame_not_in_junk (frame)
34
+ push! (junk, frame. framedata)
35
+ end
31
36
32
37
const empty_svec = Core. svec ()
33
38
@@ -245,9 +250,8 @@ function prepare_framedata(framecode, argvals::Vector{Any}, caller_will_catch_er
245
250
ssavt = src. ssavaluetypes
246
251
ng = isa (ssavt, Int) ? ssavt : length (ssavt:: Vector{Any} )
247
252
nargs, meth_nargs = length (argvals), Int (meth. nargs)
248
- if ! isempty (junk)
249
- olddata = first (junk)
250
- delete! (junk, olddata)
253
+ if length (junk) > 0
254
+ olddata = pop! (junk)
251
255
locals, ssavalues, sparams = olddata. locals, olddata. ssavalues, olddata. sparams
252
256
exception_frames, last_reference = olddata. exception_frames, olddata. last_reference
253
257
last_exception = olddata. last_exception
@@ -523,6 +527,7 @@ T = Float64
523
527
See [`enter_call`](@ref) for a similar approach not based on expressions.
524
528
"""
525
529
function enter_call_expr (expr; enter_generated = false )
530
+ empty! (junk)
526
531
r = determine_method_for_expr (expr; enter_generated = enter_generated)
527
532
if isa (r, Tuple)
528
533
return prepare_frame (r[1 : end - 1 ]. .. )
@@ -564,6 +569,7 @@ would be created by the generator.
564
569
See [`enter_call_expr`](@ref) for a similar approach based on expressions.
565
570
"""
566
571
function enter_call (@nospecialize (finfo), @nospecialize (args... ); kwargs... )
572
+ empty! (junk)
567
573
if isa (finfo, Tuple)
568
574
f = finfo[1 ]
569
575
enter_generated = finfo[2 ]:: Bool
0 commit comments