Skip to content

Commit

Permalink
Look up correct framecode for invoke (#352)
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy authored Dec 3, 2019
1 parent b591acc commit 32c7a32
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/interpret.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,13 @@ function evaluate_call_recurse!(@nospecialize(recurse), frame::Frame, call_expr:
end
if fargs[1] === Core.invoke # invoke needs special handling
f_invoked = which(fargs[2], fargs[3])
sig = Tuple{_Typeof.(fargs)...}
fargs_pruned = [fargs[2]; fargs[4:end]]
sig = Tuple{_Typeof.(fargs_pruned)...}
ret = prepare_framecode(f_invoked, sig; enter_generated=enter_generated)
isa(ret, Compiled) && invoke(fargs[2:end]...)
framecode, lenv = ret
fargs = [fargs[2]; fargs[4:end]]
lenv === nothing && return framecode # this was a Builtin
fargs = fargs_pruned
else
framecode, lenv = get_call_framecode(fargs, frame.framecode, frame.pc; enter_generated=enter_generated)
if lenv === nothing
Expand Down
8 changes: 8 additions & 0 deletions test/interpret.jl
Original file line number Diff line number Diff line change
Expand Up @@ -613,3 +613,11 @@ end
f() = map(x -> 2x, 1:10)
@test @interpret(f()) == f()
end

@testset "invoke" begin
# Example provided by jmert in #352
f(d::Diagonal{T}) where {T} = invoke(f, Tuple{AbstractMatrix}, d)
f(m::AbstractMatrix{T}) where {T} = T
D = Diagonal([1.0, 2.0])
@test @interpret(f(D)) === f(D)
end

0 comments on commit 32c7a32

Please sign in to comment.