Skip to content

Commit c07bbbd

Browse files
committed
Comments and some useful prints added
1 parent c09374f commit c07bbbd

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ trait BCodeSkelBuilder extends BCodeHelpers {
282282

283283
if (emitSource) {
284284
sourceMap = sourceMapFor(cunit)(s => classBTypeFromSymbol(s).internalName)
285+
// debugExtension is the ScalaDebug Stratum
286+
// println(s"sourceMap for ${claszSymbol.fullName} = ${sourceMap.debugExtension}")
285287
cnode.visitSource(cunit.source.file.name, sourceMap.debugExtension.orNull)
286288
}
287289

@@ -564,7 +566,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
564566
lnn.line = nr
565567
case _ =>
566568
mnode.visitLineNumber(nr, currProgramPoint())
567-
569+
568570
def lineNumber(tree: Tree): Unit = {
569571
if !emitLines || !tree.span.exists then return;
570572
if tree.source != cunit.source then

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ object InlinedSourceMaps:
8585
val requests = mutable.ListBuffer.empty[(SourcePosition, SourcePosition)]
8686
var internalNames = Map.empty[SourceFile, String]
8787

88+
// Collect all inlined calls in the compilation unit
89+
8890
class RequestCollector(enclosingFile: SourceFile) extends TreeTraverser:
8991
override def traverse(tree: Tree)(using Context): Unit =
9092
if tree.source != enclosingFile && tree.source != cunit.source then
@@ -95,6 +97,7 @@ object InlinedSourceMaps:
9597
cls match
9698
case Some(symbol) if !internalNames.isDefinedAt(tree.source) =>
9799
internalNames += (tree.source -> internalNameProvider(symbol))
100+
//println(s"Internal name for ${tree.source} is ${internalNames(tree.source)}")
98101
// We are skipping any internal name info if we already have one stored in our map
99102
// because a debugger will use internal name only to localize matching source.
100103
// Both old and new internal names are associated with the same source file
@@ -107,17 +110,30 @@ object InlinedSourceMaps:
107110
else traverseChildren(tree)
108111
end RequestCollector
109112

113+
// Create the mapping from the real source files to the real and virtual lines
114+
110115
// Don't generate mappings for the quotes compiled at runtime by the staging compiler
111116
if cunit.source.file.isVirtual then InlinedSourceMap(cunit, Nil, Map.empty[SourceFile, String])
112117
else
113-
var lastLine = cunit.tpdTree.sourcePos.endLine
118+
var lastLine = cunit.tpdTree.sourcePos.endLine // Last line of the source file
119+
//println(s"lastLine = $lastLine")
114120
def allocate(origPos: SourcePosition): Int =
115-
val line = lastLine + 1
121+
val line = lastLine + 1 // Add an empty line. Why ?
116122
lastLine += origPos.lines.length
123+
//println(s"LastLine = $lastLine, line = $line")
117124
line
118125

119126
RequestCollector(cunit.source).traverse(cunit.tpdTree)
120127
val allocated = requests.sortBy(_._1.start).map(r => Request(r._1, r._2, allocate(r._2)))
128+
// targetPos.startLine is the line in the source file where the inlined call is located
129+
// origPos.startLine is the line in the source file where the inlined is defined
130+
// firstFakeLine is the first virtual line of the inline
131+
/*allocated.foreach { case Request(targetPos, origPos, firstFakeLine) =>
132+
println(s"targetPos = ${targetPos.startLine}, origPos = ${origPos.startLine}, firstFakeLine = $firstFakeLine")
133+
}*/
134+
// internalNames is a map from source file to the internal name of the class that contains the inlined code
135+
// Map(local/Macro_1.scala -> Macro_1$package$)
136+
//println(s"internalNames = $internalNames")
121137
InlinedSourceMap(cunit, allocated.toList, internalNames)
122138
end sourceMapFor
123139

@@ -126,10 +142,13 @@ object InlinedSourceMaps:
126142
requests: List[Request],
127143
internalNames: Map[SourceFile, String])(using Context):
128144

145+
// Generate the Scala Stratum and the ScalaDebug Stratum from the map created in sourceMapFor
146+
129147
def debugExtension: Option[String] = Option.when(requests.nonEmpty) {
130148
val scalaStratum =
131149
val files = cunit.source :: requests.map(_.origPos.source).distinct.filter(_ != cunit.source)
132150
val mappings = requests.map { case Request(_, origPos, firstFakeLine) =>
151+
//println(s" origPos = ${origPos.startLine}, files.indexOf(origPos.source) + 1 = ${files.indexOf(origPos.source) + 1}, origPos.lines.length = ${origPos.lines.length}, firstFakeLine = $firstFakeLine")
133152
Mapping(origPos.startLine, files.indexOf(origPos.source) + 1, origPos.lines.length, firstFakeLine, 1)
134153
}
135154
Stratum("Scala",

compiler/src/dotty/tools/dotc/inlines/Inlines.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,15 @@ object Inlines:
249249

250250
/** Replace `Inlined` node by a block that contains its bindings and expansion */
251251
def dropInlined(inlined: Inlined)(using Context): Tree =
252+
//println(i"inlined : ${inlined.show}")
253+
//println(i"inlined is empty : ${inlined.call.isEmpty}")
252254
val topLevelClass = Option.when(!inlined.call.isEmpty)(inlined.call.symbol.topLevelClass)
255+
//println(i"topLevelClass : ${topLevelClass}")
253256
val inliningPosition = InliningPosition(inlined.sourcePos, topLevelClass)
257+
//println(i"inliningPosition : ${inliningPosition}")
254258
val withPos = inlined.expansion.withAttachment(InliningPosition, inliningPosition)
259+
//println(i"withPos : ${withPos}")
260+
//println(i"inlined.bindings : ${inlined.bindings}")
255261
if inlined.bindings.isEmpty then withPos else cpy.Block(inlined)(inlined.bindings, withPos)
256262

257263
/** Leave only a call trace consisting of

compiler/src/dotty/tools/dotc/transform/ExpandPrivate.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class ExpandPrivate extends MiniPhase with IdentityDenotTransformer { thisPhase
6666
private def ensurePrivateAccessible(d: SymDenotation)(using Context) =
6767
if (isVCPrivateParamAccessor(d))
6868
d.ensureNotPrivate.installAfter(thisPhase)
69-
else if (d.is(PrivateTerm) && !d.owner.is(Package) && d.owner != ctx.owner.lexicallyEnclosingClass && !d.is(InlineProxy) && !d.is(Synthetic)) {
69+
else if (d.is(PrivateTerm) && !d.owner.is(Package) && d.owner != ctx.owner.lexicallyEnclosingClass && !d.is(InlineProxy)) {
7070
// Paths `p1` and `p2` are similar if they have a common suffix that follows
7171
// possibly different directory paths. That is, their common suffix extends
7272
// in both cases either to the start of the path or to a file separator character.

0 commit comments

Comments
 (0)