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

RFC: Embed an error when a generator fails. #31756

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

maleadt
Copy link
Member

@maleadt maleadt commented Apr 18, 2019

Fix #25707, and also results in more GPU compatible code since it doesn't dynamically dispatch to the generator in order to throw an error.

Some thoughts/TODO's:

  • Expr(:error, e) doesn't work because jl_expand(Expr(:lambda, ...)) doesn't return a CodeInfo then?
  • stack traces are obviously truncated; should we reconstruct the line info stack to make them accurate?

Also, the new behavior is shown by code_typed but not code_warntype, I'm not sure why that's the case (probably #31764):

julia> @generated bar() = whatever
bar (generic function with 1 method)

julia> foo() = bar()
foo (generic function with 1 method)

julia> @code_warntype foo()
Variables
  #self#::Core.Compiler.Const(foo, false)

Body::Union{}
1 ─     Main.bar()
└──     Core.Compiler.Const(:(return %1), false)

julia> @code_typed foo()
CodeInfo(
1throw(UndefVarError(:whatever))::Union{}$(Expr(:unreachable))::Union{}
│       φ ()::Union{}
└──     $(Expr(:unreachable))::Union{}
) => Union{}

@maleadt maleadt added the compiler:codegen Generation of LLVM IR and native code label Apr 18, 2019
@vchuravy
Copy link
Sponsor Member

How does this handle the case of:

function f(x)
  if @generated
    error()
  else
    x^2
  end
end

Copy link
Sponsor Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also try to re-invoke the staged function at runtime, and throw the exception at that time, rather than falling back to storing a copy of the error (which might waste memory) as this PR does, or trying to use the non-specialized code as it does now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:codegen Generation of LLVM IR and native code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optional generators swallow errors
3 participants