JuliaInterpreter.jl icon indicating copy to clipboard operation
JuliaInterpreter.jl copied to clipboard

@interpreter^2 fails

Open KristofferC opened this issue 6 years ago • 5 comments

Would be cool if this would work:

julia> f() = @interpret 1+1
f (generic function with 1 method)

julia> @interpret f()
ERROR: TypeError: in typeassert, expected JuliaInterpreter.FrameData, got Nothing
Stacktrace:
 [1] maybe_evaluate_builtin(::Frame, ::Expr, ::Bool) at C:\Users\Kristoffer\.julia\packages\JuliaInterpreter\ZrOBa\src\builtins-julia1.1.jl:162
 [2] #evaluate_call_recurse!#37(::Bool, ::Function, ::Any, ::Frame, ::Expr) at C:\Users\Kristoffer\.julia\packages\JuliaInterpreter\ZrOBa\src\interpret.jl:208
 [3] evaluate_call_recurse! at C:\Users\Kristoffer\.julia\packages\JuliaInterpreter\ZrOBa\src\interpret.jl:205 [inlined]
 [4] eval_rhs(::Any, ::Frame, ::Expr) at C:\Users\Kristoffer\.julia\packages\JuliaInterpreter\ZrOBa\src\interpret.jl:371
 [5] step_expr!(::Any, ::Frame, ::Any, ::Bool) at C:\Users\Kristoffer\.julia\packages\JuliaInterpreter\ZrOBa\src\interpret.jl:504
...

Might be problematic with our globals and so on.

KristofferC avatar Mar 28 '19 15:03 KristofferC

This now works if we disable recycle:

julia> f() = @interpret 1+1
f (generic function with 1 method)

julia> @interpret f()
2

If I add it back (note that I run the check to see that we are not double adding a FrameData):

julia> JuliaInterpreter.debug_recycle[] = true;

julia> @interpret f()
ERROR: add_int: types of a and b must match
Stacktrace:
 [1] #evaluate_call_recurse!#37(::Bool, ::Function, ::Any, ::Frame, ::Expr) at C:\Users\Kristoffer\Debugging\JuliaInterpreter\src\interpret.jl:216
 [2] evaluate_call_recurse! at C:\Users\Kristoffer\Debugging\JuliaInterpreter\src\interpret.jl:205 [inlined]
 [3] eval_rhs(::Any, ::Frame, ::Expr) at C:\Users\Kristoffer\Debugging\JuliaInterpreter\src\interpret.jl:371

We have some kind of corruption because the value of a here is the frame itself which likely comes from the outer @interpret call. So I'm guessing the recycles from the other and inner interpretation are fighting with each other somehow. Cool that it is possible to do @interpret^2 now though.

Edit: Changing f() to @interpret sin(2.0) and it starts to fail.

KristofferC avatar Mar 31 '19 13:03 KristofferC

Here is a MWE of an error (with recycle disabled):

struct S
    a::Float64
end
f() = @interpret S(1.0)
julia> f()
S(1.0)

julia> @interpret f()
S(0.0)

KristofferC avatar Apr 01 '19 12:04 KristofferC

For anyone that would like to debug the nested interpretation and want to keep your sanity. Duplicate JuliaInterpreter into a new package (JuliaInterpreter2) and do something like

f() = JuliaInterpreter2.@interpret
@interpret f()

Otherwise you don't know which print statements comes from the innner or outer interpretation etc...

KristofferC avatar Apr 02 '19 13:04 KristofferC

I think there might be confusion with SSAValues from the outer interpreter getting mixed with SSAValues of the inner interpreter. Presumably, we would need some "tagging" system to tag SSAVaulues from differents nesting level of interpretation.

KristofferC avatar Aug 16 '19 07:08 KristofferC