Skip to content

Commit 93d43be

Browse files
committed
Use name table for string attributes
1 parent 035d885 commit 93d43be

File tree

6 files changed

+25
-12
lines changed

6 files changed

+25
-12
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ object AttributePickler:
2121
assert(attributes.stringTagValues.exists(_._1 == TastyFormat.SOURCEFILEattr))
2222
for (tag, value) <- attributes.stringTagValues do
2323
assert(TastyFormat.firstStringAttrTag <= tag && tag < TastyFormat.firstUnassignedAttrTag, "Not a string attribute tag: " + tag)
24+
val utf8Ref = pickler.nameBuffer.utf8Index(value)
2425
buf.writeByte(tag)
25-
buf.writeUtf8(value)
26+
buf.writeNat(utf8Ref.index)
2627

2728
end pickleAttributes
2829

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import scala.collection.immutable.BitSet
66
import scala.collection.immutable.TreeMap
77

88
import dotty.tools.tasty.{TastyFormat, TastyReader, TastyBuffer}
9+
import dotty.tools.dotc.core.tasty.TastyUnpickler.NameTable
910

10-
class AttributeUnpickler(reader: TastyReader):
11+
class AttributeUnpickler(reader: TastyReader, nameAtRef: NameTable):
1112
import reader._
1213

1314
lazy val attributes: Attributes = {
@@ -19,7 +20,9 @@ class AttributeUnpickler(reader: TastyReader):
1920
if tag < TastyFormat.firstStringAttrTag then
2021
booleanTags += tag
2122
else if tag < TastyFormat.firstUnassignedAttrTag then
22-
stringTagValue += tag -> readUtf8()
23+
val utf8Ref = readNameRef()
24+
val value = nameAtRef(utf8Ref).toString
25+
stringTagValue += tag -> value
2326
else
2427
assert(false, "unknown attribute tag: " + tag)
2528

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ object DottyUnpickler {
3939

4040
class AttributesSectionUnpickler extends SectionUnpickler[AttributeUnpickler](AttributesSection) {
4141
def unpickle(reader: TastyReader, nameAtRef: NameTable): AttributeUnpickler =
42-
new AttributeUnpickler(reader)
42+
new AttributeUnpickler(reader, nameAtRef)
4343
}
4444
}
4545

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ class NameBuffer extends TastyBuffer(10000) {
4949
}
5050
}
5151

52+
def utf8Index(value: String): NameRef =
53+
import Decorators.toTermName
54+
nameIndex(value.toTermName)
55+
5256
private inline def withLength(inline op: Unit, lengthWidth: Int = 1): Unit = {
5357
val lengthAddr = currentAddr
5458
var i = 0

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,18 @@ class TastyPrinter(bytes: Array[Byte]) {
232232
def unpickle(reader: TastyReader, tastyName: NameTable): String = {
233233
import reader.*
234234
sb.append(s" ${reader.endAddr.index - reader.currentAddr.index}")
235-
val attributes = new AttributeUnpickler(reader).attributes
236235
sb.append(s" attributes bytes:\n")
237-
238-
for tag <- attributes.booleanTags do
239-
sb.append(" ").append(attributeTagToString(tag)).append("\n")
240-
for (tag, value) <- attributes.stringTagValues do
236+
while !isAtEnd do
237+
val tag = readByte()
241238
sb.append(" ").append(attributeTagToString(tag))
242-
.append(" ").append(value).append("\n")
239+
if tag < firstStringAttrTag then ()
240+
else if tag < firstUnassignedAttrTag then
241+
val utf8Ref = readNameRef()
242+
val value = nameAtRef(utf8Ref).toString
243+
sb.append(nameStr(s" ${utf8Ref.index} [$value]"))
244+
else
245+
sb.append("unknown attribute tag: ").append(tag)
246+
sb.append("\n")
243247
sb.result
244248
}
245249
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Macro-format:
5050
// If positive, this is a NameRef for the fully qualified name of a term parameter.
5151
5252
NameRef = Nat // ordinal number of name in name table, starting from 1.
53+
Utf8Ref = Nat // ordinal number of UTF8 in name table, starting from 1.
5354
```
5455
5556
Note: Unqualified names in the name table are strings. The context decides whether a name is
@@ -278,13 +279,13 @@ Standard Section: "Attributes" Attribute*
278279
WITHPUREFUNSattr
279280
JAVAattr
280281
OUTLINEattr
281-
SOURCEFILEattr Utf8
282+
SOURCEFILEattr Utf8Ref
282283
```
283284
284285
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.
285286
```none
286287
Attribute Category 1 (tags 1-64) : tag
287-
Attribute Category 2 (tags 65-128): tag UTF8
288+
Attribute Category 2 (tags 65-128): tag Utf8Ref
288289
```
289290
290291
**************************************************************************************/

0 commit comments

Comments
 (0)