Skip to content

Commit 8f9afe1

Browse files
committed
Remove isInitialized
1 parent 33afca2 commit 8f9afe1

File tree

5 files changed

+21
-30
lines changed

5 files changed

+21
-30
lines changed

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,14 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
8888

8989
private var compiling = false
9090

91-
private var myCtx = rootContext(using ictx)
91+
private var myCtx: Context | Null = rootContext(using ictx)
9292

9393
/** The context created for this run */
94-
given runContext[Dummy_so_its_a_def]: Context = myCtx
94+
given runContext[Dummy_so_its_a_def]: Context = myCtx.nn
9595
assert(runContext.runId <= Periods.MaxPossibleRunId)
9696

97-
private var myUnits: List[CompilationUnit] = _
98-
private var myUnitsCached: List[CompilationUnit] = _
97+
private var myUnits: List[CompilationUnit] = Nil
98+
private var myUnitsCached: List[CompilationUnit] = Nil
9999
private var myFiles: Set[AbstractFile] = _
100100

101101
// `@nowarn` annotations by source file, populated during typer
@@ -206,7 +206,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
206206
compileSources(sources)
207207
catch
208208
case NonFatal(ex) =>
209-
if !units.isInitialized then report.echo(i"exception occurred while compiling $units%, %")
209+
if units != Nil then report.echo(i"exception occurred while compiling $units%, %")
210210
else report.echo(s"exception occurred while compiling ${files.map(_.name).mkString(", ")}")
211211
throw ex
212212

@@ -367,8 +367,8 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
367367
override def reset(): Unit = {
368368
super[ImplicitRunInfo].reset()
369369
super[ConstraintRunInfo].reset()
370-
myCtx = null.asInstanceOf
371-
myUnits = null.asInstanceOf
372-
myUnitsCached = null.asInstanceOf
370+
myCtx = null
371+
myUnits = Nil
372+
myUnitsCached = Nil
373373
}
374374
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -296,15 +296,15 @@ object Trees {
296296
trait DefTree[-T >: Untyped] extends DenotingTree[T] {
297297
type ThisTree[-T >: Untyped] <: DefTree[T]
298298

299-
private var myMods: untpd.Modifiers = _
299+
private var myMods: untpd.Modifiers | Null = _
300300

301301
private[dotc] def rawMods: untpd.Modifiers =
302-
if (!myMods.isInitialized) untpd.EmptyModifiers else myMods
302+
if (myMods == null) untpd.EmptyModifiers else myMods.uncheckedNN
303303

304304
def withAnnotations(annots: List[untpd.Tree]): ThisTree[Untyped] = withMods(rawMods.withAnnotations(annots))
305305

306306
def withMods(mods: untpd.Modifiers): ThisTree[Untyped] = {
307-
val tree = if (!myMods.isInitialized || (myMods == mods)) this else cloneIn(source)
307+
val tree = if (myMods == null || (myMods == mods)) this else cloneIn(source)
308308
tree.setMods(mods)
309309
tree.asInstanceOf[ThisTree[Untyped]]
310310
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -1195,13 +1195,13 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
11951195
trait TreeProvider {
11961196
protected def computeRootTrees(using Context): List[Tree]
11971197

1198-
private var myTrees: List[Tree] = _
1198+
private var myTrees: List[Tree] | Null = _
11991199

12001200
/** Get trees defined by this provider. Cache them if -Yretain-trees is set. */
12011201
def rootTrees(using Context): List[Tree] =
12021202
if (ctx.settings.YretainTrees.value) {
1203-
if (!myTrees.isInitialized) myTrees = computeRootTrees
1204-
myTrees
1203+
if (myTrees == null) myTrees = computeRootTrees
1204+
myTrees.uncheckedNN
12051205
}
12061206
else computeRootTrees
12071207

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,9 @@ object Contexts {
272272
* the declarations of the current class.
273273
*/
274274
def effectiveScope(using Context): Scope =
275-
if owner.isInitialized && owner.isClass then owner.asClass.unforcedDecls
275+
// TODO
276+
val co: Symbol | Null = owner
277+
if co != null && co.isClass then co.asClass.unforcedDecls
276278
else scope
277279

278280
def nestingLevel: Int =
@@ -858,14 +860,14 @@ object Contexts {
858860
val initialCtx: Context = new InitialContext(this, settings)
859861

860862
/** The platform, initialized by `initPlatform()`. */
861-
private var _platform: Platform = _
863+
private var _platform: Platform | Null = _
862864

863865
/** The platform */
864866
def platform: Platform = {
865-
if !_platform.isInitialized then
867+
if _platform == null then
866868
throw new IllegalStateException(
867869
"initialize() must be called before accessing platform")
868-
_platform
870+
_platform.uncheckedNN
869871
}
870872

871873
protected def newPlatform(using Context): Platform =

compiler/src/dotty/tools/package.scala

+1-12
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ package object tools {
2828

2929
/** Forward-ported from the explicit-nulls branch. */
3030
extension [T](x: T | Null)
31-
32-
/** Assert `x` is non null and strip `Null` from type */
33-
// inline def nn: T =
34-
// assert(x != null)
35-
// x.asInstanceOf[T]
36-
3731
/** Should be used when we know from the context that `x` is not null.
3832
* Flow-typing under explicit nulls will automatically insert many necessary
3933
* occurrences of uncheckedNN.
@@ -44,8 +38,8 @@ package object tools {
4438
if x == null then None else Some(x.asInstanceOf[T])
4539
end extension
4640

41+
/** Nullable eq and ne. */
4742
extension [T <: AnyRef](x: T | Null)
48-
// nullable eq
4943
inline def eqn (y: T | Null) =
5044
if x != null then
5145
if y != null then
@@ -55,11 +49,6 @@ package object tools {
5549

5650
inline def nen(y: T | Null): Boolean = !eqn(y)
5751

58-
extension [T <: AnyRef](x: T)
59-
// var x: T = _
60-
// var x: T = uninitialized
61-
def isInitialized: Boolean = (x: T | Null) != null
62-
6352
object resultWrapper {
6453
opaque type WrappedResult[T] = T
6554
private[tools] def unwrap[T](x: WrappedResult[T]): T = x

0 commit comments

Comments
 (0)