Skip to content

Use BitSet for boolean TASTy attributes #19092

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package dotty.tools.dotc
package core.tasty

import scala.language.unsafeNulls
import scala.collection.immutable.BitSet

import dotty.tools.tasty.{TastyFormat, TastyReader, TastyBuffer}

class AttributeUnpickler(reader: TastyReader):
import reader._

lazy val attributes: Attributes = {
val booleanTags = List.newBuilder[Int]
val booleanTags = BitSet.newBuilder

while !isAtEnd do
booleanTags += readByte()
Expand Down
23 changes: 13 additions & 10 deletions compiler/src/dotty/tools/dotc/core/tasty/Attributes.scala
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
package dotty.tools.dotc.core.tasty

import dotty.tools.tasty.TastyFormat
import dotty.tools.tasty.TastyFormat.*

class Attributes(
val booleanTags: List[Int],
import scala.collection.immutable.BitSet

class Attributes private[tasty](
private[tasty] val booleanTags: BitSet,
) {
def scala2StandardLibrary: Boolean =
booleanTags.contains(TastyFormat.SCALA2STANDARDLIBRARYattr)
def explicitNulls: Boolean =
booleanTags.contains(TastyFormat.EXPLICITNULLSattr)
def scala2StandardLibrary: Boolean = booleanTags(SCALA2STANDARDLIBRARYattr)
def explicitNulls: Boolean = booleanTags(EXPLICITNULLSattr)
}

object Attributes:
def apply(
scala2StandardLibrary: Boolean,
explicitNulls: Boolean,
): Attributes =
val booleanTags = List.newBuilder[Int]
if scala2StandardLibrary then booleanTags += TastyFormat.SCALA2STANDARDLIBRARYattr
if explicitNulls then booleanTags += TastyFormat.EXPLICITNULLSattr
val booleanTags = BitSet.newBuilder
if scala2StandardLibrary then booleanTags += SCALA2STANDARDLIBRARYattr
if explicitNulls then booleanTags += EXPLICITNULLSattr
new Attributes(booleanTags.result())
end apply

val empty: Attributes =
new Attributes(BitSet.empty)
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class DottyUnpickler(bytes: Array[Byte], mode: UnpickleMode = UnpickleMode.TopLe
private val treeUnpickler = unpickler.unpickle(treeSectionUnpickler(posUnpicklerOpt, commentUnpicklerOpt, attributeUnpicklerOpt)).get

def tastyAttributes: Attributes =
attributeUnpicklerOpt.map(_.attributes).getOrElse(new Attributes(booleanTags = Nil))
attributeUnpicklerOpt.map(_.attributes).getOrElse(Attributes.empty)

/** Enter all toplevel classes and objects into their scopes
* @param roots a set of SymDenotations that should be overwritten by unpickling
Expand Down