From 4ebaa73c0d47e328b7fac2e8c16ef83d6b9cf897 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 26 Oct 2023 17:35:07 +0200 Subject: [PATCH] Add Attributes data class --- .../dotty/tools/dotc/core/tasty/AttributePickler.scala | 6 +++--- .../dotty/tools/dotc/core/tasty/AttributeUnpickler.scala | 6 ++++-- compiler/src/dotty/tools/dotc/core/tasty/Attributes.scala | 5 +++++ .../src/dotty/tools/dotc/core/tasty/ScratchData.scala | 2 +- .../src/dotty/tools/dotc/core/tasty/TastyPrinter.scala | 4 ++-- .../src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala | 2 +- compiler/src/dotty/tools/dotc/transform/Pickler.scala | 8 ++++---- 7 files changed, 20 insertions(+), 13 deletions(-) create mode 100644 compiler/src/dotty/tools/dotc/core/tasty/Attributes.scala diff --git a/compiler/src/dotty/tools/dotc/core/tasty/AttributePickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/AttributePickler.scala index 8945c145e032..ea8829762fd0 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/AttributePickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/AttributePickler.scala @@ -10,14 +10,14 @@ import java.nio.charset.StandardCharsets object AttributePickler: def pickleAttributes( - scala2StandardLibrary: Boolean, + attributes: Attributes, pickler: TastyPickler, buf: TastyBuffer ): Unit = - if scala2StandardLibrary then // or any other attribute is set + if attributes.scala2StandardLibrary then // or any other attribute is set pickler.newSection(AttributesSection, buf) // Pickle attributes - if scala2StandardLibrary then buf.writeNat(TastyFormat.SCALA2STANDARDLIBRARYattr) + if attributes.scala2StandardLibrary then buf.writeNat(TastyFormat.SCALA2STANDARDLIBRARYattr) end pickleAttributes diff --git a/compiler/src/dotty/tools/dotc/core/tasty/AttributeUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/AttributeUnpickler.scala index 19ab18eae90c..38f7b46c7e1a 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/AttributeUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/AttributeUnpickler.scala @@ -10,7 +10,7 @@ import java.nio.charset.StandardCharsets class AttributeUnpickler(reader: TastyReader): import reader._ - lazy val scala2StandardLibrary = { + lazy val attributes = { var scala2StandardLibrary = false while (!isAtEnd) { readNat() match @@ -19,7 +19,9 @@ class AttributeUnpickler(reader: TastyReader): case attribute => assert(false, "Unexpected attribute value: " + attribute) } - scala2StandardLibrary + Attributes( + scala2StandardLibrary, + ) } end AttributeUnpickler diff --git a/compiler/src/dotty/tools/dotc/core/tasty/Attributes.scala b/compiler/src/dotty/tools/dotc/core/tasty/Attributes.scala new file mode 100644 index 000000000000..4f36ebdbc7fd --- /dev/null +++ b/compiler/src/dotty/tools/dotc/core/tasty/Attributes.scala @@ -0,0 +1,5 @@ +package dotty.tools.dotc.core.tasty + +class Attributes( + val scala2StandardLibrary: Boolean, +) diff --git a/compiler/src/dotty/tools/dotc/core/tasty/ScratchData.scala b/compiler/src/dotty/tools/dotc/core/tasty/ScratchData.scala index 74cc6aaae533..889cf31a40b0 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/ScratchData.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/ScratchData.scala @@ -10,7 +10,7 @@ class ScratchData: val pickledIndices = new mutable.BitSet val commentBuffer = new TastyBuffer(5000) - val attributeBuffer = new TastyBuffer(128) + val attributeBuffer = new TastyBuffer(32) def reset() = assert(delta ne delta1) diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TastyPrinter.scala b/compiler/src/dotty/tools/dotc/core/tasty/TastyPrinter.scala index eb627c900e71..86b9c6c7f340 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TastyPrinter.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TastyPrinter.scala @@ -230,9 +230,9 @@ class TastyPrinter(bytes: Array[Byte]) { def unpickle(reader: TastyReader, tastyName: NameTable): String = { sb.append(s" ${reader.endAddr.index - reader.currentAddr.index}") - val attributeUnpickler = new AttributeUnpickler(reader) + val attributes = new AttributeUnpickler(reader).attributes sb.append(s" attributes bytes:\n") - if attributeUnpickler.scala2StandardLibrary then + if attributes.scala2StandardLibrary then sb.append(" SCALA2STANDARDLIBRARYattr\n") sb.result } diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala index 185762f0e8c0..c25f33c624e5 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala @@ -100,7 +100,7 @@ class TreeUnpickler(reader: TastyReader, private var withCaptureChecks: Boolean = false private val unpicklingScala2Library = - attributeUnpicklerOpt.exists(_.scala2StandardLibrary) + attributeUnpicklerOpt.exists(_.attributes.scala2StandardLibrary) private def registerSym(addr: Addr, sym: Symbol) = symAtAddr(addr) = sym diff --git a/compiler/src/dotty/tools/dotc/transform/Pickler.scala b/compiler/src/dotty/tools/dotc/transform/Pickler.scala index 2584ec146e16..1f55da7b64b0 100644 --- a/compiler/src/dotty/tools/dotc/transform/Pickler.scala +++ b/compiler/src/dotty/tools/dotc/transform/Pickler.scala @@ -108,10 +108,10 @@ class Pickler extends Phase { pickler, treePkl.buf.addrOfTree, treePkl.docString, tree, scratch.commentBuffer) - AttributePickler.pickleAttributes( - ctx.settings.YcompileScala2Library.value, - pickler, - scratch.attributeBuffer) + val attributes = Attributes( + scala2StandardLibrary = ctx.settings.YcompileScala2Library.value, + ) + AttributePickler.pickleAttributes(attributes, pickler, scratch.attributeBuffer) val pickled = pickler.assembleParts()