Skip to content

Commit 7df9906

Browse files
Kordyjananatoliykmetyuk
authored andcommitted
Add information aobut internal class name to SMAP
1 parent 68fee16 commit 7df9906

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

compiler/src/dotty/tools/backend/jvm/BCodeSkelBuilder.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
281281
superClass, interfaceNames.toArray)
282282

283283
if (emitSource) {
284-
sourceMap = sourceMapFor(cunit)
284+
sourceMap = sourceMapFor(cunit)(s => classBTypeFromSymbol(s).internalName)
285285
cnode.visitSource(cunit.source.file.name, sourceMap.debugExtension.orNull)
286286
}
287287

compiler/src/dotty/tools/backend/jvm/InlinedSourceMaps.scala

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import dotc.CompilationUnit
66
import dotc.ast.tpd._
77
import dotc.util.{ SourcePosition, SourceFile }
88
import dotc.core.Contexts._
9+
import dotc.core.Symbols.Symbol
910
import dotc.report
1011
import dotc.typer.Inliner.InliningPosition
1112
import collection.mutable
1213

13-
import scala.collection.mutable.StringBuilder
1414

1515
object InlinedSourceMaps:
1616
private case class Request(targetPos: SourcePosition, origPos: SourcePosition, firstFakeLine: Int)
@@ -61,17 +61,26 @@ object InlinedSourceMaps:
6161
b ++= "*E\n"
6262
end Stratum
6363

64-
def sourceMapFor(cunit: CompilationUnit)(using Context): InlinedSourceMap =
64+
def sourceMapFor(cunit: CompilationUnit)(internalNameProvider: Symbol => String)(using Context): InlinedSourceMap =
6565
val requests = mutable.ListBuffer.empty[Request]
6666
var lastLine = cunit.tpdTree.sourcePos.endLine
67+
var internalNames = Map.empty[SourceFile, String]
6768

6869
class RequestCollector(enclosingFile: SourceFile) extends TreeTraverser:
6970
override def traverse(tree: Tree)(using Context): Unit =
7071
if tree.source != enclosingFile && tree.source != cunit.source then
7172
tree.getAttachment(InliningPosition) match
72-
case Some(targetPos) =>
73+
case Some(InliningPosition(targetPos, cls)) =>
7374
val firstFakeLine = allocate(tree.sourcePos)
7475
requests += Request(targetPos, tree.sourcePos, firstFakeLine)
76+
cls match
77+
case Some(symbol) if !internalNames.isDefinedAt(tree.source) =>
78+
internalNames += (tree.source -> internalNameProvider(symbol))
79+
// We are skipping any internal name info if we already have one stored in our map
80+
// because a debugger will use internal name only to localize matching source.
81+
// Both old and new internal names are associated with the same source file
82+
// so it doesn't matter if internal name is not matching used symbol.
83+
case _ => ()
7584
RequestCollector(tree.source).traverseChildren(tree)
7685
case None =>
7786
// Not exactly sure in which cases it is happening. Should we report warning?
@@ -85,17 +94,24 @@ object InlinedSourceMaps:
8594
line
8695

8796
RequestCollector(cunit.source).traverse(cunit.tpdTree)
88-
InlinedSourceMap(cunit, requests.toList)
97+
InlinedSourceMap(cunit, requests.toList, internalNames)
8998
end sourceMapFor
9099

91-
class InlinedSourceMap private[InlinedSourceMaps] (cunit: CompilationUnit, requests: List[Request])(using Context):
100+
class InlinedSourceMap private[InlinedSourceMaps] (
101+
cunit: CompilationUnit,
102+
requests: List[Request],
103+
internalNames: Map[SourceFile, String])(using Context):
104+
92105
def debugExtension: Option[String] = Option.when(requests.nonEmpty) {
93106
val scalaStratum =
94107
val files = cunit.source :: requests.map(_.origPos.source).distinct.filter(_ != cunit.source)
95108
val mappings = requests.map { case Request(_, origPos, firstFakeLine) =>
96109
Mapping(origPos.startLine, files.indexOf(origPos.source) + 1, origPos.lines.length, firstFakeLine, 1)
97110
}
98-
Stratum("Scala", files.zipWithIndex.map { case (f, n) => File(n + 1, f.name, None) }, Mapping(0, 1, cunit.tpdTree.sourcePos.lines.length, 0, 1) +: mappings)
111+
Stratum("Scala",
112+
files.zipWithIndex.map { case (f, n) => File(n + 1, f.name, internalNames.get(f)) },
113+
Mapping(0, 1, cunit.tpdTree.sourcePos.lines.length, 0, 1) +: mappings
114+
)
99115

100116
val debugStratum =
101117
val mappings = requests.map { case Request(targetPos, origPos, firstFakeLine) =>

compiler/src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ import quoted.QuoteUtils
3737
object Inliner {
3838
import tpd._
3939

40-
val InliningPosition = new Property.StickyKey[SourcePosition]
40+
object InliningPosition extends Property.StickyKey[InliningPosition]
41+
case class InliningPosition(sourcePos: SourcePosition, topLevelSymbol: Option[Symbol])
4142

4243
/** `sym` is an inline method with a known body to inline.
4344
*/
@@ -226,12 +227,15 @@ object Inliner {
226227

227228
/** Replace `Inlined` node by a block that contains its bindings and expansion */
228229
def dropInlined(inlined: Inlined)(using Context): Tree =
229-
// In case that bindings are present we are adding SourcePosition attachement both to the resulting block and to the expansion
230+
val topLevelClass = Some(inlined.call.symbol.topLevelClass).filter(_.exists)
231+
val inliningPosition = InliningPosition(inlined.sourcePos, topLevelClass)
232+
233+
// In case that bindings are present we are adding InliningPosition attachement both to the resulting block and to the expansion
230234
// as in some cases the block is removed in one of later phases and attachment is lost.
231235
val tree1 =
232236
if inlined.bindings.isEmpty then inlined.expansion
233-
else cpy.Block(inlined)(inlined.bindings, inlined.expansion.withAttachment(InliningPosition, inlined.sourcePos))
234-
tree1.withAttachment(InliningPosition, inlined.sourcePos)
237+
else cpy.Block(inlined)(inlined.bindings, inlined.expansion.withAttachment(InliningPosition, inliningPosition))
238+
tree1.withAttachment(InliningPosition, inliningPosition)
235239

236240
/** Leave only a call trace consisting of
237241
* - a reference to the top-level class from which the call was inlined,

0 commit comments

Comments
 (0)