Skip to content

Commit 5265bd9

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

25 files changed

+66
-60
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: 6 additions & 6 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) */
@@ -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

0 commit comments

Comments
 (0)