Skip to content

Commit

Permalink
elide base index of sections
Browse files Browse the repository at this point in the history
  • Loading branch information
bishabosha committed Mar 13, 2024
1 parent 6e1bba5 commit 5778f8e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
14 changes: 10 additions & 4 deletions compiler/src/dotty/tools/dotc/core/tasty/TastyPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class TastyPrinter(bytes: Array[Byte], val testPickler: Boolean) {
}
indent -= 2
}
sb.append(s"\n\nTrees (${endAddr.index - startAddr.index} bytes, starting from $base):")
sb.append(sectionHeader("Trees", reader, lineEnd = false))
while (!isAtEnd) {
printTree()
newLine()
Expand All @@ -199,7 +199,7 @@ class TastyPrinter(bytes: Array[Byte], val testPickler: Boolean) {
def unpickle0(reader: TastyReader)(using tastyName: NameRefs): Unit = {
import reader.*
val posUnpickler = new PositionUnpickler(reader, tastyName)
sb.append(s"\n\nPositions (${reader.endAddr.index - reader.startAddr.index} bytes, starting from $base):\n")
sb.append(sectionHeader("Positions", reader))
val lineSizes = posUnpickler.lineSizes
sb.append(s" lines: ${lineSizes.length}\n")
sb.append(s" line sizes:\n")
Expand Down Expand Up @@ -232,7 +232,7 @@ class TastyPrinter(bytes: Array[Byte], val testPickler: Boolean) {
import reader.*
val comments = new CommentUnpickler(reader).comments
if !comments.isEmpty then
sb.append(s"\n\nComments (${reader.endAddr.index - reader.startAddr.index} bytes, starting from $base):\n")
sb.append(sectionHeader("Comments", reader))
val sorted = comments.toSeq.sortBy(_._1.index)
for ((addr, cmt) <- sorted) {
sb.append(treeStr("%6d".format(addr.index)))
Expand All @@ -245,7 +245,7 @@ class TastyPrinter(bytes: Array[Byte], val testPickler: Boolean) {
import dotty.tools.tasty.TastyFormat.*
def unpickle0(reader: TastyReader)(using nameAtRef: NameRefs): Unit = {
import reader.*
sb.append(s"\n\nAttributes (${reader.endAddr.index - reader.startAddr.index} bytes, starting from $base):\n")
sb.append(sectionHeader("Attributes", reader))
while !isAtEnd do
// TODO: Should we elide attributes under testPickler? (i.e.
// if we add new attributes many check files will need to be updated)
Expand Down Expand Up @@ -290,6 +290,12 @@ class TastyPrinter(bytes: Array[Byte], val testPickler: Boolean) {
}
}

private final def sectionHeader(name: String, reader: TastyReader, lineEnd: Boolean = true): String =
val count = reader.endAddr.index - reader.startAddr.index
val suffix = if lineEnd then "\n" else ""
val base = if testPickler then "<elided base index>" else reader.base
s"\n\n$name ($count bytes, starting from $base):$suffix"

abstract class PrinterSectionUnpickler[T](val name: String) {
def unpickle0(reader: TastyReader)(using refs: NameRefs): T
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/Pickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ class Pickler extends Phase {
if hasDiff(printed, checkContents) then
output("after-printing.txt", printed)
report.error(em"""TASTy printer difference for $cls in ${cls.source}, did not match ${check},
| output dumped in after-printing.txt, check diff with `git diff --no-index -- after-printing.txt ${check}`
| output dumped in after-printing.txt, check diff with `git diff --no-index -- $check after-printing.txt`
| actual output:
|$printed""")
}
Expand Down
6 changes: 3 additions & 3 deletions tests/pos/i19806/J.tastycheck
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Names (217 bytes, starting from 80):
25: Attributes


Trees (145 bytes, starting from 300):
Trees (145 bytes, starting from <elided base index>):
0: PACKAGE(142)
3: TERMREFpkg 1 [p]
5: VALDEF(11) 2 [J]
Expand Down Expand Up @@ -113,7 +113,7 @@ Trees (145 bytes, starting from 300):
143: SHAREDtype 38
145:

Positions (145 bytes, starting from 448):
Positions (145 bytes, starting from <elided base index>):
lines: 23
line sizes:
10, 0, 19, 0, 15, 0, 35, 29, 3, 0, 36, 29, 3, 0, 52, 41, 3, 0, 53, 41
Expand Down Expand Up @@ -155,7 +155,7 @@ Positions (145 bytes, starting from 448):
0: 23 [<elided source file name>]


Attributes (4 bytes, starting from 597):
Attributes (4 bytes, starting from <elided base index>):
JAVAattr
OUTLINEattr
SOURCEFILEattr 23 [<elided source file name>]

0 comments on commit 5778f8e

Please sign in to comment.