From c038268fd5b29fcb7332da74772228475e652660 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Tue, 19 Mar 2019 04:10:45 -0500 Subject: [PATCH] Step through invokelatest (#184) --- src/generate_builtins.jl | 11 ++++++----- src/utils.jl | 1 + test/debug.jl | 11 +++++++++++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/generate_builtins.jl b/src/generate_builtins.jl index 0d100b9621c4c..cca634d6b8c67 100644 --- a/src/generate_builtins.jl +++ b/src/generate_builtins.jl @@ -131,14 +131,15 @@ 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)...) @@ -146,7 +147,7 @@ function maybe_evaluate_builtin(frame, call_expr, expand::Bool) """) continue elseif f === Core.invoke - print(io, + print(io, """ $head f === invoke argswrapped = getargs(args, frame) diff --git a/src/utils.jl b/src/utils.jl index 3bf616236008e..103c90bc6c76d 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -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 diff --git a/test/debug.jl b/test/debug.jl index 548f9de531913..dd2d268c9dbe3 100644 --- a/test/debug.jl +++ b/test/debug.jl @@ -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]