-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Method calls get a line number #17428
Conversation
eadd934
to
aa7d19f
Compare
A progression in specs2 location
|
@@ -0,0 +1,26 @@ | |||
|
|||
object Test: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll need a
// scalajs: --skip
at the top of this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aha!
In your test example: object Test:
def void(): Unit = ???
def self(): this.type = this
def test() =
this // this is line 8
.self()
.void() I got a debug line on line 8, on the The full debug line table is:
For the same reason, we now got two debug lines on the breakpoint of the following example, one on loading val list = List(1, 2, 3)
/* breakpoint */ list.foreach { x =>
println(x)
} |
Another example is this one: val list = List(1)
for {
x <- list
y <- list // line 4
z = x + y // line 5
} yield x If I put a breakpoint line 4 and 5:
As you can see the compiler puts a lot too much debug lines, notably in the lambda methods of the for loop. This is not a consequence of your PR, but it makes it slightly worse, adding even more debug lines. If you can remove the debug line on loading the variable, it would surely help. |
Already without this PR Scala 3 emits more line numbers than 2, for this example
Difference between Scala 2 and 3 (without this PR):
Lambdas are encoded slightly differently, in Scala 2 the body method is static, in Scala 3 it's private. So the receiver needs to be loaded on the stack in Scala 3. Not sure if the additional line number is related to that.
@adpi2 why would you remove that line number? It seems useful to be able to stop the debugger on that line. |
I spoke too fast. It is indeed useful to be able to stop on that line. The debug line that annoys me is the Suppose we have those lines: 1 list.foreach { x =>
2 println(x)
3 } In Scala 2 the debug sequence looks like this:
In Scala 3 before the PR:
In Scala 3 after the PR:
This round trip to line 1 is confusing. Putting a line number on the method call is okay, but the intermediate step on line 2 is annoying. If we can find a way to remove it that would be better. |
I think going back to line 1 is correct. Take this Java example: public class Test {
Test self() { return this; }
void run(String arg) { return; }
void t() {
self().run(
toString()
);
}
} javac produces the following bytecode:
If we don't go back to line 5, the stack trace will show that the |
Yes it is correct. It is the one on line 2 that I wish we can remove. When I debug my program I don't care about the invocation of |
right; the "invocation of |
So as far as I can tell, the PR here is fine in itself, we can merge it in Scala 2. But for Scala 3 we should clean up spurious positions with lambdas first, as this PR makes this issue worse. |
💯 |
I was interested in returning to the issue but have not yet, and would not stand in the way of anyone with more compelling interests. |
Fixes #17425
Forward ports scala/scala#10393