Skip to content

Commit 0ffa4d9

Browse files
committed
use Uninitialized instead of Null for relevant vars in dotty
1 parent 1ad95b0 commit 0ffa4d9

29 files changed

+83
-76
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/ConstraintRunInfo.scala

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

45
import Contexts._
56
import config.Printers.{default, typr}
67

78
trait ConstraintRunInfo { self: Run =>
89
private var maxSize = 0
9-
private var maxConstraint: Constraint | Null = _
10+
private var maxConstraint: Constraint | Uninitialized = _
1011
def recordConstraintSize(c: Constraint, size: Int): Unit =
1112
if (size > maxSize) {
1213
maxSize = size

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ object Contexts {
308308
def getFile(name: String): AbstractFile = getFile(name.toTermName)
309309

310310

311-
private var related: SimpleIdentityMap[Phase | SourceFile, Context] | Null = null
311+
private var related: SimpleIdentityMap[Phase | SourceFile, Context] | Uninitialized = initiallyNull
312312

313313
private def lookup(key: Phase | SourceFile): Context | Null =
314314
util.Stats.record("Context.related.lookup")
@@ -853,7 +853,7 @@ object Contexts {
853853
val initialCtx: Context = new InitialContext(this, settings)
854854

855855
/** The platform, initialized by `initPlatform()`. */
856-
private var _platform: Platform | Null = _
856+
private var _platform: Platform | Uninitialized = _
857857

858858
/** The platform */
859859
def platform: Platform = {
@@ -911,8 +911,8 @@ object Contexts {
911911
/** A table for hash consing unique named types */
912912
private[core] val uniqueNamedTypes: NamedTypeUniques = NamedTypeUniques()
913913

914-
var emptyTypeBounds: TypeBounds | Null = null
915-
var emptyWildcardBounds: WildcardType | Null = null
914+
var emptyTypeBounds: TypeBounds | Uninitialized = initiallyNull
915+
var emptyWildcardBounds: WildcardType | Uninitialized = initiallyNull
916916

917917
/** Number of findMember calls on stack */
918918
private[core] var findMemberCount: Int = 0
@@ -1006,7 +1006,7 @@ object Contexts {
10061006
// Test that access is single threaded
10071007

10081008
/** The thread on which `checkSingleThreaded was invoked last */
1009-
@sharable private var thread: Thread | Null = null
1009+
@sharable private var thread: Thread | Uninitialized = initiallyNull
10101010

10111011
/** Check that we are on the same thread as before */
10121012
def checkSingleThreaded(): Unit =

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: 3 additions & 3 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
*/
220-
private var elemsCache: List[Symbol] | Null = null
220+
private var elemsCache: List[Symbol] | Uninitialized = initiallyNull
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: 8 additions & 8 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
@@ -1701,15 +1701,15 @@ object SymDenotations {
17011701

17021702
// ----- caches -------------------------------------------------------
17031703

1704-
private var myTypeParams: List[TypeSymbol] | Null = null
1704+
private var myTypeParams: List[TypeSymbol] | Uninitialized = initiallyNull
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) */
17111711
type BaseTypeMap = EqHashMap[CachedType, Type]
1712-
private var myBaseTypeCache: BaseTypeMap | Null = null
1712+
private var myBaseTypeCache: BaseTypeMap | Uninitialized = initiallyNull
17131713
private var myBaseTypeCachePeriod: Period = Nowhere
17141714

17151715
private var baseDataCache: BaseData = BaseData.None
@@ -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: 12 additions & 12 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,9 +2093,9 @@ object Types {
20932093

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

2096-
private var myName: Name | Null = null
2097-
private var lastDenotation: Denotation | Null = null
2098-
private var lastSymbol: Symbol | Null = null
2096+
private var myName: Name | Uninitialized = initiallyNull
2097+
private var lastDenotation: Denotation | Uninitialized = initiallyNull
2098+
private var lastSymbol: Symbol | Uninitialized = initiallyNull
20992099
private var checkedPeriod: Period = Nowhere
21002100
private var myStableHash: Byte = 0
21012101
private var mySignature: Signature = _
@@ -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/reporting/StoreReporter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import Diagnostic._
1919
*/
2020
class StoreReporter(outer: Reporter | Null = Reporter.NoReporter, fromTyperState: Boolean = false) extends Reporter {
2121

22-
protected var infos: mutable.ListBuffer[Diagnostic] | Null = null
22+
protected var infos: mutable.ListBuffer[Diagnostic] | Uninitialized = initiallyNull
2323

2424
def doReport(dia: Diagnostic)(using Context): Unit = {
2525
typr.println(s">>>> StoredError: ${dia.message}") // !!! DEBUG

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

0 commit comments

Comments
 (0)