Skip to content

Commit

Permalink
Add Attributes data class
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed Oct 26, 2023
1 parent e8a39f0 commit 4ebaa73
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,7 +19,9 @@ class AttributeUnpickler(reader: TastyReader):
case attribute =>
assert(false, "Unexpected attribute value: " + attribute)
}
scala2StandardLibrary
Attributes(
scala2StandardLibrary,
)
}

end AttributeUnpickler
5 changes: 5 additions & 0 deletions compiler/src/dotty/tools/dotc/core/tasty/Attributes.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package dotty.tools.dotc.core.tasty

class Attributes(
val scala2StandardLibrary: Boolean,
)
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/tasty/ScratchData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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 @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/transform/Pickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 4ebaa73

Please sign in to comment.