Skip to content

Commit

Permalink
Make TASTy printer show tags in the binary format
Browse files Browse the repository at this point in the history
This is to make it more robust in case there is an invalid/unhandled tag.
  • Loading branch information
nicolasstucki committed Oct 26, 2023
1 parent 4ebaa73 commit 2712222
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ import java.nio.charset.StandardCharsets
class AttributeUnpickler(reader: TastyReader):
import reader._

lazy val attributes = {
lazy val attributeTags: List[Int] =
val listBuilder = List.newBuilder[Int]
while !isAtEnd do listBuilder += readNat()
listBuilder.result()

lazy val attributes: Attributes = {
var scala2StandardLibrary = false
while (!isAtEnd) {
readNat() match
case TastyFormat.SCALA2STANDARDLIBRARYattr =>
scala2StandardLibrary = true
for attributeTag <- attributeTags do
attributeTag match
case TastyFormat.SCALA2STANDARDLIBRARYattr => scala2StandardLibrary = true
case attribute =>
assert(false, "Unexpected attribute value: " + attribute)
}
Attributes(
scala2StandardLibrary,
)
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/core/tasty/TastyPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,15 @@ class TastyPrinter(bytes: Array[Byte]) {
}

class AttributesSectionUnpickler extends SectionUnpickler[String](AttributesSection) {

import dotty.tools.tasty.TastyFormat.attributeTagToString
private val sb: StringBuilder = new StringBuilder

def unpickle(reader: TastyReader, tastyName: NameTable): String = {
sb.append(s" ${reader.endAddr.index - reader.currentAddr.index}")
val attributes = new AttributeUnpickler(reader).attributes
val attributeTags = new AttributeUnpickler(reader).attributeTags
sb.append(s" attributes bytes:\n")
if attributes.scala2StandardLibrary then
sb.append(" SCALA2STANDARDLIBRARYattr\n")
for attributeTag <- attributeTags do
sb.append(" ").append(attributeTagToString(attributeTag)).append("\n")
sb.result
}
}
Expand Down
4 changes: 4 additions & 0 deletions tasty/src/dotty/tools/tasty/TastyFormat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,10 @@ object TastyFormat {
case HOLE => "HOLE"
}

def attributeTagToString(tag: Int): String = tag match {
case SCALA2STANDARDLIBRARYattr => "SCALA2STANDARDLIBRARYattr"
}

/** @return If non-negative, the number of leading references (represented as nats) of a length/trees entry.
* If negative, minus the number of leading non-reference trees.
*/
Expand Down

0 comments on commit 2712222

Please sign in to comment.