aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/TyperState.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/dotty/tools/dotc/core/TyperState.scala')
-rw-r--r--src/dotty/tools/dotc/core/TyperState.scala42
1 files changed, 36 insertions, 6 deletions
diff --git a/src/dotty/tools/dotc/core/TyperState.scala b/src/dotty/tools/dotc/core/TyperState.scala
index e492eee60..b00e55e29 100644
--- a/src/dotty/tools/dotc/core/TyperState.scala
+++ b/src/dotty/tools/dotc/core/TyperState.scala
@@ -14,10 +14,17 @@ class TyperState(val reporter: Reporter = ThrowingReporter) extends DotClass {
def constraint: Constraint = new Constraint(SimpleMap.Empty)
/** The currently uninstantiated TypeVars */
- def undetVars: List[TypeVar] = Nil
+ def undetVars: Set[TypeVar] = Set()
+
+ /** A map that records for instantiated type vars their instance type.
+ * Used only in a temporary way for contexts that may be retracted
+ * without also retracting the type var.
+ */
+ def instType: SimpleMap[TypeVar, Type] = SimpleMap.Empty
def constraint_=(c: Constraint): Unit = {}
- def undetVars_=(vs: List[TypeVar]): Unit = unsupported("undetVars_=")
+ def undetVars_=(vs: Set[TypeVar]): Unit = unsupported("undetVars_=")
+ def instType_=(m: SimpleMap[TypeVar, Type]): Unit = unsupported("instType_=")
def fresh: TyperState = this
@@ -28,19 +35,42 @@ class MutableTyperState(previous: TyperState, reporter: Reporter)
extends TyperState(reporter) {
private var myConstraint: Constraint = previous.constraint
- private var myUndetVars: List[TypeVar] = previous.undetVars
+ private var myUndetVars: Set[TypeVar] = previous.undetVars
+ private var myInstType: SimpleMap[TypeVar, Type] = previous.instType
override def constraint = myConstraint
override def undetVars = myUndetVars
+ override def instType = myInstType
override def constraint_=(c: Constraint) = myConstraint = c
- override def undetVars_=(vs: List[TypeVar]) = myUndetVars = vs
+ override def undetVars_=(vs: Set[TypeVar]) = myUndetVars = vs
+ override def instType_=(m: SimpleMap[TypeVar, Type]): Unit = myInstType = m
override def fresh: TyperState = new MutableTyperState(this, new StoreReporter)
+ /** Commit typer state so that its information is copied into current typer state
+ * In addition (1) the owning state of undetermined or temporarily instantiated
+ * type variables changes from this typer state to the current one. (2) Variables
+ * that were temporarily instantiated in the current typer state are permanently
+ * instantiated instead.
+ */
override def commit()(implicit ctx: Context) = {
- ctx.typerState.constraint = constraint
- ctx.typerState.undetVars = undetVars
+ var targetState = ctx.typerState
+ targetState.constraint = constraint
+ targetState.undetVars = undetVars
+ targetState.instType = instType
+
+ def adjustOwningState(tvar: TypeVar) =
+ if (tvar.owningState eq this) tvar.owningState = targetState
+ undetVars foreach adjustOwningState
+ instType foreachKey { case tvar: TypeVar =>
+ adjustOwningState(tvar)
+ if (tvar.owningState == targetState) {
+ tvar.inst = instType(tvar)
+ targetState.instType = targetState.instType remove tvar
+ }
+ }
+
reporter.flush()
}
}