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

Make it easier to track down errors that occur in a thunk #57

Closed
oxinabox opened this issue Oct 19, 2019 · 1 comment · Fixed by #58
Closed

Make it easier to track down errors that occur in a thunk #57

oxinabox opened this issue Oct 19, 2019 · 1 comment · Fixed by #58

Comments

@oxinabox
Copy link
Member

Consider:

julia> extern(foo())
ERROR: ArgumentError: invalid rational: zero(Int64)//zero(Int64)
Stacktrace:
 [1] __throw_rational_argerror(::Type) at ./rational.jl:19
 [2] Rational at ./rational.jl:14 [inlined]
 [3] Rational at ./rational.jl:21 [inlined]
 [4] //(::Int64, ::Int64) at ./rational.jl:44
 [5] (::var"#13#14")() at /Users/oxinabox/.julia/packages/ChainRulesCore/LC8Sv/src/differentials.jl:243
 [6] (::Thunk{var"#13#14"})() at /Users/oxinabox/.julia/packages/ChainRulesCore/LC8Sv/src/differentials.jl:250
 [7] extern(::Thunk{var"#13#14"}) at /Users/oxinabox/.julia/packages/ChainRulesCore/LC8Sv/src/differentials.jl:251
 [8] top-level scope at REPL[9]:1

There was an error thrown within the thunk.
but the stacktrace tells me nothing about how to find the thunk.

It doesn't tell me wher the Thunk was, nor what it contained.

There are a few things we can investigate:

  1. (somehow) make it so the line numbers for the thunk's inner function in [5] reflect where the @thunk was rather than its contents
  2. use source.__line__ and source.__file__ to actually include that in the functions name
  3. include the expression wrapped in the functions name
  4. Have a way to disable thiunking and make it eager. I think this can be done by having disable_thunking()=@eval macro thunk(x) x end and matching enable_thunk() to restore original definition
@oxinabox
Copy link
Member Author

oxinabox commented Oct 19, 2019

This seems to work to do option 1.

julia> macro demo()
       Expr(:->, Expr(:tuple), Expr(:block, __source__, Expr(:call, +, 1, 1)))
       end
@demo (macro with 1 method)

julia> f = @demo
#7 (generic function with 1 method)

julia> methods(f)
# 1 method for anonymous function "#7":
[1] (::var"#7#8")() in Main at REPL[2]:1

julia> g=@demo
#9 (generic function with 1 method)

julia> methods(g)
# 1 method for anonymous function "#9":
[1] (::var"#9#10")() in Main at REPL[4]:1

Note that f says it was declared in REPL cell 2,
and g says that it was declared in REPL cell 4.

I think we should do this.

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

Successfully merging a pull request may close this issue.

1 participant