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

less helpful stacktraces on 1.6 #185

Closed
simeonschaub opened this issue Feb 14, 2021 · 3 comments · Fixed by #186
Closed

less helpful stacktraces on 1.6 #185

simeonschaub opened this issue Feb 14, 2021 · 3 comments · Fixed by #186

Comments

@simeonschaub
Copy link
Contributor

As reported in JuliaLang/julia#37954 (comment), #37954 seems to have regressed stacktraces of inlined overdubs, so they show up as overdub instead of as the overdubbed function itself. From the discussion with @vchuravy on Slack:

I think the issue is that the we are not inlining
10:32
But reflecting on the method and then emitting code based of that reflection
10:33
So previously that looked like inlining to the compiler
10:33
But now it reflects what is happening accurately
10:33
So we might need to inject an inlining frame into the reflected CodeInfo
10:34
At least that is my looking into my crystal ball
10:34
There is a Mini-Cassette in the base test
10:36
So the thing to do would be to reproduce there, write a test for it and then fix it in the mini Cassette
10:36
Then we can take that fix to Cassette proper and we can reasonably be certain that it won't regress

Simeon Schaub 10:38 PM
Ah, I see, so we basically want to trick Julia into thinking this was a different function than the one actually called?

Valentin Churavy:juliaspinner: 10:59 PM
Jup

10:59
We could also teach the compiler more about Cassette
11:00
But if we can fix it on the Cassette level I would prefer that

@simeonschaub
Copy link
Contributor Author

Hmm, interesting... I have made a more minimal reproducer:
Julia 1.5:

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

julia> @generated function bar()
           ci = copy(code_lowered(foo, Tuple{})[])
           ci.linetable[1] = Core.LineInfoNode(:baz, :f, 1, 0)
           ci.inlineable = true
           return ci
       end
bar (generic function with 1 method)

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

julia> @generated function bar2()
           ci = copy(code_lowered(foo2, Tuple{})[])
           ci.linetable[1] = Core.LineInfoNode(:baz2, :f, 1, 0)
           return ci
       end
bar2 (generic function with 1 method)

julia> bar2()
ERROR: 
Stacktrace:
 [1] error() at ./error.jl:42
 [2] baz2 at ./f:1 [inlined]
 [3] bar2() at ./REPL[4]:0
 [4] top-level scope at REPL[5]:1

Latest master:

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

julia> @generated function bar()
           ci = copy(code_lowered(foo, Tuple{})[])
           ci.linetable[1] = Core.LineInfoNode(Main, :baz, :f, 1, 0)
           ci.inlineable = true
           return ci
       end
bar (generic function with 1 method)

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

julia> @generated function bar2()
           ci = copy(code_lowered(foo2, Tuple{})[])
           ci.linetable[1] = Core.LineInfoNode(Main, :baz2, :f, 1, 0)
           return ci
       end
bar2 (generic function with 1 method)

julia> bar2()
ERROR: 
Stacktrace:
 [1] error()
   @ Base ./error.jl:42
 [2] bar2
   @ ./f:1 [inlined]
 [3] bar2()
   @ Main ./REPL[19]:0
 [4] top-level scope
   @ REPL[20]:1

I am increasingly thinking that this might not be fixable in Cassette alone, since I think the way this now works, for function names in stacktraces we now always take the LineInfoNode from the initial lowering of the generated function itself, not the output of the GeneratedFunctionStub, which we can't really modify inside the body of the generated function. I still don't fully understand all of this, so I could also very well be wrong here.

@vchuravy
Copy link
Member

@JeffBezanson @vtjnash any ideas if we can fix this on the Cassette side?

@simeonschaub
Copy link
Contributor Author

(Note that the 1.5 behavior also seems kind of broken, since I would have expected the second entry to show up as bar instead of bar2.)
The best thing here really might be to support this properly in base and have a way of including the whole signature of inlined functions in stacktraces as well. Not sure how difficult that would be to add though and whether there might be other issues complicating this.

simeonschaub added a commit to simeonschaub/Cassette.jl that referenced this issue Mar 19, 2021
This fools Julia into thinking we inlined an additional function here, so we get better stacktraces.
fixes JuliaLabs#185
vchuravy pushed a commit that referenced this issue Mar 19, 2021
* better stacktraces in overdubs

This fools Julia into thinking we inlined an additional function here, so we get better stacktraces.
fixes #185
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.

2 participants