Skip to content

Commit 3dce7bf

Browse files
authored
restrict the signature types of method with the recurse argument (#645)
These routines may be overloaded by the new `recurse` type, and in such cases, it is safer to restrict the method signature as much as possible (since the overloads may use `@invoke` to dispatch to the original method to reuse the original implementation).
1 parent 8b76d2d commit 3dce7bf

File tree

3 files changed

+20
-49
lines changed

3 files changed

+20
-49
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "JuliaInterpreter"
22
uuid = "aa1ae85d-cabe-5617-a682-6adf51b2e16a"
3-
version = "0.9.35"
3+
version = "0.9.36"
44

55
[deps]
66
CodeTracking = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2"

src/commands.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ function next_line!(@nospecialize(recurse), frame::Frame, istoplevel::Bool=false
175175
end
176176
return _next_line!(recurse, frame, istoplevel, initialline, initialfile) # avoid boxing
177177
end
178-
function _next_line!(@nospecialize(recurse), frame, istoplevel, initialline::Int, initialfile::String)
178+
function _next_line!(@nospecialize(recurse), frame::Frame, istoplevel, initialline::Int, initialfile::String)
179179
predicate(frame) = is_return(pc_expr(frame)) || (linenumber(frame) != initialline || getfile(frame) != initialfile)
180180

181181
pc = next_until!(predicate, recurse, frame, istoplevel)
@@ -451,7 +451,7 @@ or one of the 'advanced' commands
451451
`rootistoplevel` and `ret` are as described for [`JuliaInterpreter.maybe_reset_frame!`](@ref).
452452
"""
453453
function debug_command(@nospecialize(recurse), frame::Frame, cmd::Symbol, rootistoplevel::Bool=false; line=nothing)
454-
function nicereturn!(@nospecialize(recurse), frame, pc, rootistoplevel)
454+
function nicereturn!(@nospecialize(recurse), frame::Frame, pc, rootistoplevel)
455455
if pc === nothing || isa(pc, BreakpointRef)
456456
return maybe_reset_frame!(recurse, frame, pc, rootistoplevel)
457457
end

src/interpret.jl

Lines changed: 17 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
isassign(frame) = isassign(frame, frame.pc)
2-
isassign(frame, pc) = (pc in frame.framecode.used)
1+
isassign(frame::Frame) = isassign(frame, frame.pc)
2+
isassign(frame::Frame, pc::Int) = (pc in frame.framecode.used)
33

4-
lookup_var(frame, val::SSAValue) = frame.framedata.ssavalues[val.id]
5-
lookup_var(frame, ref::GlobalRef) = getfield(ref.mod, ref.name)
6-
function lookup_var(frame, slot::SlotNumber)
4+
lookup_var(frame::Frame, val::SSAValue) = frame.framedata.ssavalues[val.id]
5+
lookup_var(frame::Frame, ref::GlobalRef) = getfield(ref.mod, ref.name)
6+
function lookup_var(frame::Frame, slot::SlotNumber)
77
val = frame.framedata.locals[slot.id]
88
val !== nothing && return val.value
99
throw(UndefVarError(frame.framecode.src.slotnames[slot.id]))
@@ -51,7 +51,7 @@ macro lookup(args...)
5151
end
5252
end
5353

54-
function lookup_expr(frame, e::Expr)
54+
function lookup_expr(frame::Frame, e::Expr)
5555
head = e.head
5656
head === :the_exception && return frame.framedata.last_exception[]
5757
if head === :static_parameter
@@ -82,7 +82,7 @@ end
8282
# and hence our re-use of the `callargs` field of Frame would introduce
8383
# bugs. Since these nodes use a very limited repertoire of calls, we can special-case
8484
# this quite easily.
85-
function lookup_or_eval(@nospecialize(recurse), frame, @nospecialize(node))
85+
function lookup_or_eval(@nospecialize(recurse), frame::Frame, @nospecialize(node))
8686
if isa(node, SSAValue)
8787
return lookup_var(frame, node)
8888
elseif isa(node, SlotNumber)
@@ -130,7 +130,7 @@ function lookup_or_eval(@nospecialize(recurse), frame, @nospecialize(node))
130130
return eval_rhs(recurse, frame, node)
131131
end
132132

133-
function resolvefc(frame, @nospecialize(expr))
133+
function resolvefc(frame::Frame, @nospecialize(expr))
134134
if isa(expr, SlotNumber)
135135
expr = lookup_var(frame, expr)
136136
elseif isa(expr, SSAValue)
@@ -200,7 +200,7 @@ function evaluate_foreigncall(@nospecialize(recurse), frame::Frame, call_expr::E
200200
end
201201

202202
# We have to intercept ccalls / llvmcalls before we try it as a builtin
203-
function bypass_builtins(@nospecialize(recurse), frame, call_expr, pc)
203+
function bypass_builtins(@nospecialize(recurse), frame::Frame, call_expr::Expr, pc::Int)
204204
if isassigned(frame.framecode.methodtables, pc)
205205
tme = frame.framecode.methodtables[pc]
206206
if isa(tme, Compiled)
@@ -311,7 +311,7 @@ evaluate_call!(@nospecialize(recurse), frame::Frame, call_expr::Expr; kwargs...)
311311
evaluate_call!(frame::Frame, call_expr::Expr; kwargs...) = evaluate_call!(finish_and_return!, frame, call_expr; kwargs...)
312312

313313
# The following come up only when evaluating toplevel code
314-
function evaluate_methoddef(frame, node)
314+
function evaluate_methoddef(frame::Frame, node::Expr)
315315
f = node.args[1]
316316
if f isa Symbol || f isa GlobalRef
317317
mod = f isa Symbol ? moduleof(frame) : f.mod
@@ -334,36 +334,7 @@ function evaluate_methoddef(frame, node)
334334
return f
335335
end
336336

337-
function structname(frame, node)
338-
name = node.args[1]
339-
if isa(name, GlobalRef)
340-
mod = name.mod
341-
name = name.name
342-
else
343-
mod = moduleof(frame)
344-
name = name::Symbol
345-
end
346-
return name, mod
347-
end
348-
349-
function set_structtype_const(mod::Module, name::Symbol)
350-
dt = Base.unwrap_unionall(getfield(mod, name))::DataType
351-
ccall(:jl_set_const, Cvoid, (Any, Any, Any), mod, dt.name.name::Symbol, dt.name.wrapper)
352-
end
353-
354-
function inplace_lookup!(ex, i, frame)
355-
a = ex.args[i]
356-
if isa(a, SSAValue) || isa(a, SlotNumber)
357-
ex.args[i] = lookup_var(frame, a)
358-
elseif isexpr(a, :call)
359-
for j = 1:length((a::Expr).args)
360-
inplace_lookup!(a, j, frame)
361-
end
362-
end
363-
return ex
364-
end
365-
366-
function do_assignment!(frame, @nospecialize(lhs), @nospecialize(rhs))
337+
function do_assignment!(frame::Frame, @nospecialize(lhs), @nospecialize(rhs))
367338
code, data = frame.framecode, frame.framedata
368339
if isa(lhs, SSAValue)
369340
data.ssavalues[lhs.id] = rhs
@@ -383,7 +354,7 @@ function do_assignment!(frame, @nospecialize(lhs), @nospecialize(rhs))
383354
end
384355
end
385356

386-
function maybe_assign!(frame, @nospecialize(stmt), @nospecialize(val))
357+
function maybe_assign!(frame::Frame, @nospecialize(stmt), @nospecialize(val))
387358
pc = frame.pc
388359
if isexpr(stmt, :(=))
389360
lhs = stmt.args[1]
@@ -394,9 +365,9 @@ function maybe_assign!(frame, @nospecialize(stmt), @nospecialize(val))
394365
end
395366
return nothing
396367
end
397-
maybe_assign!(frame, @nospecialize(val)) = maybe_assign!(frame, pc_expr(frame), val)
368+
maybe_assign!(frame::Frame, @nospecialize(val)) = maybe_assign!(frame, pc_expr(frame), val)
398369

399-
function eval_rhs(@nospecialize(recurse), frame, node::Expr)
370+
function eval_rhs(@nospecialize(recurse), frame::Frame, node::Expr)
400371
head = node.head
401372
if head === :new
402373
mod = moduleof(frame)
@@ -435,7 +406,7 @@ function eval_rhs(@nospecialize(recurse), frame, node::Expr)
435406
return lookup_expr(frame, node)
436407
end
437408

438-
function check_isdefined(frame, @nospecialize(node))
409+
function check_isdefined(frame::Frame, @nospecialize(node))
439410
data = frame.framedata
440411
if isa(node, SlotNumber)
441412
return data.locals[node.id] !== nothing
@@ -483,7 +454,7 @@ end
483454
# in `step_expr!`
484455
const _location = Dict{Tuple{Method,Int},Int}()
485456

486-
function step_expr!(@nospecialize(recurse), frame, @nospecialize(node), istoplevel::Bool)
457+
function step_expr!(@nospecialize(recurse), frame::Frame, @nospecialize(node), istoplevel::Bool)
487458
pc, code, data = frame.pc, frame.framecode, frame.framedata
488459
# if !is_leaf(frame)
489460
# show_stackloc(frame)
@@ -657,7 +628,7 @@ behaviors:
657628
`loc` is a `BreakpointRef`;
658629
- otherwise, `err` gets rethrown.
659630
"""
660-
function handle_err(@nospecialize(recurse), frame, err)
631+
function handle_err(@nospecialize(recurse), frame::Frame, @nospecialize(err))
661632
data = frame.framedata
662633
err_will_be_thrown_to_top_level = isempty(data.exception_frames) && !data.caller_will_catch_err
663634
if break_on_throw[] || (break_on_error[] && err_will_be_thrown_to_top_level)

0 commit comments

Comments
 (0)