aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/Types.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-06-29 19:35:24 +0200
committerMartin Odersky <odersky@gmail.com>2016-07-11 13:35:00 +0200
commitc136af18c1ff37663393e0ad738926776946679e (patch)
tree7720229e5b2b62b4ec33ac12805f1c56872e0a00 /src/dotty/tools/dotc/core/Types.scala
parentd0f82a50bffc059803b56a341c8fcd9a238431f7 (diff)
downloaddotty-c136af18c1ff37663393e0ad738926776946679e.tar.gz
dotty-c136af18c1ff37663393e0ad738926776946679e.tar.bz2
dotty-c136af18c1ff37663393e0ad738926776946679e.zip
Fixes to BetaReduce and asMemberOf; add a second betaReduce
The new one only reduces straight applications of type lambdas with definite arguments. It is called very early on appliedTo, and derivedRefinedType. The old one, now renamed to normalizeHkApply also handles wildcard arguments and can garbage collect general unneeded hk-refinements. It is called later, at various places. TODO: See what functionality of normalizeHkApply should go into betaReduce instead. Maybe we can even drop normalizeHkApply? However: need to be careful to maintain aliases for hk type inference. Handle LazyRefs in BetaReduce Needs to be careful to not skip LazyRefs when dealiasing. - Fix^2 of asMemberOf: This fix ensures that - under the old hk scheme test succeeds for compilestdlib and tasty-new-all - under the new scheme test succeeds for i94-nada (i.e. REP[T] = T). - Try to beta-reduce bounds before adding to a constraint. - More subtle handling of LazyRefs in BetaReduce - Another refinement to asMemberOf Need to assume lastSymbol in sync with lastDenotation. - Drop isSafe test from BetaReduce Instead, track the higherkinded argument names that a type variable could potentially instantiate to.
Diffstat (limited to 'src/dotty/tools/dotc/core/Types.scala')
-rw-r--r--src/dotty/tools/dotc/core/Types.scala39
1 files changed, 26 insertions, 13 deletions
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index 4f5bec56b..dadb5b95e 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -822,7 +822,16 @@ object Types {
/** Follow aliases and dereferences LazyRefs and instantiated TypeVars until type
* is no longer alias type, LazyRef, or instantiated type variable.
*/
- final def dealias(implicit ctx: Context): Type = this match {
+ final def dealias(implicit ctx: Context): Type = strictDealias match {
+ case tp: LazyRef => tp.ref.dealias
+ case tp => tp
+ }
+
+ /** Follow aliases and instantiated TypeVars until type
+ * is no longer alias type, or instantiated type variable.
+ * Do not follow LazyRefs
+ */
+ final def strictDealias(implicit ctx: Context): Type = this match {
case tp: TypeRef =>
if (tp.symbol.isClass) tp
else tp.info match {
@@ -832,19 +841,11 @@ object Types {
case tp: TypeVar =>
val tp1 = tp.instanceOpt
if (tp1.exists) tp1.dealias else tp
- case tp: LazyRef =>
- tp.ref.dealias
case tp: AnnotatedType =>
tp.derivedAnnotatedType(tp.tpe.dealias, tp.annot)
case tp => tp
}
- /** If this is a TypeAlias type, its alias otherwise this type itself */
- final def followTypeAlias(implicit ctx: Context): Type = this match {
- case TypeAlias(alias) => alias
- case _ => this
- }
-
/** Perform successive widenings and dealiasings until none can be applied anymore */
final def widenDealias(implicit ctx: Context): Type = {
val res = this.widen.dealias
@@ -859,6 +860,12 @@ object Types {
case _ => this
}
+ /** If this is a TypeAlias type, its alias otherwise this type itself */
+ final def followTypeAlias(implicit ctx: Context): Type = this match {
+ case TypeAlias(alias) => alias
+ case _ => this
+ }
+
/** If this is a (possibly aliased, annotated, and/or parameterized) reference to
* a class, the class type ref, otherwise NoType.
* @param refinementOK If `true` we also skip non-parameter refinements.
@@ -1579,14 +1586,20 @@ object Types {
// we might now get cycles over members that are in a refinement but that lack
// a symbol. Without the following precaution i974.scala stackoverflows when compiled
// with new hk scheme.
- val saved = lastDenotation
- if (name.isTypeName && lastDenotation != null && (lastDenotation.symbol ne NoSymbol))
+ val savedDenot = lastDenotation
+ val savedSymbol = lastSymbol
+ if (prefix.isInstanceOf[RecThis] && name.isTypeName) {
lastDenotation = ctx.anyTypeDenot
+ lastSymbol = NoSymbol
+ }
try
if (name.isShadowedName) prefix.nonPrivateMember(name.revertShadowed)
else prefix.member(name)
finally
- if (lastDenotation eq ctx.anyTypeDenot) lastDenotation = saved
+ if (lastDenotation eq ctx.anyTypeDenot) {
+ lastDenotation = savedDenot
+ lastSymbol = savedSymbol
+ }
}
/** (1) Reduce a type-ref `W # X` or `W { ... } # U`, where `W` is a wildcard type
@@ -2753,7 +2766,7 @@ object Types {
myRepr
}
- override def toString = s"Skolem($info)"
+ override def toString = s"Skolem($hashCode)"
}
final class CachedSkolemType(info: Type) extends SkolemType(info)