Pass enter_generated settings through to recursive frame creation
I think that what's in the tests now (as of this PR) is what's supposed to happen. The old ASTInterpreter2 tests are a little confusing here, and in particular I think the interpolation (dating from d047188f9406fcfdd84409977386f581d3bf88a8) is actually an error that none of us caught.
Fixes #161
Does this seem reasonable? No urgency, though, we could leave it open for comments as needed.
Seems reasonable to me. And the tests confirm.
Well, that's because I changed the expected test results :smile:. But I do think this is what was intended with this functionality (or rather, what can be done with the functionality now). It doesn't really seem to let you run the generator itself, more that you can see the expression body generated by the method.
OK, now this does something which IMO is actually useful :relieved: : debugging the generator itself. From the new tests:
julia> @enter callgenerated()
In callgenerated() at /home/tim/.julia/dev/JuliaInterpreter/test/debug.jl
37 callgenerated() = generatedfoo(1)
38 @generated function generatedparams(a::Array{T,N}) where {T,N}
39 zz = 1
40 :(return ($T,$N))
41 end
About to run: (generatedfoo)(1)
1|debug> sg
In #s820#47(#temp#, x) at /home/tim/.julia/dev/JuliaInterpreter/test/debug.jl
33 ex = Expr(:block)
34 push!(ex.args, :(return x))
35 return ex
36 end
37 callgenerated() = generatedfoo(1)
About to run: (Expr)(:block)
1|debug> s
In Type(args) at boot.jl
221 Expr(@nospecialize args...) = _expr(args...)
222
223 abstract type Exception end
224 struct ErrorException <: Exception
225 msg::AbstractString
About to run: (Core._apply)(Core._expr, (:block,))
1|debug> so
In #s820#47(#temp#, x) at /home/tim/.julia/dev/JuliaInterpreter/test/debug.jl
33 ex = Expr(:block)
34 push!(ex.args, :(return x))
35 return ex
36 end
37 callgenerated() = generatedfoo(1)
38 @generated function generatedparams(a::Array{T,N}) where {T,N}
About to run: (getproperty)($(QuoteNode(quote
end)), :args)
1|debug> n
In #s820#47(#temp#, x) at /home/tim/.julia/dev/JuliaInterpreter/test/debug.jl
33 ex = Expr(:block)
34 push!(ex.args, :(return x))
35 return ex
36 end
37 callgenerated() = generatedfoo(1)
38 @generated function generatedparams(a::Array{T,N}) where {T,N}
39 zz = 1
About to run: return $(QuoteNode(quote
return x
end))
1|debug> n
In callgenerated() at /home/tim/.julia/dev/JuliaInterpreter/test/debug.jl
37 callgenerated() = generatedfoo(1)
38 @generated function generatedparams(a::Array{T,N}) where {T,N}
39 zz = 1
40 :(return ($T,$N))
41 end
About to run: return $(QuoteNode(quote
return x
end))
1|debug> n
quote
return x
end
We should decide what we want here. You can try both by checking out this branch.
With just the first commit:
julia> using JuliaInterpreter
julia> @generated function f(x)
zz = 1
ex = Expr(:block)
push!(ex.args, :(return x))
return ex
end
f (generic function with 1 method)
julia> JuliaInterpreter.enter_call_expr(:($f(1)); enter_generated=true)
Frame for f(x) in Main at REPL[2]:2
1 0 CodeInfo(quote
x = Int64
julia> ans.framecode.src
CodeInfo(quote
return x
end)
julia>
With both:
julia> using JuliaInterpreter
julia> @generated function f(x)
zz = 1
ex = Expr(:block)
push!(ex.args, :(return x))
return ex
end
f (generic function with 1 method)
julia> JuliaInterpreter.enter_call_expr(:($f(1)); enter_generated=true)
Frame for #s1#3(::Any, x) in Main at REPL[2]:2
1 2 1 ─ nothing
2 2 │ zz = 1
3 3 │ ex = (Expr)(:block)
⋮
#temp# = Type{##s1#3}
x = Type{typeof(f)}
julia> ans.framecode.src
CodeInfo(
1 ─ nothing
│ zz = 1
│ ex = ($(QuoteNode(Expr)))(:block)
│ %4 = ($(QuoteNode(getproperty)))(ex, :args)
│ %5 = $(Expr(:copyast, :($(QuoteNode(:(return x))))))
│ ($(QuoteNode(push!)))(%4, %5)
└── return ex
2 ─ %8 = ($(QuoteNode(Core._expr)))(:block, $(QuoteNode(:(#= REPL[2]:2 =#))), nothing)
└── return %8
)