Skip to content

Commit 0631d67

Browse files
committed
Ensure no duplicated and ordered TASTy attributes.
1 parent 791c6fd commit 0631d67

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,21 @@ object AttributePickler:
1414
): Unit =
1515
pickler.newSection(AttributesSection, buf)
1616

17+
var lastTag = -1
18+
def assertTagOrder(tag: Int): Unit =
19+
assert(tag != lastTag, s"duplicate attribute tag: $tag")
20+
assert(tag > lastTag, s"attribute tags are not ordered: $tag after $lastTag")
21+
lastTag = tag
22+
1723
for tag <- attributes.booleanTags do
1824
assert(isBooleanAttrTag(tag), "Not a boolean attribute tag: " + tag)
25+
assertTagOrder(tag)
1926
buf.writeByte(tag)
2027

2128
assert(attributes.stringTagValues.exists(_._1 == SOURCEFILEattr))
2229
for (tag, value) <- attributes.stringTagValues do
2330
assert(isStringAttrTag(tag), "Not a string attribute tag: " + tag)
31+
assertTagOrder(tag)
2432
val utf8Ref = pickler.nameBuffer.utf8Index(value)
2533
buf.writeByte(tag)
2634
buf.writeNat(utf8Ref.index)

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class AttributeUnpickler(reader: TastyReader, nameAtRef: NameTable):
1515
val booleanTags = BitSet.newBuilder
1616
val stringTagValue = List.newBuilder[(Int, String)]
1717

18+
var lastTag = -1
1819
while !isAtEnd do
1920
val tag = readByte()
2021
if isBooleanAttrTag(tag) then
@@ -26,6 +27,11 @@ class AttributeUnpickler(reader: TastyReader, nameAtRef: NameTable):
2627
else
2728
assert(false, "unknown attribute tag: " + tag)
2829

30+
assert(tag != lastTag, s"duplicate attribute tag: $tag")
31+
assert(tag > lastTag, s"attribute tags are not ordered: $tag after $lastTag")
32+
lastTag = tag
33+
end while
34+
2935
new Attributes(booleanTags.result(), stringTagValue.result())
3036
}
3137

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ Standard Section: "Attributes" Attribute*
281281
OUTLINEattr
282282
SOURCEFILEattr Utf8Ref
283283
```
284+
Attribute tags cannot be repeated in an attribute section. Attributes are ordered by the tag ordinal.
284285
285286
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.
286287
Unassigned categories can be used to extend and existing category or to add new kinds of attributes

0 commit comments

Comments
 (0)