Skip to content

Commit

Permalink
Shrink reserved TASTy attribute categories
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed Nov 30, 2023
1 parent 9ceef59 commit cad4d30
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package dotty.tools.dotc.core.tasty
import dotty.tools.dotc.ast.{tpd, untpd}

import dotty.tools.tasty.TastyBuffer
import dotty.tools.tasty.TastyFormat, TastyFormat.AttributesSection
import dotty.tools.tasty.TastyFormat.*

object AttributePickler:

Expand All @@ -15,12 +15,12 @@ object AttributePickler:
pickler.newSection(AttributesSection, buf)

for tag <- attributes.booleanTags do
assert(tag < TastyFormat.firstStringAttrTag, "Not a boolean attribute tag: " + tag)
assert(isBooleanAttrTag(tag), "Not a boolean attribute tag: " + tag)
buf.writeByte(tag)

assert(attributes.stringTagValues.exists(_._1 == TastyFormat.SOURCEFILEattr))
assert(attributes.stringTagValues.exists(_._1 == SOURCEFILEattr))
for (tag, value) <- attributes.stringTagValues do
assert(TastyFormat.firstStringAttrTag <= tag && tag < TastyFormat.firstUnassignedAttrTag, "Not a string attribute tag: " + tag)
assert(isStringAttrTag(tag), "Not a string attribute tag: " + tag)
val utf8Ref = pickler.nameBuffer.utf8Index(value)
buf.writeByte(tag)
buf.writeNat(utf8Ref.index)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import scala.language.unsafeNulls
import scala.collection.immutable.BitSet
import scala.collection.immutable.TreeMap

import dotty.tools.tasty.{TastyFormat, TastyReader, TastyBuffer}
import dotty.tools.tasty.{TastyFormat, TastyReader, TastyBuffer}, TastyFormat.{isBooleanAttrTag, isStringAttrTag}
import dotty.tools.dotc.core.tasty.TastyUnpickler.NameTable

class AttributeUnpickler(reader: TastyReader, nameAtRef: NameTable):
Expand All @@ -17,9 +17,9 @@ class AttributeUnpickler(reader: TastyReader, nameAtRef: NameTable):

while !isAtEnd do
val tag = readByte()
if tag < TastyFormat.firstStringAttrTag then
if isBooleanAttrTag(tag) then
booleanTags += tag
else if tag < TastyFormat.firstUnassignedAttrTag then
else if isStringAttrTag(tag) then
val utf8Ref = readNameRef()
val value = nameAtRef(utf8Ref).toString
stringTagValue += tag -> value
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/tasty/TastyPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ class TastyPrinter(bytes: Array[Byte]) {
while !isAtEnd do
val tag = readByte()
sb.append(" ").append(attributeTagToString(tag))
if tag < firstStringAttrTag then ()
else if tag < firstUnassignedAttrTag then
if isBooleanAttrTag(tag) then ()
else if isBooleanAttrTag(tag) then
val utf8Ref = readNameRef()
val value = nameAtRef(utf8Ref).toString
sb.append(nameStr(s" ${utf8Ref.index} [$value]"))
Expand Down
26 changes: 16 additions & 10 deletions tasty/src/dotty/tools/tasty/TastyFormat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,13 @@ Standard Section: "Attributes" Attribute*
SOURCEFILEattr Utf8Ref
```
Note: Attribute tags are grouped into 2 categories that determine what follows, and thus allow to compute the size of the tagged tree in a generic way.
Note: Attribute tags are grouped into categories that determine what follows, and thus allow to compute the size of the tagged tree in a generic way.
Unassigned categories can be used to extend and existing category or to add new kinds of attributes
```none
Attribute Category 1 (tags 1-64) : tag
Attribute Category 2 (tags 65-128): tag Utf8Ref
Attribute Category 1 (tags 1-32) : tag
Attribute Category 2 (tags 33-64): // not assigned yet
Attribute Category 3 (tags 129-160): tag Utf8Ref
Attribute Category 4 (tags 161-255): // not assigned yet
```
**************************************************************************************/
Expand Down Expand Up @@ -617,21 +620,24 @@ object TastyFormat {

// Attributes tags

// Attr Cat. 1: tag
final val firstBooleanAttrTag = SCALA2STANDARDLIBRARYattr
// Attribute Category 1 (tags 1-32) : tag
def isBooleanAttrTag(tag: Int): Boolean = 1 <= tag && tag <= 32
final val SCALA2STANDARDLIBRARYattr = 1
final val EXPLICITNULLSattr = 2
final val CAPTURECHECKEDattr = 3
final val WITHPUREFUNSattr = 4
final val JAVAattr = 5
final val OUTLINEattr = 6

// Attr Cat. 2: tag UTF8
final val firstStringAttrTag = SOURCEFILEattr
final val SOURCEFILEattr = 128
// Attribute Category 2 (tags 33-64): unassigned

// Attr Cat. 3: unassigned
final val firstUnassignedAttrTag = 129
// Attribute Category 3 (tags 129-160): tag Utf8Ref
def isStringAttrTag(tag: Int): Boolean = 129 <= tag && tag <= 160
final val SOURCEFILEattr = 129

// Attribute Category 4 (tags 161-255): unassigned

// end of Attributes tags


/** Useful for debugging */
Expand Down

0 comments on commit cad4d30

Please sign in to comment.