Skip to content

Commit

Permalink
Add explicit nulls attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed Oct 27, 2023
1 parent 2712222 commit da6797f
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ object AttributePickler:
pickler: TastyPickler,
buf: TastyBuffer
): Unit =
if attributes.scala2StandardLibrary then // or any other attribute is set
if attributes.scala2StandardLibrary || attributes.explicitNulls then // or any other attribute is set
pickler.newSection(AttributesSection, buf)
// Pickle attributes
if attributes.scala2StandardLibrary then buf.writeNat(TastyFormat.SCALA2STANDARDLIBRARYattr)
if attributes.explicitNulls then buf.writeNat(TastyFormat.EXPLICITNULLSattr)

end pickleAttributes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ class AttributeUnpickler(reader: TastyReader):

lazy val attributes: Attributes = {
var scala2StandardLibrary = false
var explicitNulls = false
for attributeTag <- attributeTags do
attributeTag match
case TastyFormat.SCALA2STANDARDLIBRARYattr => scala2StandardLibrary = true
case TastyFormat.EXPLICITNULLSattr => explicitNulls = true
case attribute =>
assert(false, "Unexpected attribute value: " + attribute)
Attributes(
scala2StandardLibrary,
explicitNulls,
)
}

Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/tasty/Attributes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ package dotty.tools.dotc.core.tasty

class Attributes(
val scala2StandardLibrary: Boolean,
val explicitNulls: Boolean,
)
5 changes: 5 additions & 0 deletions compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ class TreeUnpickler(reader: TastyReader,
private val unpicklingScala2Library =
attributeUnpicklerOpt.exists(_.attributes.scala2StandardLibrary)

/** This dependency was compiled with explicit nulls enabled */
// TODO Use this to tag the symbols of this dependency as compiled with explicit nulls (see use of unpicklingScala2Library).
private val explicitNulls =
attributeUnpicklerOpt.exists(_.attributes.explicitNulls)

private def registerSym(addr: Addr, sym: Symbol) =
symAtAddr(addr) = sym

Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/transform/Pickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class Pickler extends Phase {

val attributes = Attributes(
scala2StandardLibrary = ctx.settings.YcompileScala2Library.value,
explicitNulls = ctx.settings.YexplicitNulls.value,
)
AttributePickler.pickleAttributes(attributes, pickler, scratch.attributeBuffer)

Expand Down
5 changes: 4 additions & 1 deletion tasty/src/dotty/tools/tasty/TastyFormat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ Standard Section: "Comments" Comment*
Standard Section: "Attributes" Attribute*
```none
Attribute = SCALA2STANDARDLIBRARYattr
EXPLICITNULLSattr
```
**************************************************************************************/
Expand Down Expand Up @@ -605,9 +606,10 @@ object TastyFormat {
final val firstLengthTreeTag = PACKAGE


// Attribute tags
// Attributes tags

final val SCALA2STANDARDLIBRARYattr = 1
final val EXPLICITNULLSattr = 2

/** Useful for debugging */
def isLegalTag(tag: Int): Boolean =
Expand Down Expand Up @@ -826,6 +828,7 @@ object TastyFormat {

def attributeTagToString(tag: Int): String = tag match {
case SCALA2STANDARDLIBRARYattr => "SCALA2STANDARDLIBRARYattr"
case EXPLICITNULLSattr => "EXPLICITNULLSattr"
}

/** @return If non-negative, the number of leading references (represented as nats) of a length/trees entry.
Expand Down

0 comments on commit da6797f

Please sign in to comment.