diff options
author | Martin Odersky <odersky@gmail.com> | 2013-11-20 15:06:12 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2013-11-20 15:06:12 +0100 |
commit | 5240de72c9cc0beb552dc1fd77510b3d7b19a8c6 (patch) | |
tree | fbd652d601f647f6788bb15a02f6d8216a70083c | |
parent | db5066bbb4c281bd3b65fe6422314afee115de5e (diff) | |
download | dotty-5240de72c9cc0beb552dc1fd77510b3d7b19a8c6.tar.gz dotty-5240de72c9cc0beb552dc1fd77510b3d7b19a8c6.tar.bz2 dotty-5240de72c9cc0beb552dc1fd77510b3d7b19a8c6.zip |
Splitting constraint.appky into at, bounds, contains.
Motivation: Keep usages separate, prepare for larger constraint refactoring.
-rw-r--r-- | src/dotty/tools/dotc/core/Constraint.scala | 9 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/TypeComparer.scala | 12 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/Types.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Inferencing.scala | 4 |
4 files changed, 16 insertions, 11 deletions
diff --git a/src/dotty/tools/dotc/core/Constraint.scala b/src/dotty/tools/dotc/core/Constraint.scala index d2ea6aa65..7d1ad5abe 100644 --- a/src/dotty/tools/dotc/core/Constraint.scala +++ b/src/dotty/tools/dotc/core/Constraint.scala @@ -28,11 +28,16 @@ class Constraint(val map: SimpleMap[PolyType, Array[Type]]) extends AnyVal with /** The constraint for given type parameter `param`, or NoType if `param` is not part of * the constraint domain. */ - def apply(param: PolyParam): Type = { + def at(param: PolyParam): Type = { val entries = map(param.binder) if (entries == null) NoType else entries(param.paramNum) } + /** The constraint bounds for given type parameter `param`. + * @pre `param` is not part of the constraint domain. + */ + def bounds(param: PolyParam): TypeBounds = at(param).asInstanceOf[TypeBounds] + /** The constraint for the type parameters of `pt`. * @pre The polytype's type parameters are contained in the constraint's domain. */ @@ -116,7 +121,7 @@ class Constraint(val map: SimpleMap[PolyType, Array[Type]]) extends AnyVal with def constraintText(indent: Int, printer: Printer): Text = { val assocs = for (param <- domainParams) - yield (" " * indent) ~ param.toText(printer) ~ this(param).toText(printer) + yield (" " * indent) ~ param.toText(printer) ~ at(param).toText(printer) Text(assocs, "\n") } diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala index a796d7e43..a517f4b8c 100644 --- a/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/src/dotty/tools/dotc/core/TypeComparer.scala @@ -72,7 +72,7 @@ class TypeComparer(initctx: Context) extends DotClass { !frozenConstraint && { println(s"adding ${param.show} ${if (fromBelow) ">:>" else "<:<"} ${bound.show} to ${constraint.show}") bound match { - case bound: PolyParam if constraint(bound).exists => + case bound: PolyParam if constraint contains bound => addConstraint1(param, bound, fromBelow) && addConstraint1(bound, param, !fromBelow) case _ => @@ -99,7 +99,7 @@ class TypeComparer(initctx: Context) extends DotClass { } } } - val bounds = constraint(param).asInstanceOf[TypeBounds] + val bounds = constraint.bounds(param) val bound = if (fromBelow) bounds.lo else bounds.hi val inst = avoidParam(bound) println(s"approx ${param.show}, from below = $fromBelow, bound = ${bound.show}, inst = ${inst.show}") @@ -206,7 +206,7 @@ class TypeComparer(initctx: Context) extends DotClass { case tp2: PolyParam => tp2 == tp1 || { isSubTypeWhenFrozen(tp1, bounds(tp2).lo) || { - constraint(tp2) match { + constraint at tp2 match { case TypeBounds(lo, _) => addConstraint(tp2, tp1.widen.dealias, fromBelow = true) case _ => secondTry(tp1, tp2) } @@ -245,7 +245,7 @@ class TypeComparer(initctx: Context) extends DotClass { (tp1 == tp2) || { isSubTypeWhenFrozen(bounds(tp1).hi, tp2) || { assert(frozenConstraint || !(tp2 isRef defn.NothingClass)) // !!!DEBUG - constraint(tp1) match { + constraint at tp1 match { case TypeBounds(_, hi) => addConstraint(tp1, tp2.dealias, fromBelow = false) case _ => thirdTry(tp1, tp2) } @@ -384,14 +384,14 @@ class TypeComparer(initctx: Context) extends DotClass { } /** The current bounds of type parameter `param` */ - def bounds(param: PolyParam): TypeBounds = constraint(param) match { + def bounds(param: PolyParam): TypeBounds = constraint at param match { case bounds: TypeBounds => bounds case _ => param.binder.paramBounds(param.paramNum) } /** Defer constraining type variables when comnpared against prototypes */ def isMatchedByProto(proto: ProtoType, tp: Type) = tp.stripTypeVar match { - case tp: PolyParam if constraint(tp).exists => true + case tp: PolyParam if constraint contains tp => true case _ => proto.isMatchedBy(tp) } diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index dd17f5672..1b880b86f 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -2033,7 +2033,7 @@ object Types { * is also a singleton type. */ def instantiate(fromBelow: Boolean)(implicit ctx: Context): Type = { - val upperBound = ctx.typerState.constraint(origin).bounds.hi + val upperBound = ctx.typerState.constraint.bounds(origin).hi def isSingleton(tp: Type): Boolean = tp match { case tp: SingletonType => true case AndType(tp1, tp2) => isSingleton(tp1) | isSingleton(tp2) diff --git a/src/dotty/tools/dotc/typer/Inferencing.scala b/src/dotty/tools/dotc/typer/Inferencing.scala index eb88c0764..a364d0f3d 100644 --- a/src/dotty/tools/dotc/typer/Inferencing.scala +++ b/src/dotty/tools/dotc/typer/Inferencing.scala @@ -259,8 +259,8 @@ object Inferencing { if (v == 1) tvar.instantiate(fromBelow = false) else if (v == -1) tvar.instantiate(fromBelow = true) else { - val bounds @ TypeBounds(lo, hi) = ctx.typerState.constraint(tvar.origin) - if (!(hi <:< lo)) result = Some(tvar) + val bounds = ctx.typerState.constraint.bounds(tvar.origin) + if (!(bounds.hi <:< bounds.lo)) result = Some(tvar) tvar.instantiate(fromBelow = false) } result |