@@ -6,11 +6,11 @@ import dotc.CompilationUnit
6
6
import dotc .ast .tpd ._
7
7
import dotc .util .{ SourcePosition , SourceFile }
8
8
import dotc .core .Contexts ._
9
+ import dotc .core .Symbols .Symbol
9
10
import dotc .report
10
11
import dotc .typer .Inliner .InliningPosition
11
12
import collection .mutable
12
13
13
- import scala .collection .mutable .StringBuilder
14
14
15
15
object InlinedSourceMaps :
16
16
private case class Request (targetPos : SourcePosition , origPos : SourcePosition , firstFakeLine : Int )
@@ -61,17 +61,26 @@ object InlinedSourceMaps:
61
61
b ++= " *E\n "
62
62
end Stratum
63
63
64
- def sourceMapFor (cunit : CompilationUnit )(using Context ): InlinedSourceMap =
64
+ def sourceMapFor (cunit : CompilationUnit )(internalNameProvider : Symbol => String )( using Context ): InlinedSourceMap =
65
65
val requests = mutable.ListBuffer .empty[Request ]
66
66
var lastLine = cunit.tpdTree.sourcePos.endLine
67
+ var internalNames = Map .empty[SourceFile , String ]
67
68
68
69
class RequestCollector (enclosingFile : SourceFile ) extends TreeTraverser :
69
70
override def traverse (tree : Tree )(using Context ): Unit =
70
71
if tree.source != enclosingFile && tree.source != cunit.source then
71
72
tree.getAttachment(InliningPosition ) match
72
- case Some (targetPos) =>
73
+ case Some (InliningPosition ( targetPos, cls) ) =>
73
74
val firstFakeLine = allocate(tree.sourcePos)
74
75
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 _ => ()
75
84
RequestCollector (tree.source).traverseChildren(tree)
76
85
case None =>
77
86
// Not exactly sure in which cases it is happening. Should we report warning?
@@ -85,17 +94,24 @@ object InlinedSourceMaps:
85
94
line
86
95
87
96
RequestCollector (cunit.source).traverse(cunit.tpdTree)
88
- InlinedSourceMap (cunit, requests.toList)
97
+ InlinedSourceMap (cunit, requests.toList, internalNames )
89
98
end sourceMapFor
90
99
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
+
92
105
def debugExtension : Option [String ] = Option .when(requests.nonEmpty) {
93
106
val scalaStratum =
94
107
val files = cunit.source :: requests.map(_.origPos.source).distinct.filter(_ != cunit.source)
95
108
val mappings = requests.map { case Request (_, origPos, firstFakeLine) =>
96
109
Mapping (origPos.startLine, files.indexOf(origPos.source) + 1 , origPos.lines.length, firstFakeLine, 1 )
97
110
}
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
+ )
99
115
100
116
val debugStratum =
101
117
val mappings = requests.map { case Request (targetPos, origPos, firstFakeLine) =>
0 commit comments