-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Code returned from generated function calls behaves incorrectly #25055
Comments
Looks like the julia> @generated function foo(::Val{N}) where N
ex = quote end
println(object_id(ex))
println(length(ex.args))
push!(ex.args, :nothing)
if N > 0
:(foo(Val(N-1)))
else
:(nothing)
end
end
foo (generic function with 1 method)
julia> foo(Val(3))
12108886621498232131
1
12108886621498232131
2
12108886621498232131
3
12108886621498232131
4
|
Um, I thought one could inspect the lowered generator, but julia> code_lowered(foo, Tuple{Val{3}}, false)
ERROR: Method is @generated; try `code_lowered` instead. Julia bug or user bug? |
See if this fixes it:
|
Thanks, but no that doesn't seem to fix the original issue, or what @martinholters reduced it to. |
Somehow (likely in the new allocation elimination pass) this transformation is happening:
I haven't figured out how yet, though. |
Bisection confirms 4e81b9c as the point where this regressed. |
Anyone have any clues here? I miss generated functions 😢 . Happy to help dig in if anyone can give some pointers. |
Where are you running into this issue? Using an # example from Jeff
julia> function f()
x = quote end
return x
end
f (generic function with 1 method)
julia> @code_typed f()
CodeInfo(:(begin
#= line 3 =#
return $(QuoteNode(quote
#= REPL[1]:2 =#
end))
end)) => Expr
# workaround?
julia> function g()
x = Expr(:block)
return x
end
g (generic function with 1 method)
julia> @code_typed g()
CodeInfo(:(begin
# meta: location boot.jl Type 197
SSAValue(1) = (Core._expr)(:block)::Expr
# meta: pop location
#= line 3 =#
return SSAValue(1)
end)) => Expr |
This reverts commit 70727a4.
Caused by #24113 (cc @JeffBezanson), breaks CUDAnative. Repro:
Before:
After:
ie. the
inner
function is called on aTuple{Int64}
, while the code returned byouter
contains a call toouter(val[1])
whereval[1]
is a plain integer, and thus should result in a call toinner(val[1])
.Couple of things that change this behavior:
ex = Expr(:block)
or return expressions instead of pushing to a blockouter(1)
first causes infinite recursionThe text was updated successfully, but these errors were encountered: