Skip to content

Commit c7f3510

Browse files
authored
refactor out returning from a frame (#310)
1 parent e048dc4 commit c7f3510

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

src/commands.jl

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,8 @@ function finish_stack!(@nospecialize(recurse), frame::Frame, rootistoplevel::Boo
5959
ret = finish_and_return!(recurse, frame, istoplevel)
6060
isa(ret, BreakpointRef) && return ret
6161
frame === frame0 && return ret
62-
recycle(frame)
63-
frame = caller(frame)
62+
frame = return_from(frame)
6463
frame === nothing && return ret
65-
frame.callee = nothing
6664
pc = frame.pc
6765
if isassign(frame, pc)
6866
lhs = SSAValue(pc)
@@ -325,10 +323,8 @@ function maybe_reset_frame!(@nospecialize(recurse), frame::Frame, @nospecialize(
325323
isa(pc, BreakpointRef) && return leaf(frame), pc
326324
if pc === nothing
327325
val = get_return(frame)
328-
recycle(frame)
329-
frame = caller(frame)
326+
frame = return_from(frame)
330327
frame === nothing && return nothing
331-
frame.callee = nothing
332328
ssavals = frame.framedata.ssavalues
333329
is_wrapper = isassigned(ssavals, frame.pc) && ssavals[frame.pc] === Wrapper()
334330
maybe_assign!(frame, val)
@@ -353,9 +349,7 @@ function unwind_exception(frame::Frame, exc)
353349
frame.framedata.last_exception[] = exc
354350
return frame
355351
end
356-
recycle(frame)
357-
frame = caller(frame)
358-
frame === nothing || (frame.callee = nothing)
352+
frame = return_from(frame)
359353
end
360354
rethrow(exc)
361355
end

src/construct.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ const debug_recycle = Base.RefValue(false)
3434
push!(junk, frame.framedata)
3535
end
3636

37+
function return_from(frame::Frame)
38+
recycle(frame)
39+
frame = caller(frame)
40+
frame === nothing || (frame.callee = nothing)
41+
return frame
42+
end
43+
3744
function clear_caches()
3845
empty!(junk)
3946
empty!(framedict)

src/interpret.jl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ function evaluate_call_recurse!(@nospecialize(recurse), frame::Frame, call_expr:
244244
end
245245
isa(ret, BreakpointRef) && return ret
246246
frame.callee = nothing
247-
recycle(newframe)
247+
return_from(newframe)
248248
return ret
249249
end
250250

@@ -492,7 +492,7 @@ function step_expr!(@nospecialize(recurse), frame, @nospecialize(node), istoplev
492492
finish!(recurse, newframe, true)
493493
frame.callee = nothing
494494
end
495-
recycle(newframe)
495+
return_from(newframe)
496496
elseif node.head == :global
497497
# error("fixme")
498498
elseif node.head == :toplevel
@@ -504,7 +504,7 @@ function step_expr!(@nospecialize(recurse), frame, @nospecialize(node), istoplev
504504
while true
505505
($through_methoddef_or_done!)($recurse, newframe) === nothing && break
506506
end
507-
$recycle(newframe)
507+
$return_from(newframe)
508508
end)))
509509
elseif node.head == :error
510510
error("unexpected error statement ", node)
@@ -579,10 +579,8 @@ function handle_err(@nospecialize(recurse), frame, err)
579579
return BreakpointRef(frame.framecode, frame.pc, err)
580580
end
581581
if isempty(data.exception_frames)
582-
is_root_frame = frame.caller === nothing
583-
if !is_root_frame && !err_will_be_thrown_to_top_level
584-
frame.caller.callee = nothing
585-
recycle(frame)
582+
if !err_will_be_thrown_to_top_level
583+
return_from(frame)
586584
end
587585
# Check for world age errors, which generally indicate a failure to go back to toplevel
588586
if isa(err, MethodError)

0 commit comments

Comments
 (0)