aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/Types.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-06-29 19:57:02 +0200
committerMartin Odersky <odersky@gmail.com>2016-07-11 13:35:02 +0200
commite749d832e9adebc502c961d743b3b29072f8116a (patch)
tree4c9bdc83925a118ce4cfe37f9d2deea2c6ee7613 /src/dotty/tools/dotc/core/Types.scala
parent6414f3bccf5319d273e8f5eb5461b111e9270b34 (diff)
downloaddotty-e749d832e9adebc502c961d743b3b29072f8116a.tar.gz
dotty-e749d832e9adebc502c961d743b3b29072f8116a.tar.bz2
dotty-e749d832e9adebc502c961d743b3b29072f8116a.zip
Various tweaks
- Swap order of subtype tests The theory is that if two refined types have the same refined name, then they are likely to be of related classes. So it seems more fruitful to check the argument before the typeconstructor because that way we test the part that's more likely to fail first. Rough observations seem to indicate a 3% improvement in the junit test time. - Cleanups Drop some unnecessary cases; improve comments. - Smarter handling of LazyRefs in betaReduce Try to combine type constructor and arguments under a common LazyRef. - Optimize RecType/RecType comparisons - Fix compareHkLambda, make it check variances.
Diffstat (limited to 'src/dotty/tools/dotc/core/Types.scala')
-rw-r--r--src/dotty/tools/dotc/core/Types.scala43
1 files changed, 14 insertions, 29 deletions
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index 3d4ec6601..2120706f6 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -2151,15 +2151,6 @@ object Types {
throw new AssertionError(s"bad instantiation: $this")
def checkInst(implicit ctx: Context): this.type = {
- if (false && Config.newHK && refinedName.isHkArgName && refinedInfo.isInstanceOf[TypeAlias]) {
- parent.stripTypeVar match {
- case TypeApplications.TypeLambda(_, _) =>
- println(i"fshy: $this")
- println(s"fshy: $this")
- new Error().printStackTrace()
- case _ =>
- }
- }
if (refinedName == tpnme.hkApplyOBS)
parent.stripTypeVar match {
case RefinedType(_, name, _) if name.isHkArgName => // ok
@@ -2190,12 +2181,16 @@ object Types {
case _ =>
tp
}
- val reduced = substAlias(parent)
- if (reduced ne parent) {
- hk.println(i"REDUCE $this ----> ${reduced}")
- reduced
+ parent match {
+ case parent: LazyRef =>
+ LazyRef(() => derivedRefinedType(parent.ref, refinedName, refinedInfo))
+ case _ =>
+ val reduced = substAlias(parent)
+ if (reduced ne parent) {
+ hk.println(i"REDUCE $this ----> ${reduced}")
+ reduced
+ } else this
}
- else this
case _ =>
this
}
@@ -2304,7 +2299,6 @@ object Types {
case tp: TypeRef => apply(x, tp.prefix)
case tp: RecThis => RecType.this eq tp.binder
case tp: LazyRef => true // Assume a reference to be safe.
- // TODO: Check that all accumulators handle LazyRefs correctly
case _ => foldOver(x, tp)
}
}
@@ -2315,22 +2309,13 @@ object Types {
override def computeHash = doHash(parent)
override def toString = s"RecType($parent | $hashCode)"
+
+ private def checkInst(implicit ctx: Context): this.type = {
+ this
+ }
}
object RecType {
- /* Note: this might well fail for nested Recs.
- * Failing scenario: Rebind a nest rec, creates a new rec
- * but it still has RecThis references to the outer rec.
- def checkInst(tp: Type)(implicit ctx: Context): tp.type = {
- var binders: List[RecType] = Nil
- tp.foreachPart {
- case rt: RecType => binders = rt :: binders
- case rt: RecThis => assert(binders contains rt.binder)
- case _ =>
- }
- tp
- }
- */
/** Create a RecType, normalizing its contents. This means:
*
@@ -2356,7 +2341,7 @@ object Types {
case tp =>
tp
}
- unique(rt.derivedRecType(normalize(rt.parent)))
+ unique(rt.derivedRecType(normalize(rt.parent))).checkInst
}
def closeOver(parentExp: RecType => Type)(implicit ctx: Context) = {
val rt = this(parentExp)