Skip to content

Commit 324f1d7

Browse files
committed
Fix TASTy source position printer
Now it properly shows that the sources form the position section are references in the name table. This includes the coloring of the indices and referenced names. ```diff source paths: - 0: t/Test.scala + 0: 21 [t/Test.scala] ```
1 parent 2e4e8fe commit 324f1d7

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

compiler/src/dotty/tools/dotc/core/tasty/PositionUnpickler.scala

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class PositionUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName) {
1818

1919
private var myLineSizes: Array[Int] = uninitialized
2020
private var mySpans: util.HashMap[Addr, Span] = uninitialized
21-
private var mySourcePaths: util.HashMap[Addr, String] = uninitialized
21+
private var mySourceNameRefs: util.HashMap[Addr, NameRef] = uninitialized
2222
private var isDefined = false
2323

2424
def ensureDefined(): Unit = {
@@ -31,15 +31,14 @@ class PositionUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName) {
3131
i += 1
3232

3333
mySpans = util.HashMap[Addr, Span]()
34-
mySourcePaths = util.HashMap[Addr, String]()
34+
mySourceNameRefs = util.HashMap[Addr, NameRef]()
3535
var curIndex = 0
3636
var curStart = 0
3737
var curEnd = 0
3838
while (!isAtEnd) {
3939
val header = readInt()
4040
if (header == SOURCE) {
41-
val path = nameAtRef(readNameRef()).toString
42-
mySourcePaths(Addr(curIndex)) = path
41+
mySourceNameRefs(Addr(curIndex)) = readNameRef()
4342
}
4443
else {
4544
val addrDelta = header >> 3
@@ -64,9 +63,9 @@ class PositionUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName) {
6463
mySpans
6564
}
6665

67-
private[tasty] def sourcePaths: util.ReadOnlyMap[Addr, String] = {
66+
private[tasty] def sourceNameRefs: util.ReadOnlyMap[Addr, NameRef] = {
6867
ensureDefined()
69-
mySourcePaths
68+
mySourceNameRefs
7069
}
7170

7271
private[tasty] def lineSizes: Array[Int] = {
@@ -75,5 +74,5 @@ class PositionUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName) {
7574
}
7675

7776
def spanAt(addr: Addr): Span = spans.getOrElse(addr, NoSpan)
78-
def sourcePathAt(addr: Addr): String = sourcePaths.getOrElse(addr, "")
77+
def sourcePathAt(addr: Addr): String = sourceNameRefs.get(addr).fold("")(nameAtRef(_).toString)
7978
}

compiler/src/dotty/tools/dotc/core/tasty/TastyPrinter.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,12 @@ class TastyPrinter(bytes: Array[Byte]) {
218218
sb.append(s": ${offsetToInt(pos.start)} .. ${pos.end}\n")
219219
}
220220

221-
val sources = posUnpickler.sourcePaths
221+
val sources = posUnpickler.sourceNameRefs
222222
sb.append(s"\n source paths:\n")
223223
val sortedPath = sources.toSeq.sortBy(_._1.index)
224-
for ((addr, path) <- sortedPath) {
224+
for ((addr, nameRef) <- sortedPath) {
225225
sb.append(treeStr("%6d: ".format(addr.index)))
226-
sb.append(path)
226+
sb.append(nameStr(s"${nameRef.index} [${tastyName(nameRef)}]"))
227227
sb.append("\n")
228228
}
229229

project/scripts/cmdTests

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ echo "testing sbt scalac -print-tasty"
2727
clear_out "$OUT"
2828
"$SBT" ";scalac $SOURCE -d $OUT ;scalac -print-tasty -color:never $TASTY" > "$tmp"
2929
grep -qe "0: ASTs" "$tmp"
30-
grep -qe "0: tests/pos/HelloWorld.scala" "$tmp"
30+
grep -qe "0: 41 [tests/pos/HelloWorld.scala]" "$tmp"
3131

3232
echo "testing that paths SourceFile annotations are relativized"
3333
clear_out "$OUT"

0 commit comments

Comments
 (0)