Skip to content

Commit 79b23ab

Browse files
committed
use Uninitialized instead of Null for relevant vars in dotty
1 parent c2775b0 commit 79b23ab

25 files changed

+67
-61
lines changed

compiler/src/dotty/tools/dotc/CompilationUnit.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class CompilationUnit protected (val source: SourceFile) {
7171
suspendedAtInliningPhase = true
7272
throw CompilationUnit.SuspendException()
7373

74-
private var myAssignmentSpans: Map[Int, List[Span]] | Null = null
74+
private var myAssignmentSpans: Map[Int, List[Span]] | Uninitialized = initiallyNull
7575

7676
/** A map from (name-) offsets of all local variables in this compilation unit
7777
* that can be tracked for being not null to the list of spans of assignments

compiler/src/dotty/tools/dotc/ast/Positioned.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ abstract class Positioned(implicit @constructorOnly src: SourceFile) extends Src
160160
*/
161161
def checkPos(nonOverlapping: Boolean)(using Context): Unit = try {
162162
import untpd._
163-
var lastPositioned: Positioned | Null = null
163+
var lastPositioned: Positioned | Uninitialized = initiallyNull
164164
var lastSpan = NoSpan
165165
def check(p: Any): Unit = p match {
166166
case p: Positioned =>
@@ -234,7 +234,7 @@ abstract class Positioned(implicit @constructorOnly src: SourceFile) extends Src
234234

235235
object Positioned {
236236
@sharable private var debugId = Int.MinValue
237-
@sharable private var ids: java.util.WeakHashMap[Positioned, Int] | Null = null
237+
@sharable private var ids: java.util.WeakHashMap[Positioned, Int] | Uninitialized = initiallyNull
238238
@sharable private var nextId: Int = 0
239239

240240
def init(using Context): Unit =

compiler/src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ object Trees {
294294
trait DefTree[-T >: Untyped] extends DenotingTree[T] {
295295
type ThisTree[-T >: Untyped] <: DefTree[T]
296296

297-
private var myMods: untpd.Modifiers | Null = _
297+
private var myMods: untpd.Modifiers | Uninitialized = _
298298

299299
private[dotc] def rawMods: untpd.Modifiers =
300300
if (myMods == null) untpd.EmptyModifiers else myMods.uncheckedNN

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
12561256
trait TreeProvider {
12571257
protected def computeRootTrees(using Context): List[Tree]
12581258

1259-
private var myTrees: List[Tree] | Null = _
1259+
private var myTrees: List[Tree] | Uninitialized = _
12601260

12611261
/** Get trees defined by this provider. Cache them if -Yretain-trees is set. */
12621262
def rootTrees(using Context): List[Tree] =

compiler/src/dotty/tools/dotc/core/Names.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ object Names {
163163
override def asTermName: TermName = this
164164

165165
@sharable // because it is only modified in the synchronized block of toTypeName.
166-
private var myTypeName: TypeName | Null = null
166+
private var myTypeName: TypeName | Uninitialized = initiallyNull
167167
// Note: no @volatile needed since type names are immutable and therefore safely published
168168

169169
override def toTypeName: TypeName =
@@ -225,10 +225,10 @@ object Names {
225225
}
226226

227227
@sharable // because it's just a cache for performance
228-
private var myMangledString: String | Null = null
228+
private var myMangledString: String | Uninitialized = initiallyNull
229229

230230
@sharable // because it's just a cache for performance
231-
private var myMangled: Name | Null = null
231+
private var myMangled: Name | Uninitialized = initiallyNull
232232

233233
protected[Names] def mangle: ThisName
234234

@@ -259,7 +259,7 @@ object Names {
259259

260260
protected def computeToString: String
261261

262-
@sharable private var myToString: String | Null = null
262+
@sharable private var myToString: String | Uninitialized = initiallyNull
263263

264264
override def toString: String =
265265
if myToString == null then myToString = computeToString

compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
565565
i += 1
566566
}
567567

568-
private var myUninstVars: mutable.ArrayBuffer[TypeVar] | Null = _
568+
private var myUninstVars: mutable.ArrayBuffer[TypeVar] | Uninitialized = _
569569

570570
/** The uninstantiated typevars of this constraint */
571571
def uninstVars: collection.Seq[TypeVar] = {

compiler/src/dotty/tools/dotc/core/Scopes.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,14 @@ object Scopes {
213213

214214
/** the hash table
215215
*/
216-
private var hashTable: Array[ScopeEntry | Null] | Null = null
216+
private var hashTable: Array[ScopeEntry | Null] | Uninitialized = initiallyNull
217217

218218
/** a cache for all elements, to be used by symbol iterator.
219219
*/
220220
private var elemsCache: List[Symbol] | Null = null
221221

222222
/** The synthesizer to be used, or `null` if no synthesis is done on this scope */
223-
private var synthesize: SymbolSynthesizer | Null = null
223+
private var synthesize: SymbolSynthesizer | Uninitialized = initiallyNull
224224

225225
/** Use specified synthesize for this scope */
226226
def useSynthesizer(s: SymbolSynthesizer): Unit = synthesize = s

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ object SymDenotations {
495495
/** `fullName` where `.' is the separator character */
496496
def fullName(using Context): Name = fullNameSeparated(QualifiedName)
497497

498-
private var myTargetName: Name | Null = null
498+
private var myTargetName: Name | Uninitialized = initiallyNull
499499

500500
private def computeTargetName(targetNameAnnot: Option[Annotation])(using Context): Name =
501501
targetNameAnnot match
@@ -1704,7 +1704,7 @@ object SymDenotations {
17041704
private var myTypeParams: List[TypeSymbol] | Null = null
17051705
private var fullNameCache: SimpleIdentityMap[QualifiedNameKind, Name] = SimpleIdentityMap.empty
17061706

1707-
private var myMemberCache: EqHashMap[Name, PreDenotation] | Null = null
1707+
private var myMemberCache: EqHashMap[Name, PreDenotation] | Uninitialized = initiallyNull
17081708
private var myMemberCachePeriod: Period = Nowhere
17091709

17101710
/** A cache from types T to baseType(T, C) */
@@ -1755,7 +1755,7 @@ object SymDenotations {
17551755
invalidateMemberNamesCache()
17561756
if sym.isWrappedToplevelDef then
17571757
val outerCache = sym.owner.owner.asClass.classDenot.myMemberCache
1758-
if outerCache != null then outerCache.remove(sym.name)
1758+
if outerCache != null then outerCache.uncheckedNN.remove(sym.name)
17591759

17601760
override def copyCaches(from: SymDenotation, phase: Phase)(using Context): this.type = {
17611761
from match {
@@ -1838,7 +1838,7 @@ object SymDenotations {
18381838

18391839
// ------ class-specific operations -----------------------------------
18401840

1841-
private var myThisType: Type | Null = null
1841+
private var myThisType: Type | Uninitialized = initiallyNull
18421842

18431843
/** The this-type depends on the kind of class:
18441844
* - for a package class `p`: ThisType(TypeRef(Noprefix, p))
@@ -1856,7 +1856,7 @@ object SymDenotations {
18561856
ThisType.raw(TypeRef(pre, cls))
18571857
}
18581858

1859-
private var myTypeRef: TypeRef | Null = null
1859+
private var myTypeRef: TypeRef | Uninitialized = initiallyNull
18601860

18611861
override def typeRef(using Context): TypeRef = {
18621862
if (myTypeRef == null) myTypeRef = super.typeRef
@@ -2628,8 +2628,8 @@ object SymDenotations {
26282628
def apply(module: TermSymbol, modcls: ClassSymbol): LazyType = this
26292629

26302630
private var myDecls: Scope = EmptyScope
2631-
private var mySourceModule: Symbol | Null = null
2632-
private var myModuleClass: Symbol | Null = null
2631+
private var mySourceModule: Symbol | Uninitialized = initiallyNull
2632+
private var myModuleClass: Symbol | Uninitialized = initiallyNull
26332633
private var mySourceModuleFn: Context ?=> Symbol = LazyType.NoSymbolFn
26342634
private var myModuleClassFn: Context ?=> Symbol = LazyType.NoSymbolFn
26352635

compiler/src/dotty/tools/dotc/core/Symbols.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ object Symbols {
6565
myCoord = c
6666
}
6767

68-
private var myDefTree: Tree | Null = null
68+
private var myDefTree: Tree | Uninitialized = initiallyNull
6969

7070
/** The tree defining the symbol at pickler time, EmptyTree if none was retained */
7171
def defTree: Tree =

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
4949
needsGc = false
5050
if Config.checkTypeComparerReset then checkReset()
5151

52-
private var pendingSubTypes: util.MutableSet[(Type, Type)] | Null = null
52+
private var pendingSubTypes: util.MutableSet[(Type, Type)] | Uninitialized = initiallyNull
5353
private var recCount = 0
5454
private var monitored = false
5555

compiler/src/dotty/tools/dotc/core/TypeOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ object TypeOps:
796796
//
797797
// See tests/patmat/i3938.scala
798798
class InferPrefixMap extends TypeMap {
799-
var prefixTVar: Type | Null = null
799+
var prefixTVar: Type | Uninitialized = initiallyNull
800800
def apply(tp: Type): Type = tp match {
801801
case ThisType(tref: TypeRef) if !tref.symbol.isStaticOwner =>
802802
if (tref.symbol.is(Module))

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2073,7 +2073,7 @@ object Types {
20732073

20742074
/** Implementations of this trait cache the results of `narrow`. */
20752075
trait NarrowCached extends Type {
2076-
private var myNarrow: TermRef | Null = null
2076+
private var myNarrow: TermRef | Uninitialized = initiallyNull
20772077
override def narrow(using Context): TermRef = {
20782078
if (myNarrow == null) myNarrow = super.narrow
20792079
myNarrow.nn
@@ -2093,7 +2093,7 @@ object Types {
20932093

20942094
assert(prefix.isValueType || (prefix eq NoPrefix), s"invalid prefix $prefix")
20952095

2096-
private var myName: Name | Null = null
2096+
private var myName: Name | Uninitialized = initiallyNull
20972097
private var lastDenotation: Denotation | Null = null
20982098
private var lastSymbol: Symbol | Null = null
20992099
private var checkedPeriod: Period = Nowhere
@@ -2881,7 +2881,7 @@ object Types {
28812881

28822882
// `refFn` can be null only if `computed` is true.
28832883
case class LazyRef(private var refFn: (Context => (Type | Null)) | Null) extends UncachedProxyType with ValueType {
2884-
private var myRef: Type | Null = null
2884+
private var myRef: Type | Uninitialized = initiallyNull
28852885
private var computed = false
28862886

28872887
override def tryNormalize(using Context): Type = ref.tryNormalize
@@ -3024,7 +3024,7 @@ object Types {
30243024

30253025
val parent: Type = parentExp(this: @unchecked)
30263026

3027-
private var myRecThis: RecThis | Null = null
3027+
private var myRecThis: RecThis | Uninitialized = initiallyNull
30283028

30293029
def recThis: RecThis = {
30303030
if (myRecThis == null) myRecThis = new RecThisImpl(this)
@@ -3441,7 +3441,7 @@ object Types {
34413441
final def isTypeLambda: Boolean = isInstanceOf[TypeLambda]
34423442
final def isHigherKinded: Boolean = isInstanceOf[TypeProxy]
34433443

3444-
private var myParamRefs: List[ParamRefType] | Null = null
3444+
private var myParamRefs: List[ParamRefType] | Uninitialized = initiallyNull
34453445

34463446
def paramRefs: List[ParamRefType] = {
34473447
if myParamRefs == null then
@@ -4636,7 +4636,7 @@ object Types {
46364636
//val id = skid
46374637
//assert(id != 10)
46384638

4639-
private var myRepr: Name | Null = null
4639+
private var myRepr: Name | Uninitialized = initiallyNull
46404640
def repr(using Context): Name = {
46414641
if (myRepr == null) myRepr = SkolemName.fresh()
46424642
myRepr.nn
@@ -4820,7 +4820,7 @@ object Types {
48204820
def alternatives(using Context): List[Type] = cases.map(caseType)
48214821
def underlying(using Context): Type = bound
48224822

4823-
private var myReduced: Type | Null = null
4823+
private var myReduced: Type | Uninitialized = initiallyNull
48244824
private var reductionContext: util.MutableMap[Type, Type] = _
48254825

48264826
override def tryNormalize(using Context): Type =
@@ -4920,8 +4920,8 @@ object Types {
49204920
decls: Scope,
49214921
selfInfo: TypeOrSymbol) extends CachedGroundType with TypeType {
49224922

4923-
private var selfTypeCache: Type | Null = null
4924-
private var appliedRefCache: Type | Null = null
4923+
private var selfTypeCache: Type | Uninitialized = initiallyNull
4924+
private var appliedRefCache: Type | Uninitialized = initiallyNull
49254925

49264926
/** The self type of a class is the conjunction of
49274927
* - the explicit self type if given (or the info of a given self symbol), and
@@ -4948,7 +4948,7 @@ object Types {
49484948
}
49494949

49504950
// cached because baseType needs parents
4951-
private var parentsCache: List[Type] | Null = null
4951+
private var parentsCache: List[Type] | Uninitialized = initiallyNull
49524952

49534953
override def parents(using Context): List[Type] = {
49544954
if (parentsCache == null)

compiler/src/dotty/tools/dotc/parsing/Scanners.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1555,7 +1555,7 @@ object Scanners {
15551555
/** The enclosing region, which is required to exist */
15561556
def enclosing: Region = outer.asInstanceOf[Region]
15571557

1558-
var knownWidth: IndentWidth | Null = null
1558+
var knownWidth: IndentWidth | Uninitialized = initiallyNull
15591559

15601560
/** The indentation width, Zero if not known */
15611561
final def indentWidth: IndentWidth =

compiler/src/dotty/tools/dotc/reporting/Message.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ abstract class Message(val errorId: ErrorMessageID) { self =>
6969
*/
7070
def canExplain: Boolean = explain.nonEmpty
7171

72-
private var myMsg: String | Null = null
72+
private var myMsg: String | Uninitialized = initiallyNull
7373
private var myIsNonSensical: Boolean = false
7474

7575
private def dropNonSensical(msg: String): String =

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
package dotty.tools.dotc
1+
package dotty.tools
2+
package dotc
23
package transform
34

45
import MegaPhase._
@@ -52,7 +53,7 @@ class CapturedVars extends MiniPhase with IdentityDenotTransformer:
5253
Set(refClass(defn.ObjectClass), volatileRefClass(defn.ObjectClass))
5354
}
5455

55-
private var myRefInfo: RefInfo | Null = null
56+
private var myRefInfo: RefInfo | Uninitialized = initiallyNull
5657
private def refInfo(using Context): RefInfo = {
5758
if (myRefInfo == null) myRefInfo = new RefInfo()
5859
myRefInfo.uncheckedNN

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
package dotty.tools.dotc
1+
package dotty.tools
2+
package dotc
23
package transform
34

45
import java.util.IdentityHashMap
@@ -44,7 +45,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
4445
val containerFlagsMask: FlagSet = Method | Lazy | Accessor | Module
4546

4647
/** A map of lazy values to the fields they should null after initialization. */
47-
private var lazyValNullables: IdentityHashMap[Symbol, mutable.ListBuffer[Symbol]] | Null = _
48+
private var lazyValNullables: IdentityHashMap[Symbol, mutable.ListBuffer[Symbol]] | Uninitialized = _
4849
private def nullableFor(sym: Symbol)(using Context) = {
4950
// optimisation: value only used once, we can remove the value from the map
5051
val nullables = lazyValNullables.nn.remove(sym)
@@ -382,7 +383,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
382383
val thizClass = Literal(Constant(claz.info))
383384
val helperModule = requiredModule("scala.runtime.LazyVals")
384385
val getOffset = Select(ref(helperModule), lazyNme.RLazyVals.getOffset)
385-
var offsetSymbol: TermSymbol | Null = null
386+
var offsetSymbol: TermSymbol | Uninitialized = initiallyNull
386387
var flag: Tree = EmptyTree
387388
var ord = 0
388389

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
package dotty.tools.dotc
1+
package dotty.tools
2+
package dotc
23
package transform
34

45
import ast.Trees._, ast.tpd, core._
@@ -35,7 +36,7 @@ class SpecializeFunctions extends MiniPhase {
3536
val sym = ddef.symbol
3637
val cls = ctx.owner.asClass
3738

38-
var specName: Name | Null = null
39+
var specName: Name | Uninitialized = initiallyNull
3940

4041
def isSpecializable = {
4142
val paramTypes = ddef.termParamss.head.map(_.symbol.info)

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
package dotty.tools.dotc
1+
package dotty.tools
2+
package dotc
23
package transform
34

45
import core._
@@ -190,8 +191,8 @@ class Splicing extends MacroTransform:
190191
private class SpliceTransformer(spliceOwner: Symbol, isCaptured: Symbol => Boolean) extends Transformer:
191192
private var refBindingMap = mutable.Map.empty[Symbol, (Tree, Symbol)]
192193
/** Reference to the `Quotes` instance of the current level 1 splice */
193-
private var quotes: Tree | Null = null // TODO: add to the context
194-
private var healedTypes: PCPCheckAndHeal.QuoteTypeTags | Null = null // TODO: add to the context
194+
private var quotes: Tree | Uninitialized = initiallyNull // TODO: add to the context
195+
private var healedTypes: PCPCheckAndHeal.QuoteTypeTags | Uninitialized = initiallyNull // TODO: add to the context
195196

196197
def transformSplice(tree: tpd.Tree, tpe: Type, holeIdx: Int)(using Context): tpd.Tree =
197198
assert(level == 0)

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
package dotty.tools.dotc
1+
package dotty.tools
2+
package dotc
23
package transform
34

45
import ast.{TreeTypeMap, tpd}
@@ -232,7 +233,7 @@ class TailRec extends MiniPhase {
232233
var failureReported: Boolean = false
233234

234235
/** The `tailLabelN` label symbol, used to encode a `continue` from the infinite `while` loop. */
235-
private var myContinueLabel: Symbol | Null = _
236+
private var myContinueLabel: Symbol | Uninitialized = _
236237
def continueLabel(using Context): Symbol = {
237238
if (myContinueLabel == null)
238239
myContinueLabel = newSymbol(method, TailLabelName.fresh(), Label, defn.UnitType)

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
package dotty.tools.dotc
1+
package dotty.tools
2+
package dotc
23
package transform
34

45
import core.Names.Name
@@ -213,7 +214,7 @@ class TreeChecker extends Phase with SymTransformer {
213214
}
214215

215216
// used to check invariant of lambda encoding
216-
var nestingBlock: untpd.Block | Null = null
217+
var nestingBlock: untpd.Block | Uninitialized = initiallyNull
217218
private def withBlock[T](block: untpd.Block)(op: => T): T = {
218219
val outerBlock = nestingBlock
219220
nestingBlock = block

0 commit comments

Comments
 (0)