@@ -5,15 +5,23 @@ package core
55import Types ._
66import Flags ._
77import Contexts ._
8- import util .{SimpleIdentityMap , DotClass }
8+ import util .{SimpleIdentityMap , SimpleIdentitySet , DotClass }
99import reporting ._
1010import printing .{Showable , Printer }
1111import printing .Texts ._
1212import config .Config
1313import collection .mutable
1414import java .lang .ref .WeakReference
15+ import Decorators ._
1516
16- class TyperState (previous : TyperState /* | Null */ ) extends DotClass with Showable {
17+ object TyperState {
18+ @ sharable private var nextId : Int = 0
19+ }
20+
21+ class TyperState (previous : TyperState /* | Null */ ) {
22+
23+ val id = TyperState .nextId
24+ TyperState .nextId += 1
1725
1826 private [this ] var myReporter =
1927 if (previous == null ) new ConsoleReporter () else previous.reporter
@@ -42,19 +50,6 @@ class TyperState(previous: TyperState /* | Null */) extends DotClass with Showab
4250 private val previousConstraint =
4351 if (previous == null ) constraint else previous.constraint
4452
45- private [this ] var myEphemeral : Boolean =
46- if (previous == null ) false else previous.ephemeral
47-
48- /** The ephemeral flag is set as a side effect if an operation accesses
49- * the underlying type of a type variable. The reason we need this flag is
50- * that any such operation is not referentially transparent; it might logically change
51- * its value at the moment the type variable is instantiated. Caching code needs to
52- * check the ephemeral flag; If the flag is set during an operation, the result
53- * of that operation should not be cached.
54- */
55- def ephemeral = myEphemeral
56- def ephemeral_= (x : Boolean ): Unit = { myEphemeral = x }
57-
5853 private [this ] var myIsCommittable = true
5954
6055 def isCommittable = myIsCommittable
@@ -81,6 +76,11 @@ class TyperState(previous: TyperState /* | Null */) extends DotClass with Showab
8176 /** The uninstantiated variables */
8277 def uninstVars = constraint.uninstVars
8378
79+ /** The set of uninstantiated type variables which have this state as their owning state */
80+ private [this ] var myOwnedVars : TypeVars = SimpleIdentitySet .empty
81+ def ownedVars = myOwnedVars
82+ def ownedVars_= (vs : TypeVars ): Unit = myOwnedVars = vs
83+
8484 /** Gives for each instantiated type var that does not yet have its `inst` field
8585 * set, the instance value stored in the constraint. Storing instances in constraints
8686 * is done only in a temporary way for contexts that may be retracted
@@ -159,7 +159,7 @@ class TyperState(previous: TyperState /* | Null */) extends DotClass with Showab
159159 constraint foreachTypeVar { tvar =>
160160 if (tvar.owningState.get eq this ) tvar.owningState = new WeakReference (targetState)
161161 }
162- targetState.ephemeral |= ephemeral
162+ targetState.ownedVars ++= ownedVars
163163 targetState.gc()
164164 reporter.flush()
165165 isCommitted = true
@@ -185,8 +185,7 @@ class TyperState(previous: TyperState /* | Null */) extends DotClass with Showab
185185 constraint = constraint.remove(poly)
186186 }
187187
188- override def toText ( printer : Printer ) : Text = constraint.toText(printer)
188+ override def toString : String = s " TS[ $id ] "
189189
190- def hashesStr : String =
191- if (previous == null ) " " else hashCode.toString + " -> " + previous.hashesStr
190+ def stateChainStr : String = s " $this${if (previous == null ) " " else previous.stateChainStr}"
192191}
0 commit comments