aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/TyperState.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-06-20 15:04:03 +0200
committerMartin Odersky <odersky@gmail.com>2014-06-20 15:04:19 +0200
commitb3364db33ff2ee2d57b4d0eaed03632099244f63 (patch)
treecfc94722c01bf6a7ddb3eff5411149e8a40235e1 /src/dotty/tools/dotc/core/TyperState.scala
parent7cf6202ea94c016ffc2d2528ad8add186e9f3827 (diff)
downloaddotty-b3364db33ff2ee2d57b4d0eaed03632099244f63.tar.gz
dotty-b3364db33ff2ee2d57b4d0eaed03632099244f63.tar.bz2
dotty-b3364db33ff2ee2d57b4d0eaed03632099244f63.zip
Avoid caching values that depend on typevar state.
TypeVars flip from the initial state, where underlying == origin to the final state where underlying == inst. This flip can invalidate information that depends on the underlying type of a TypeVar. Since we do not know when the flip occurs, we need to avoid keeping any such information in a cache. The commit makes three caches depend on a new value: typerState.ephemeral. The value is set to `true` each time we follow the underlying type of a TypeVar, and this disables cached information to be retained. A test case for this commit is t2693.scala. This test passes typechecking with the previous commit, but fails in -Ycheck:front because of stale cache info in an "#Apply" typeref. The present commit fixes that.
Diffstat (limited to 'src/dotty/tools/dotc/core/TyperState.scala')
-rw-r--r--src/dotty/tools/dotc/core/TyperState.scala12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/dotty/tools/dotc/core/TyperState.scala b/src/dotty/tools/dotc/core/TyperState.scala
index 8c742edab..fd8a534d4 100644
--- a/src/dotty/tools/dotc/core/TyperState.scala
+++ b/src/dotty/tools/dotc/core/TyperState.scala
@@ -23,6 +23,10 @@ class TyperState(r: Reporter) extends DotClass with Showable {
/** The uninstantiated variables */
def uninstVars = constraint.uninstVars
+ /** The ephemeral flag */
+ def ephemeral: Boolean = false
+ def ephemeral_=(x: Boolean): Unit = ()
+
/** Gives for each instantiated type var that does not yet have its `inst` field
* set, the instance value stored in the constraint. Storing instances in constraints
* is done only in a temporary way for contexts that may be retracted
@@ -76,6 +80,12 @@ extends TyperState(r) {
override def constraint = myConstraint
override def constraint_=(c: Constraint) = myConstraint = c
+ private var myEphemeral: Boolean = previous.ephemeral
+
+ override def ephemeral = myEphemeral
+ override def ephemeral_=(x: Boolean): Unit = { myEphemeral = x }
+
+
override def fresh(isCommittable: Boolean): TyperState =
new MutableTyperState(this, new StoreReporter, isCommittable)
@@ -96,11 +106,11 @@ extends TyperState(r) {
val targetState = ctx.typerState
assert(isCommittable)
targetState.constraint = constraint
-
constraint foreachTypeVar { tvar =>
if (tvar.owningState eq this)
tvar.owningState = targetState
}
+ targetState.ephemeral = ephemeral
targetState.gc()
reporter.flush()
}