Skip to content

Commit 5778f8e

Browse files
committed
elide base index of sections
1 parent 6e1bba5 commit 5778f8e

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

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

+10-4
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ class TastyPrinter(bytes: Array[Byte], val testPickler: Boolean) {
187187
}
188188
indent -= 2
189189
}
190-
sb.append(s"\n\nTrees (${endAddr.index - startAddr.index} bytes, starting from $base):")
190+
sb.append(sectionHeader("Trees", reader, lineEnd = false))
191191
while (!isAtEnd) {
192192
printTree()
193193
newLine()
@@ -199,7 +199,7 @@ class TastyPrinter(bytes: Array[Byte], val testPickler: Boolean) {
199199
def unpickle0(reader: TastyReader)(using tastyName: NameRefs): Unit = {
200200
import reader.*
201201
val posUnpickler = new PositionUnpickler(reader, tastyName)
202-
sb.append(s"\n\nPositions (${reader.endAddr.index - reader.startAddr.index} bytes, starting from $base):\n")
202+
sb.append(sectionHeader("Positions", reader))
203203
val lineSizes = posUnpickler.lineSizes
204204
sb.append(s" lines: ${lineSizes.length}\n")
205205
sb.append(s" line sizes:\n")
@@ -232,7 +232,7 @@ class TastyPrinter(bytes: Array[Byte], val testPickler: Boolean) {
232232
import reader.*
233233
val comments = new CommentUnpickler(reader).comments
234234
if !comments.isEmpty then
235-
sb.append(s"\n\nComments (${reader.endAddr.index - reader.startAddr.index} bytes, starting from $base):\n")
235+
sb.append(sectionHeader("Comments", reader))
236236
val sorted = comments.toSeq.sortBy(_._1.index)
237237
for ((addr, cmt) <- sorted) {
238238
sb.append(treeStr("%6d".format(addr.index)))
@@ -245,7 +245,7 @@ class TastyPrinter(bytes: Array[Byte], val testPickler: Boolean) {
245245
import dotty.tools.tasty.TastyFormat.*
246246
def unpickle0(reader: TastyReader)(using nameAtRef: NameRefs): Unit = {
247247
import reader.*
248-
sb.append(s"\n\nAttributes (${reader.endAddr.index - reader.startAddr.index} bytes, starting from $base):\n")
248+
sb.append(sectionHeader("Attributes", reader))
249249
while !isAtEnd do
250250
// TODO: Should we elide attributes under testPickler? (i.e.
251251
// if we add new attributes many check files will need to be updated)
@@ -290,6 +290,12 @@ class TastyPrinter(bytes: Array[Byte], val testPickler: Boolean) {
290290
}
291291
}
292292

293+
private final def sectionHeader(name: String, reader: TastyReader, lineEnd: Boolean = true): String =
294+
val count = reader.endAddr.index - reader.startAddr.index
295+
val suffix = if lineEnd then "\n" else ""
296+
val base = if testPickler then "<elided base index>" else reader.base
297+
s"\n\n$name ($count bytes, starting from $base):$suffix"
298+
293299
abstract class PrinterSectionUnpickler[T](val name: String) {
294300
def unpickle0(reader: TastyReader)(using refs: NameRefs): T
295301
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ class Pickler extends Phase {
308308
if hasDiff(printed, checkContents) then
309309
output("after-printing.txt", printed)
310310
report.error(em"""TASTy printer difference for $cls in ${cls.source}, did not match ${check},
311-
| output dumped in after-printing.txt, check diff with `git diff --no-index -- after-printing.txt ${check}`
311+
| output dumped in after-printing.txt, check diff with `git diff --no-index -- $check after-printing.txt`
312312
| actual output:
313313
|$printed""")
314314
}

tests/pos/i19806/J.tastycheck

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Names (217 bytes, starting from 80):
3232
25: Attributes
3333

3434

35-
Trees (145 bytes, starting from 300):
35+
Trees (145 bytes, starting from <elided base index>):
3636
0: PACKAGE(142)
3737
3: TERMREFpkg 1 [p]
3838
5: VALDEF(11) 2 [J]
@@ -113,7 +113,7 @@ Trees (145 bytes, starting from 300):
113113
143: SHAREDtype 38
114114
145:
115115

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

157157

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

0 commit comments

Comments
 (0)