8000 SI-7518 Better positioning for inlined code · retronym/scala@178c37b · GitHub
[go: up one dir, main page]

Skip to content

Commit 178c37b

Browse files
committed
SI-7518 Better positioning for inlined code
The inliner was positioning all inlined instructions at the method call (`targetPos). This makes debugging of code compiled under `-optimize` difficult. This commit retains the original position of the inlined instruction if it is in the same source file as the method call. In other cases, we have to fall back to the `targetPos`; line number information in classfiles can only index into current source file.
1 parent 7691423 commit 178c37b

File tree

6 files changed

+54
-1
lines changed

6 files changed

+54
-1
lines changed

src/compiler/scala/tools/nsc/backend/opt/Inliners.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,7 @@ abstract class Inliners extends SubComponent {
878878
}
879879
// check any pending NEW's
880880
pending remove i foreach (_.init = newInstr.asInstanceOf[CALL_METHOD])
881+
newInstr.setPos(i.pos)
881882
newInstr
882883
}
883884

@@ -909,7 +910,8 @@ abstract class Inliners extends SubComponent {
909910
val calleeLin = inc.m.linearizedBlocks()
910911
calleeLin foreach { bb =>
911912
var info = if(hasRETURN) (a in bb) else null
912-
def emitInlined(i: Instruction) = inlinedBlock(bb).emit(i, targetPos)
913+
def sameSource(p1: Position, p2: Position) = p1 != NoPosition && p2 != NoPosition && p1.source == p2.source
914+
def emitInlined(i: Instruction) = inlinedBlock(bb).emit(i, if (sameSource(targetPos, i.pos)) i.pos else targetPos)
913915
def emitDrops(toDrop: Int) = info.stack.types drop toDrop foreach (t => emitInlined(DROP(t)))
914916

915917
for (i <- bb) {

test/files/run/t7518.check

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class scala.tools.asm.tree.MethodNode
2+
L0
3+
LINENUMBER 6 L0
4+
LDC "LINE 6"
5+
INVOKEVIRTUAL java/lang/String.toString ()Ljava/lang/String;
6+
L1
7+
LINENUMBER 5 L1
8+
POP
9+
RETURN
10+
L2
11+
LOCALVARIABLE this LInlinePosition; L0 L2 0
12+
MAXSTACK = 1
13+
MAXLOCALS = 1
14+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-optimize
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class InlinePosition {
2+
@inline final def foo[A](a: => A) = a
3+
4+
def client {
5+
foo {
6+
"LINE 6".toString
7+
}
8+
}
9+
}

test/files/run/t7518/Test.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import scala.tools.partest.BytecodeTest
2+
import scala.tools.asm.util._
3+
import java.io._
4+
5+
object Test extends BytecodeTest {
6+
def show {
7+
val classNode = loadClassNode("InlinePosition", skipDebugInfo = false)
8+
val meth = getMethod(classNode, "client")
9+
val textifier = new Textifier()
10+
meth.accept(new TraceMethodVisitor(textifier))
11+
}
12+
}

test/files/run/t7518/Test_2.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import scala.tools.partest.BytecodeTest
2+
import scala.tools.asm.util._
3+
import scala.tools.nsc.util.stringFromWriter
4+
5+
object Test extends BytecodeTest {
6+
def show {
7+
// your code that inspect ASM trees and prints values
8+
val classNode = loadClassNode("InlinePosition", skipDebugInfo = false)
9+
val meth = getMethod(classNode, "client")
10+
println(meth.getClass)
11+
val textifier = new Textifier()
12+
meth.accept(new TraceMethodVisitor(textifier))
13+
println(stringFromWriter(w => textifier.print(w)))
14+
}
15+
}

0 commit comments

Comments
 (0)
< 2961 /div>
0