@@ -2,6 +2,8 @@ package dotty.tools
22package dotc
33package core
44
5+ import scala.language.{unsafeNulls => _}
6+
57import Types._
68import Contexts._
79import util.{SimpleIdentityMap, SimpleIdentitySet}
@@ -45,7 +47,7 @@ class TyperState() {
4547 private var myId: Int = _
4648 def id: Int = myId
4749
48- private var previous: TyperState /* | Null */ = _
50+ private var previous: TyperState | Null = _
4951
5052 private var myReporter: Reporter = _
5153
@@ -75,7 +77,7 @@ class TyperState() {
7577 this
7678
7779 def isGlobalCommittable: Boolean =
78- isCommittable && (previous == null || previous.isGlobalCommittable)
80+ isCommittable && (previous == null || previous.uncheckedNN. isGlobalCommittable)
7981
8082 private var isCommitted: Boolean = _
8183
@@ -92,7 +94,7 @@ class TyperState() {
9294 /** Initializes all fields except reporter, isCommittable, which need to be
9395 * set separately.
9496 */
95- private[core] def init(previous: TyperState /* | Null */ , constraint: Constraint): this.type =
97+ private[core] def init(previous: TyperState | Null, constraint: Constraint): this.type =
9698 this.myId = TyperState.nextId
9799 TyperState.nextId += 1
98100 this.previous = previous
@@ -117,7 +119,8 @@ class TyperState() {
117119 * which is not yet committed, or which does not have a parent.
118120 */
119121 def uncommittedAncestor: TyperState =
120- if (isCommitted) previous.uncommittedAncestor else this
122+ // TODO
123+ if (isCommitted) previous.nn.uncommittedAncestor else this
121124
122125 /** Commit typer state so that its information is copied into current typer state
123126 * In addition (1) the owning state of undetermined or temporarily instantiated
@@ -179,7 +182,7 @@ class TyperState() {
179182 var ts = this
180183 while ts.constraint.domainLambdas.contains(tl) do
181184 ts.constraint = ts.constraint.subst(tl, tl1)
182- ts = ts.previous
185+ ts = ts.previous.nn
183186
184187 /** Integrate the constraints from `that` into this TyperState.
185188 *
@@ -235,14 +238,14 @@ class TyperState() {
235238 * each tvar can only be instantiated by one TyperState.
236239 */
237240 private def includeVar(tvar: TypeVar)(using Context): Unit =
238- val oldState = tvar.owningState.get
241+ val oldState = tvar.owningState.nn. get
239242 assert(oldState == null || !oldState.isCommittable,
240243 i"$this attempted to take ownership of $tvar which is already owned by committable $oldState")
241244 tvar.owningState = new WeakReference(this)
242245 ownedVars += tvar
243246
244247 private def isOwnedAnywhere(ts: TyperState, tvar: TypeVar): Boolean =
245- ts.ownedVars.contains(tvar) || ts.previous != null && isOwnedAnywhere(ts.previous, tvar)
248+ ts.ownedVars.contains(tvar) || ts.previous != null && isOwnedAnywhere(ts.previous.uncheckedNN , tvar)
246249
247250 /** Make type variable instances permanent by assigning to `inst` field if
248251 * type variable instantiation cannot be retracted anymore. Then, remove
@@ -253,7 +256,8 @@ class TyperState() {
253256 Stats.record("typerState.gc")
254257 val toCollect = new mutable.ListBuffer[TypeLambda]
255258 for tvar <- ownedVars do
256- assert(tvar.owningState.get eq this, s"Inconsistent state in $this: it owns $tvar whose owningState is ${tvar.owningState.get}")
259+ val tvaros = tvar.owningState.nn.get
260+ assert(tvaros != null && (tvaros eq this), s"Inconsistent state in $this: it owns $tvar whose owningState is ${tvaros}")
257261 assert(!tvar.inst.exists, s"Inconsistent state in $this: it owns $tvar which is already instantiated")
258262 val inst = constraint.instType(tvar)
259263 if inst.exists then
@@ -266,9 +270,9 @@ class TyperState() {
266270 override def toString: String = {
267271 def ids(state: TyperState): List[String] =
268272 s"${state.id}${if (state.isCommittable) "" else "X"}" ::
269- (if (state.previous == null) Nil else ids(state.previous))
273+ (if (state.previous == null) Nil else ids(state.previous.uncheckedNN ))
270274 s"TS[${ids(this).mkString(", ")}]"
271275 }
272276
273- def stateChainStr: String = s"$this${if (previous == null) "" else previous.stateChainStr}"
277+ def stateChainStr: String = s"$this${if (previous == null) "" else previous.uncheckedNN. stateChainStr}"
274278}
0 commit comments