Skip to content

Commit da6797f

Browse files
committed
Add explicit nulls attribute
1 parent 2712222 commit da6797f

File tree

6 files changed

+16
-2
lines changed

6 files changed

+16
-2
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
@@ -14,10 +14,11 @@ object AttributePickler:
1414
pickler: TastyPickler,
1515
buf: TastyBuffer
1616
): Unit =
17-
if attributes.scala2StandardLibrary then // or any other attribute is set
17+
if attributes.scala2StandardLibrary || attributes.explicitNulls then // or any other attribute is set
1818
pickler.newSection(AttributesSection, buf)
1919
// Pickle attributes
2020
if attributes.scala2StandardLibrary then buf.writeNat(TastyFormat.SCALA2STANDARDLIBRARYattr)
21+
if attributes.explicitNulls then buf.writeNat(TastyFormat.EXPLICITNULLSattr)
2122

2223
end pickleAttributes
2324

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@ class AttributeUnpickler(reader: TastyReader):
1717

1818
lazy val attributes: Attributes = {
1919
var scala2StandardLibrary = false
20+
var explicitNulls = false
2021
for attributeTag <- attributeTags do
2122
attributeTag match
2223
case TastyFormat.SCALA2STANDARDLIBRARYattr => scala2StandardLibrary = true
24+
case TastyFormat.EXPLICITNULLSattr => explicitNulls = true
2325
case attribute =>
2426
assert(false, "Unexpected attribute value: " + attribute)
2527
Attributes(
2628
scala2StandardLibrary,
29+
explicitNulls,
2730
)
2831
}
2932

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ package dotty.tools.dotc.core.tasty
22

33
class Attributes(
44
val scala2StandardLibrary: Boolean,
5+
val explicitNulls: Boolean,
56
)

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ class TreeUnpickler(reader: TastyReader,
102102
private val unpicklingScala2Library =
103103
attributeUnpicklerOpt.exists(_.attributes.scala2StandardLibrary)
104104

105+
/** This dependency was compiled with explicit nulls enabled */
106+
// TODO Use this to tag the symbols of this dependency as compiled with explicit nulls (see use of unpicklingScala2Library).
107+
private val explicitNulls =
108+
attributeUnpicklerOpt.exists(_.attributes.explicitNulls)
109+
105110
private def registerSym(addr: Addr, sym: Symbol) =
106111
symAtAddr(addr) = sym
107112

compiler/src/dotty/tools/dotc/transform/Pickler.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ class Pickler extends Phase {
110110

111111
val attributes = Attributes(
112112
scala2StandardLibrary = ctx.settings.YcompileScala2Library.value,
113+
explicitNulls = ctx.settings.YexplicitNulls.value,
113114
)
114115
AttributePickler.pickleAttributes(attributes, pickler, scratch.attributeBuffer)
115116

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ Standard Section: "Comments" Comment*
271271
Standard Section: "Attributes" Attribute*
272272
```none
273273
Attribute = SCALA2STANDARDLIBRARYattr
274+
EXPLICITNULLSattr
274275
```
275276
276277
**************************************************************************************/
@@ -605,9 +606,10 @@ object TastyFormat {
605606
final val firstLengthTreeTag = PACKAGE
606607

607608

608-
// Attribute tags
609+
// Attributes tags
609610

610611
final val SCALA2STANDARDLIBRARYattr = 1
612+
final val EXPLICITNULLSattr = 2
611613

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

827829
def attributeTagToString(tag: Int): String = tag match {
828830
case SCALA2STANDARDLIBRARYattr => "SCALA2STANDARDLIBRARYattr"
831+
case EXPLICITNULLSattr => "EXPLICITNULLSattr"
829832
}
830833

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

0 commit comments

Comments
 (0)