Skip to content

Commit 7687329

Browse files
authored
allow interpreting TypedSlots (#491)
1 parent 1b2eecb commit 7687329

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/optimize.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ function replace_coretypes_list!(list::AbstractVector; rev::Bool)
419419
end
420420
if isa(x, Core.SSAValue)
421421
return SSAValue(x.id)
422-
elseif isa(x, Core.SlotNumber)
422+
elseif isa(x, Core.SlotNumber) || isa(x, Core.TypedSlot)
423423
return SlotNumber(x.id)
424424
end
425425
return x

test/interpret.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,3 +821,23 @@ module ForInclude end
821821
ex = :(include("dummy_file.jl"))
822822
@test JuliaInterpreter.finish_and_return!(Frame(ForInclude, ex), true) == 55
823823
end
824+
825+
@testset "TypedSlots" begin
826+
function foo(x, y)
827+
z = x + y
828+
if z < 4
829+
z += 1
830+
end
831+
u = (x -> x + z)(x)
832+
v = Ref{Union{Int, Missing}}(x)[] + y
833+
return u + v
834+
end
835+
836+
ci = code_typed(foo, NTuple{2, Int}; optimize=false)[][1]
837+
mi = Core.Compiler.method_instances(foo, NTuple{2, Int})[]
838+
839+
frameargs = Any[foo, 1, 2]
840+
framecode = JuliaInterpreter.FrameCode(mi.def, ci)
841+
frame = JuliaInterpreter.prepare_frame(framecode, frameargs, mi.sparam_vals)
842+
@test JuliaInterpreter.finish_and_return!(frame) === 8
843+
end

0 commit comments

Comments
 (0)