Skip to content

Commit

Permalink
Step through invokelatest (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy authored Mar 19, 2019
1 parent b7b389b commit c038268
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/generate_builtins.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,23 @@ function maybe_evaluate_builtin(frame, call_expr, expand::Bool)
return Some{Any}(ntuple(i->@lookup(frame, args[i+1]), length(args)-1))
""")
continue
elseif f === Core._apply
# Resolve varargs calls
elseif f === Core._apply || f === Core._apply_latest
# Resolve varargs calls and invokelatest
fstr = scopedname(f)
print(io,
"""
$head f === Core._apply
$head f === $fstr
argswrapped = getargs(args, frame)
if !expand
return Some{Any}(Core._apply(argswrapped...))
return Some{Any}($fstr(argswrapped...))
end
argsflat = Base.append_any((argswrapped[1],), argswrapped[2:end]...)
new_expr = Expr(:call, map(x->isa(x, Symbol) || isa(x, Expr) || isa(x, QuoteNode) ? QuoteNode(x) : x, argsflat)...)
return new_expr
""")
continue
elseif f === Core.invoke
print(io,
print(io,
"""
$head f === invoke
argswrapped = getargs(args, frame)
Expand Down
1 change: 1 addition & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ end
Like `which` except it operates on the complete tuple-type `tt`.
"""
function whichtt(@nospecialize(tt))
# TODO: provide explicit control over world age? In case we ever need to call "old" methods.
m = ccall(:jl_gf_invoke_lookup, Any, (Any, UInt), tt, typemax(UInt))
m === nothing && return nothing
return m.func::Method
Expand Down
11 changes: 11 additions & 0 deletions test/debug.jl
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,17 @@ struct B{T} end
@test get_return(frame) == f_inv(2)
end

f_inv_latest(x::Real) = 1 + Core._apply_latest(f_inv, x)
@testset "invokelatest" begin
fr = JuliaInterpreter.enter_call(f_inv_latest, 2.0)
fr, pc = JuliaInterpreter.debug_command(fr, :nc)
frame, pc = JuliaInterpreter.debug_command(fr, :s) # step into invokelatest
@test frame.framecode.scope.sig == Tuple{typeof(f_inv),Real}
JuliaInterpreter.debug_command(frame, :c)
frame = root(frame)
@test get_return(frame) == f_inv_latest(2.0)
end

@testset "Issue #178" begin
remove()
a = [1, 2, 3, 4]
Expand Down

0 comments on commit c038268

Please sign in to comment.