diff options
author | Martin Odersky <odersky@gmail.com> | 2015-01-13 17:35:12 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2015-01-13 17:35:12 +0100 |
commit | 3e3ef5222429beddedd6912feeff7975bdd67bf8 (patch) | |
tree | 9646fa0c2fd872c923fc8d3cb2a16f72884c30ee /src/dotty | |
parent | 155049286628843eb7aeb2d8d610ac53291ea6f3 (diff) | |
download | dotty-3e3ef5222429beddedd6912feeff7975bdd67bf8.tar.gz dotty-3e3ef5222429beddedd6912feeff7975bdd67bf8.tar.bz2 dotty-3e3ef5222429beddedd6912feeff7975bdd67bf8.zip |
Two new hooks in ConstraintHandling
Unlike isSubtypeWhenFrozen, these can be implemented by
TrackingConstraint without needing full bounds, which is expensive.
Diffstat (limited to 'src/dotty')
-rw-r--r-- | src/dotty/tools/dotc/core/ConstraintHandling.scala | 8 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/TypeComparer.scala | 4 |
2 files changed, 9 insertions, 3 deletions
diff --git a/src/dotty/tools/dotc/core/ConstraintHandling.scala b/src/dotty/tools/dotc/core/ConstraintHandling.scala index 2aa2a4acd..c3243f5d9 100644 --- a/src/dotty/tools/dotc/core/ConstraintHandling.scala +++ b/src/dotty/tools/dotc/core/ConstraintHandling.scala @@ -68,8 +68,14 @@ trait ConstraintHandling { try isSubType(tp1, tp2) finally frozenConstraint = saved } + + protected def constraintImpliesSub(param: PolyParam, tp: Type): Boolean = + isSubTypeWhenFrozen(bounds(param).hi, tp) + + protected def constraintImpliesSuper(param: PolyParam, tp: Type): Boolean = + isSubTypeWhenFrozen(tp, bounds(param).lo) - /** The current bounds of type parameter `param` */ + /** The current bounds of type parameter `param` */ final def bounds(param: PolyParam): TypeBounds = constraint at param match { case bounds: TypeBounds if !ignoreConstraint => bounds case _ => param.binder.paramBounds(param.paramNum) diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala index 457b29829..d327da017 100644 --- a/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/src/dotty/tools/dotc/core/TypeComparer.scala @@ -180,7 +180,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling wi tp2 == tp1 || { if (solvedConstraint && (constraint contains tp2)) isSubType(tp1, bounds(tp2).lo) else - isSubTypeWhenFrozen(tp1, bounds(tp2).lo) || { + constraintImpliesSuper(tp2, tp1) || { if (isConstrained(tp2)) addConstraint(tp2, tp1.widenExpr, fromBelow = true) else (ctx.mode is Mode.TypevarsMissContext) || secondTry(tp1, tp2) } @@ -242,7 +242,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling wi tp1 == tp2 || { if (solvedConstraint && (constraint contains tp1)) isSubType(bounds(tp1).lo, tp2) else - isSubTypeWhenFrozen(bounds(tp1).hi, tp2) || { + constraintImpliesSub(tp1, tp2) || { if (isConstrained(tp1)) addConstraint(tp1, tp2, fromBelow = false) && { if ((!frozenConstraint) && |