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

Bytecode line numbers for calls within inlined code may be worng #6085

Open
nicolasstucki opened this issue Mar 13, 2019 · 2 comments
Open

Comments

@nicolasstucki
Copy link
Contributor

Currently the line numbers of method invocations in the bytecode uses the last parameter as the line of the call. This is useful to save an extra label and line number in the bytecode and avoid jumping back while debugging.

Unfortunately if the last argument happens to be inlined from somewhere else, the call also inherits this line number.

object Test {

  inline def fun[T](inline tag: String): Unit = {
    printStack(
      tag,
      "track" // line 6
    )
    printStack(
      "track",
      tag // line 10
    )
  }

  def printStack(tag1: String, tag2: String): Unit = {
    println(s"$tag1 $tag2: ${new Exception().getStackTrace().apply(1)}")
  }

  def main(args: Array[String]): Unit = {
    fun(
      "abc" // line 20
    )
  }
}
abc track: Test$.main(i4947a2.scala:6)
track abc: Test$.main(i4947a2.scala:20)

Note: this only hapend on top of #6066 which fixes the positions of inlined arguments with singleton types. Before the buggy position happend to negate it self with this bug.

Possible solutions:

  • Use the end line of the position of theApply/TypeApply as position of invocation
    • For every invocation: would increse bytecode size of every multiline call
    • Only if the position of the last argument if not contained in the position of the call
  • Loose all inline positions: we already have to do it for all inline code that comes from another file. The position of the call is used for all inlined trees.
@smarter
Copy link
Member

smarter commented Mar 13, 2019

Loose all inline positions: we already have to do it for all inline code that comes from another file. The position of the call is used for all inlined trees.

That would give terrible backtraces and make it impossible to debug code that's wrapped in trace in dotty.

@nicolasstucki
Copy link
Contributor Author

This is only for code the is inlined from the same file. The code for trace will have all its positions removed. We cannot do better because we can only emit line numbers but no source files.

This issue is only about those few cases where the inlined method is in the same file.

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

No branches or pull requests

2 participants