Skip to content

Commit 2712222

Browse files
committed
Make TASTy printer show tags in the binary format
This is to make it more robust in case there is an invalid/unhandled tag.
1 parent 4ebaa73 commit 2712222

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@ import java.nio.charset.StandardCharsets
1010
class AttributeUnpickler(reader: TastyReader):
1111
import reader._
1212

13-
lazy val attributes = {
13+
lazy val attributeTags: List[Int] =
14+
val listBuilder = List.newBuilder[Int]
15+
while !isAtEnd do listBuilder += readNat()
16+
listBuilder.result()
17+
18+
lazy val attributes: Attributes = {
1419
var scala2StandardLibrary = false
15-
while (!isAtEnd) {
16-
readNat() match
17-
case TastyFormat.SCALA2STANDARDLIBRARYattr =>
18-
scala2StandardLibrary = true
20+
for attributeTag <- attributeTags do
21+
attributeTag match
22+
case TastyFormat.SCALA2STANDARDLIBRARYattr => scala2StandardLibrary = true
1923
case attribute =>
2024
assert(false, "Unexpected attribute value: " + attribute)
21-
}
2225
Attributes(
2326
scala2StandardLibrary,
2427
)

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,15 +225,15 @@ class TastyPrinter(bytes: Array[Byte]) {
225225
}
226226

227227
class AttributesSectionUnpickler extends SectionUnpickler[String](AttributesSection) {
228-
228+
import dotty.tools.tasty.TastyFormat.attributeTagToString
229229
private val sb: StringBuilder = new StringBuilder
230230

231231
def unpickle(reader: TastyReader, tastyName: NameTable): String = {
232232
sb.append(s" ${reader.endAddr.index - reader.currentAddr.index}")
233-
val attributes = new AttributeUnpickler(reader).attributes
233+
val attributeTags = new AttributeUnpickler(reader).attributeTags
234234
sb.append(s" attributes bytes:\n")
235-
if attributes.scala2StandardLibrary then
236-
sb.append(" SCALA2STANDARDLIBRARYattr\n")
235+
for attributeTag <- attributeTags do
236+
sb.append(" ").append(attributeTagToString(attributeTag)).append("\n")
237237
sb.result
238238
}
239239
}

tasty/src/dotty/tools/tasty/TastyFormat.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,10 @@ object TastyFormat {
824824
case HOLE => "HOLE"
825825
}
826826

827+
def attributeTagToString(tag: Int): String = tag match {
828+
case SCALA2STANDARDLIBRARYattr => "SCALA2STANDARDLIBRARYattr"
829+
}
830+
827831
/** @return If non-negative, the number of leading references (represented as nats) of a length/trees entry.
828832
* If negative, minus the number of leading non-reference trees.
829833
*/

0 commit comments

Comments
 (0)