Skip to content
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

Optional generator expansion in code_lowered (#22979) broken by #23168 #25059

Closed
jrevels opened this issue Dec 13, 2017 · 2 comments
Closed

Optional generator expansion in code_lowered (#22979) broken by #23168 #25059

jrevels opened this issue Dec 13, 2017 · 2 comments

Comments

@jrevels
Copy link
Member

jrevels commented Dec 13, 2017

Found by @martinholters here (I figured I should make an actual issue for it).

Previously, you could pass false to code_lowered's expand_generated argument to get the CodeInfo for a function's unexpanded generator. Now, however:

julia> @generated f(x) = :(x+1)
f (generic function with 1 method)

julia> code_lowered(f, Tuple{Int}, false)
ERROR: Method is @generated; try `code_lowered` instead.
Stacktrace:
 [1] error at ./error.jl:33 [inlined]
 [2] uncompressed_ast(::Method) at ./reflection.jl:753
 [3] uncompressed_ast(::Core.MethodInstance) at ./reflection.jl:758
 [4] (::getfield(Base, Symbol("##12#13")){DataType,Bool})(::Core.MethodInstance) at ./reflection.jl:634
 [5] next at ./generator.jl:47 [inlined]
 [6] _collect(::Array{Union{Method, Core.MethodInstance},1}, ::Base.Generator{Array{Union{Method, Core.MethodInstance},1},getfield(Base, Symbol("##12#13")){DataType,Bool}}, ::Base.EltypeUnknown, ::Base.HasShape) at ./array.jl:538
 [7] collect_similar(::Array{Union{Method, Core.MethodInstance},1}, ::Base.Generator{Array{Union{Method, Core.MethodInstance},1},getfield(Base, Symbol("##12#13")){DataType,Bool}}) at ./array.jl:475
 [8] map(::Function, ::Array{Union{Method, Core.MethodInstance},1}) at ./abstractarray.jl:1923
 [9] code_lowered(::Any, ::Any, ::Bool) at ./reflection.jl:624
 [10] top-level scope

This appears to have been broken by 80a2c2f#diff-ca03aefbdf6018c4da887b6ec35e0027L740.

There was a test that checked to make sure this functionality didn't regress, but it looks like that test got deleted as part of #23168: 80a2c2f#diff-2ea596942a7d251702840ffcaab1e763L773

@martinholters
Copy link
Member

Ah, actually the docstring of code_lowered tells:

  If expand_generated is false, the returned CodeInfo instances will correspond to fallback implementations. An error is thrown if no fallback
  implementation exists. If expand_generated is true, these CodeInfo instances will correspond to the method bodies yielded by expanding the
  generators.

For the @generated function f, no fallback implementation exists, so having the error is to be expected as by the documentation. (Although the error message isn't particularly helpful.)

However, over in #25055 it would be helpful to have a way of retrieving the lowered generator.

@JuliaLang JuliaLang deleted a comment from martinholters Dec 13, 2017
@JeffBezanson
Copy link
Sponsor Member

This is intentional. The generator is a separate function, which can be accessed as method.generator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants