Skip to content

Commit cad4d30

Browse files
committed
Shrink reserved TASTy attribute categories
1 parent 9ceef59 commit cad4d30

File tree

4 files changed

+25
-19
lines changed

4 files changed

+25
-19
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package dotty.tools.dotc.core.tasty
33
import dotty.tools.dotc.ast.{tpd, untpd}
44

55
import dotty.tools.tasty.TastyBuffer
6-
import dotty.tools.tasty.TastyFormat, TastyFormat.AttributesSection
6+
import dotty.tools.tasty.TastyFormat.*
77

88
object AttributePickler:
99

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

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

21-
assert(attributes.stringTagValues.exists(_._1 == TastyFormat.SOURCEFILEattr))
21+
assert(attributes.stringTagValues.exists(_._1 == SOURCEFILEattr))
2222
for (tag, value) <- attributes.stringTagValues do
23-
assert(TastyFormat.firstStringAttrTag <= tag && tag < TastyFormat.firstUnassignedAttrTag, "Not a string attribute tag: " + tag)
23+
assert(isStringAttrTag(tag), "Not a string attribute tag: " + tag)
2424
val utf8Ref = pickler.nameBuffer.utf8Index(value)
2525
buf.writeByte(tag)
2626
buf.writeNat(utf8Ref.index)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import scala.language.unsafeNulls
55
import scala.collection.immutable.BitSet
66
import scala.collection.immutable.TreeMap
77

8-
import dotty.tools.tasty.{TastyFormat, TastyReader, TastyBuffer}
8+
import dotty.tools.tasty.{TastyFormat, TastyReader, TastyBuffer}, TastyFormat.{isBooleanAttrTag, isStringAttrTag}
99
import dotty.tools.dotc.core.tasty.TastyUnpickler.NameTable
1010

1111
class AttributeUnpickler(reader: TastyReader, nameAtRef: NameTable):
@@ -17,9 +17,9 @@ class AttributeUnpickler(reader: TastyReader, nameAtRef: NameTable):
1717

1818
while !isAtEnd do
1919
val tag = readByte()
20-
if tag < TastyFormat.firstStringAttrTag then
20+
if isBooleanAttrTag(tag) then
2121
booleanTags += tag
22-
else if tag < TastyFormat.firstUnassignedAttrTag then
22+
else if isStringAttrTag(tag) then
2323
val utf8Ref = readNameRef()
2424
val value = nameAtRef(utf8Ref).toString
2525
stringTagValue += tag -> value

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ class TastyPrinter(bytes: Array[Byte]) {
236236
while !isAtEnd do
237237
val tag = readByte()
238238
sb.append(" ").append(attributeTagToString(tag))
239-
if tag < firstStringAttrTag then ()
240-
else if tag < firstUnassignedAttrTag then
239+
if isBooleanAttrTag(tag) then ()
240+
else if isBooleanAttrTag(tag) then
241241
val utf8Ref = readNameRef()
242242
val value = nameAtRef(utf8Ref).toString
243243
sb.append(nameStr(s" ${utf8Ref.index} [$value]"))

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,13 @@ Standard Section: "Attributes" Attribute*
282282
SOURCEFILEattr Utf8Ref
283283
```
284284
285-
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.
285+
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.
286+
Unassigned categories can be used to extend and existing category or to add new kinds of attributes
286287
```none
287-
Attribute Category 1 (tags 1-64) : tag
288-
Attribute Category 2 (tags 65-128): tag Utf8Ref
288+
Attribute Category 1 (tags 1-32) : tag
289+
Attribute Category 2 (tags 33-64): // not assigned yet
290+
Attribute Category 3 (tags 129-160): tag Utf8Ref
291+
Attribute Category 4 (tags 161-255): // not assigned yet
289292
```
290293
291294
**************************************************************************************/
@@ -617,21 +620,24 @@ object TastyFormat {
617620

618621
// Attributes tags
619622

620-
// Attr Cat. 1: tag
621-
final val firstBooleanAttrTag = SCALA2STANDARDLIBRARYattr
623+
// Attribute Category 1 (tags 1-32) : tag
624+
def isBooleanAttrTag(tag: Int): Boolean = 1 <= tag && tag <= 32
622625
final val SCALA2STANDARDLIBRARYattr = 1
623626
final val EXPLICITNULLSattr = 2
624627
final val CAPTURECHECKEDattr = 3
625628
final val WITHPUREFUNSattr = 4
626629
final val JAVAattr = 5
627630
final val OUTLINEattr = 6
628631

629-
// Attr Cat. 2: tag UTF8
630-
final val firstStringAttrTag = SOURCEFILEattr
631-
final val SOURCEFILEattr = 128
632+
// Attribute Category 2 (tags 33-64): unassigned
632633

633-
// Attr Cat. 3: unassigned
634-
final val firstUnassignedAttrTag = 129
634+
// Attribute Category 3 (tags 129-160): tag Utf8Ref
635+
def isStringAttrTag(tag: Int): Boolean = 129 <= tag && tag <= 160
636+
final val SOURCEFILEattr = 129
637+
638+
// Attribute Category 4 (tags 161-255): unassigned
639+
640+
// end of Attributes tags
635641

636642

637643
/** Useful for debugging */

0 commit comments

Comments
 (0)