Skip to content

Commit c038268

Browse files
authored
Step through invokelatest (#184)
1 parent b7b389b commit c038268

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

src/generate_builtins.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,22 +131,23 @@ function maybe_evaluate_builtin(frame, call_expr, expand::Bool)
131131
return Some{Any}(ntuple(i->@lookup(frame, args[i+1]), length(args)-1))
132132
""")
133133
continue
134-
elseif f === Core._apply
135-
# Resolve varargs calls
134+
elseif f === Core._apply || f === Core._apply_latest
135+
# Resolve varargs calls and invokelatest
136+
fstr = scopedname(f)
136137
print(io,
137138
"""
138-
$head f === Core._apply
139+
$head f === $fstr
139140
argswrapped = getargs(args, frame)
140141
if !expand
141-
return Some{Any}(Core._apply(argswrapped...))
142+
return Some{Any}($fstr(argswrapped...))
142143
end
143144
argsflat = Base.append_any((argswrapped[1],), argswrapped[2:end]...)
144145
new_expr = Expr(:call, map(x->isa(x, Symbol) || isa(x, Expr) || isa(x, QuoteNode) ? QuoteNode(x) : x, argsflat)...)
145146
return new_expr
146147
""")
147148
continue
148149
elseif f === Core.invoke
149-
print(io,
150+
print(io,
150151
"""
151152
$head f === invoke
152153
argswrapped = getargs(args, frame)

src/utils.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ end
3131
Like `which` except it operates on the complete tuple-type `tt`.
3232
"""
3333
function whichtt(@nospecialize(tt))
34+
# TODO: provide explicit control over world age? In case we ever need to call "old" methods.
3435
m = ccall(:jl_gf_invoke_lookup, Any, (Any, UInt), tt, typemax(UInt))
3536
m === nothing && return nothing
3637
return m.func::Method

test/debug.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,17 @@ struct B{T} end
342342
@test get_return(frame) == f_inv(2)
343343
end
344344

345+
f_inv_latest(x::Real) = 1 + Core._apply_latest(f_inv, x)
346+
@testset "invokelatest" begin
347+
fr = JuliaInterpreter.enter_call(f_inv_latest, 2.0)
348+
fr, pc = JuliaInterpreter.debug_command(fr, :nc)
349+
frame, pc = JuliaInterpreter.debug_command(fr, :s) # step into invokelatest
350+
@test frame.framecode.scope.sig == Tuple{typeof(f_inv),Real}
351+
JuliaInterpreter.debug_command(frame, :c)
352+
frame = root(frame)
353+
@test get_return(frame) == f_inv_latest(2.0)
354+
end
355+
345356
@testset "Issue #178" begin
346357
remove()
347358
a = [1, 2, 3, 4]

0 commit comments

Comments
 (0)