aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-07-12 19:15:19 +0200
committerMartin Odersky <odersky@gmail.com>2016-07-13 13:47:43 +0200
commit1443fd4c844c1c54e59479e156833d2cce9a349a (patch)
tree44cd0ee637d25116f8a941c0b892fa43d74ba31b /src
parent7df0fa52ade1e4cfe3d50a9ea7e5adf2d8c161c0 (diff)
downloaddotty-1443fd4c844c1c54e59479e156833d2cce9a349a.tar.gz
dotty-1443fd4c844c1c54e59479e156833d2cce9a349a.tar.bz2
dotty-1443fd4c844c1c54e59479e156833d2cce9a349a.zip
Optimize hk comparisons
Use (cached) superType where possible.
Diffstat (limited to 'src')
-rw-r--r--src/dotty/tools/dotc/core/TypeComparer.scala22
-rw-r--r--src/dotty/tools/dotc/core/Types.scala13
2 files changed, 24 insertions, 11 deletions
diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala
index a763e1de8..31cc87b3a 100644
--- a/src/dotty/tools/dotc/core/TypeComparer.scala
+++ b/src/dotty/tools/dotc/core/TypeComparer.scala
@@ -668,25 +668,25 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
* tp1 <:< tp2 using fourthTry (this might instantiate params in tp1)
* tp1 <:< app2 using isSubType (this might instantiate params in tp2)
*/
- def compareLower(tycon2bounds: TypeBounds): Boolean = {
- val app2 = tycon2bounds.lo.applyIfParameterized(args2)
- if (tycon2bounds.lo eq tycon2bounds.hi) isSubType(tp1, app2)
- else either(fourthTry(tp1, tp2), isSubType(tp1, app2))
+ def compareLower(tycon2bounds: TypeBounds, tyconIsTypeRef: Boolean): Boolean = {
+ def app2 = tycon2bounds.lo.applyIfParameterized(args2)
+ if (tycon2bounds.lo eq tycon2bounds.hi)
+ isSubType(tp1, if (tyconIsTypeRef) tp2.superType else app2)
+ else
+ either(fourthTry(tp1, tp2), isSubType(tp1, app2))
}
tycon2 match {
case param2: PolyParam =>
isMatchingApply(tp1) || {
if (canConstrain(param2)) canInstantiate(param2)
- else compareLower(bounds(param2))
+ else compareLower(bounds(param2), tyconIsTypeRef = false)
}
case tycon2: TypeRef =>
isMatchingApply(tp1) ||
- compareLower(tycon2.info.bounds)
- case tycon2: TypeVar =>
- isSubType(tp1, tycon2.underlying.appliedTo(args2))
- case tycon2: AnnotatedType =>
- compareHkApply2(tp1, tp2, tycon2.underlying, args2)
+ compareLower(tycon2.info.bounds, tyconIsTypeRef = true)
+ case _: TypeVar | _: AnnotatedType =>
+ isSubType(tp1, tp2.superType)
case _ =>
false
}
@@ -706,7 +706,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
canConstrain(param1) && canInstantiate ||
isSubType(bounds(param1).hi.applyIfParameterized(args1), tp2)
case tycon1: TypeProxy =>
- isSubType(tycon1.superType.applyIfParameterized(args1), tp2)
+ isSubType(tp1.superType, tp2)
case _ =>
false
}
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index 938e40128..fc68740eb 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -2661,6 +2661,19 @@ object Types {
}
cachedSuper
}
+
+ def lowerBound(implicit ctx: Context) = tycon.stripTypeVar match {
+ case tycon: TypeRef =>
+ tycon.info match {
+ case TypeBounds(lo, hi) =>
+ if (lo eq hi) superType // optimization, can profit from caching in this case
+ else lo.applyIfParameterized(args)
+ case _ => NoType
+ }
+ case _ =>
+ NoType
+ }
+
/*
def lowerBound(implicit ctx: Context): Type = tycon.stripTypeVar match {
case tp: TypeRef =>