aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/OrderingConstraint.scala
diff options
context:
space:
mode:
authorDmitry Petrashko <dmitry.petrashko@gmail.com>2015-04-09 16:57:55 +0200
committerDmitry Petrashko <dmitry.petrashko@gmail.com>2015-04-09 16:57:55 +0200
commitafa630a78b4f2cd9bd799b5a0199b99548f18aaa (patch)
tree9da8ad19573c8c913b47a232a3b57662aa660ec1 /src/dotty/tools/dotc/core/OrderingConstraint.scala
parent33f5d62bcbc6ec649e739958fc19c4524305471c (diff)
downloaddotty-afa630a78b4f2cd9bd799b5a0199b99548f18aaa.tar.gz
dotty-afa630a78b4f2cd9bd799b5a0199b99548f18aaa.tar.bz2
dotty-afa630a78b4f2cd9bd799b5a0199b99548f18aaa.zip
Remove trailing spaces in Dotty source.
Diffstat (limited to 'src/dotty/tools/dotc/core/OrderingConstraint.scala')
-rw-r--r--src/dotty/tools/dotc/core/OrderingConstraint.scala192
1 files changed, 96 insertions, 96 deletions
diff --git a/src/dotty/tools/dotc/core/OrderingConstraint.scala b/src/dotty/tools/dotc/core/OrderingConstraint.scala
index 0c39a26a6..21d003451 100644
--- a/src/dotty/tools/dotc/core/OrderingConstraint.scala
+++ b/src/dotty/tools/dotc/core/OrderingConstraint.scala
@@ -16,10 +16,10 @@ object OrderingConstraint {
/** The type of `OrderingConstraint#boundsMap` */
type ParamBounds = SimpleMap[PolyType, Array[Type]]
-
+
/** The type of `OrderingConstraint#lowerMap`, `OrderingConstraint#upperMap` */
type ParamOrdering = SimpleMap[PolyType, Array[List[PolyParam]]]
-
+
/** A new constraint with given maps */
private def newConstraint(boundsMap: ParamBounds, lowerMap: ParamOrdering, upperMap: ParamOrdering)(implicit ctx: Context) : OrderingConstraint = {
val result = new OrderingConstraint(boundsMap, lowerMap, upperMap)
@@ -27,29 +27,29 @@ object OrderingConstraint {
ctx.runInfo.recordConstraintSize(result, result.boundsMap.size)
result
}
-
+
/** A lens for updating a single entry array in one of the three constraint maps */
abstract class ConstraintLens[T <: AnyRef: ClassTag] {
- def entries(c: OrderingConstraint, poly: PolyType): Array[T]
+ def entries(c: OrderingConstraint, poly: PolyType): Array[T]
def updateEntries(c: OrderingConstraint, poly: PolyType, entries: Array[T])(implicit ctx: Context): OrderingConstraint
def initial: T
-
+
def apply(c: OrderingConstraint, poly: PolyType, idx: Int) = {
val es = entries(c, poly)
if (es == null) initial else es(idx)
}
-
+
/** The `current` constraint but with the entry for `param` updated to `entry`.
* `current` is used linearly. If it is different from `prev` it is
* known to be dead after the call. Hence it is OK to update destructively
* parts of `current` which are not shared by `prev`.
*/
- def update(prev: OrderingConstraint, current: OrderingConstraint,
+ def update(prev: OrderingConstraint, current: OrderingConstraint,
poly: PolyType, idx: Int, entry: T)(implicit ctx: Context): OrderingConstraint = {
var es = entries(current, poly)
if (es != null && (es(idx) eq entry)) current
else {
- val result =
+ val result =
if (es == null) {
es = Array.fill(poly.paramNames.length)(initial)
updateEntries(current, poly, es)
@@ -64,40 +64,40 @@ object OrderingConstraint {
result
}
}
-
- def update(prev: OrderingConstraint, current: OrderingConstraint,
+
+ def update(prev: OrderingConstraint, current: OrderingConstraint,
param: PolyParam, entry: T)(implicit ctx: Context): OrderingConstraint =
update(prev, current, param.binder, param.paramNum, entry)
-
- def map(prev: OrderingConstraint, current: OrderingConstraint,
- poly: PolyType, idx: Int, f: T => T)(implicit ctx: Context): OrderingConstraint =
+
+ def map(prev: OrderingConstraint, current: OrderingConstraint,
+ poly: PolyType, idx: Int, f: T => T)(implicit ctx: Context): OrderingConstraint =
update(prev, current, poly, idx, f(apply(current, poly, idx)))
- def map(prev: OrderingConstraint, current: OrderingConstraint,
- param: PolyParam, f: T => T)(implicit ctx: Context): OrderingConstraint =
+ def map(prev: OrderingConstraint, current: OrderingConstraint,
+ param: PolyParam, f: T => T)(implicit ctx: Context): OrderingConstraint =
map(prev, current, param.binder, param.paramNum, f)
}
val boundsLens = new ConstraintLens[Type] {
- def entries(c: OrderingConstraint, poly: PolyType): Array[Type] =
+ def entries(c: OrderingConstraint, poly: PolyType): Array[Type] =
c.boundsMap(poly)
- def updateEntries(c: OrderingConstraint, poly: PolyType, entries: Array[Type])(implicit ctx: Context): OrderingConstraint =
+ def updateEntries(c: OrderingConstraint, poly: PolyType, entries: Array[Type])(implicit ctx: Context): OrderingConstraint =
newConstraint(c.boundsMap.updated(poly, entries), c.lowerMap, c.upperMap)
def initial = NoType
}
-
+
val lowerLens = new ConstraintLens[List[PolyParam]] {
- def entries(c: OrderingConstraint, poly: PolyType): Array[List[PolyParam]] =
+ def entries(c: OrderingConstraint, poly: PolyType): Array[List[PolyParam]] =
c.lowerMap(poly)
- def updateEntries(c: OrderingConstraint, poly: PolyType, entries: Array[List[PolyParam]])(implicit ctx: Context): OrderingConstraint =
+ def updateEntries(c: OrderingConstraint, poly: PolyType, entries: Array[List[PolyParam]])(implicit ctx: Context): OrderingConstraint =
newConstraint(c.boundsMap, c.lowerMap.updated(poly, entries), c.upperMap)
def initial = Nil
}
val upperLens = new ConstraintLens[List[PolyParam]] {
- def entries(c: OrderingConstraint, poly: PolyType): Array[List[PolyParam]] =
+ def entries(c: OrderingConstraint, poly: PolyType): Array[List[PolyParam]] =
c.upperMap(poly)
- def updateEntries(c: OrderingConstraint, poly: PolyType, entries: Array[List[PolyParam]])(implicit ctx: Context): OrderingConstraint =
+ def updateEntries(c: OrderingConstraint, poly: PolyType, entries: Array[List[PolyParam]])(implicit ctx: Context): OrderingConstraint =
newConstraint(c.boundsMap, c.lowerMap, c.upperMap.updated(poly, entries))
def initial = Nil
}
@@ -105,7 +105,7 @@ object OrderingConstraint {
import OrderingConstraint._
-/** Constraint over undetermined type parameters that keeps separate maps to
+/** Constraint over undetermined type parameters that keeps separate maps to
* reflect parameter orderings.
* @param boundsMap a map from PolyType to arrays.
* Each array contains twice the number of entries as there a type parameters
@@ -115,23 +115,23 @@ import OrderingConstraint._
* An instantiated type parameter is represented by having its instance type in
* the corresponding array entry. The dual use of arrays for poly params
* and typevars is to save space and hopefully gain some speed.
- *
+ *
* @param lowerMap a map from PolyTypes to arrays. Each array entry corresponds
* to a parameter P of the polytype; it contains all constrained parameters
- * Q that are known to be smaller than P, i.e. Q <: P.
+ * Q that are known to be smaller than P, i.e. Q <: P.
* @param upperMap a map from PolyTypes to arrays. Each array entry corresponds
* to a parameter P of the polytype; it contains all constrained parameters
- * Q that are known to be greater than P, i.e. P <: Q.
+ * Q that are known to be greater than P, i.e. P <: Q.
*/
-class OrderingConstraint(private val boundsMap: ParamBounds,
- private val lowerMap : ParamOrdering,
+class OrderingConstraint(private val boundsMap: ParamBounds,
+ private val lowerMap : ParamOrdering,
private val upperMap : ParamOrdering) extends Constraint {
-
+
type This = OrderingConstraint
-
-
+
+
// ----------- Basic indices --------------------------------------------------
-
+
/** The number of type parameters in the given entry array */
private def paramCount(entries: Array[Type]) = entries.length >> 1
@@ -145,7 +145,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
if (entries == null) NoType
else entries(param.paramNum)
}
-
+
// ----------- Contains tests --------------------------------------------------
def contains(pt: PolyType): Boolean = boundsMap(pt) != null
@@ -163,42 +163,42 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
}
private def isBounds(tp: Type) = tp.isInstanceOf[TypeBounds]
-
+
// ---------- Dependency handling ----------------------------------------------
-
+
def lower(param: PolyParam): List[PolyParam] = lowerLens(this, param.binder, param.paramNum)
def upper(param: PolyParam): List[PolyParam] = upperLens(this, param.binder, param.paramNum)
-
+
def minLower(param: PolyParam): List[PolyParam] = {
val all = lower(param)
all.filterNot(p => all.exists(isLess(p, _)))
}
-
+
def minUpper(param: PolyParam): List[PolyParam] = {
val all = upper(param)
all.filterNot(p => all.exists(isLess(_, p)))
}
-
+
def exclusiveLower(param: PolyParam, butNot: PolyParam): List[PolyParam] =
lower(param).filterNot(isLess(_, butNot))
-
+
def exclusiveUpper(param: PolyParam, butNot: PolyParam): List[PolyParam] =
upper(param).filterNot(isLess(butNot, _))
-
+
// ---------- Info related to PolyParams -------------------------------------------
def isLess(param1: PolyParam, param2: PolyParam): Boolean =
upper(param1).contains(param2)
- def nonParamBounds(param: PolyParam): TypeBounds =
+ def nonParamBounds(param: PolyParam): TypeBounds =
entry(param).asInstanceOf[TypeBounds]
-
+
def fullLowerBound(param: PolyParam)(implicit ctx: Context): Type =
(nonParamBounds(param).lo /: minLower(param))(_ | _)
- def fullUpperBound(param: PolyParam)(implicit ctx: Context): Type =
+ def fullUpperBound(param: PolyParam)(implicit ctx: Context): Type =
(nonParamBounds(param).hi /: minUpper(param))(_ & _)
-
+
def fullBounds(param: PolyParam)(implicit ctx: Context): TypeBounds =
nonParamBounds(param).derivedTypeBounds(fullLowerBound(param), fullUpperBound(param))
@@ -209,17 +209,17 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
val tvar = typeVar(entries, param.paramNum)
if (tvar != null) tvar else NoType
}
- }
+ }
// ---------- Adding PolyTypes --------------------------------------------------
-
+
/** The list of parameters P such that, for a fresh type parameter Q:
- *
+ *
* Q <: tp implies Q <: P and isUpper = true, or
* tp <: Q implies P <: Q and isUpper = false
*/
def dependentParams(tp: Type, isUpper: Boolean): List[PolyParam] = tp match {
- case param: PolyParam if contains(param) =>
+ case param: PolyParam if contains(param) =>
param :: (if (isUpper) upper(param) else lower(param))
case tp: AndOrType =>
val ps1 = dependentParams(tp.tp1, isUpper)
@@ -228,7 +228,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
case _ =>
Nil
}
-
+
/** The bound type `tp` without constrained parameters which are clearly
* dependent. A parameter in an upper bound is clearly dependent if it appears
* in a hole of a context H given by:
@@ -237,7 +237,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
* H & T
* T & H
*
- * (the idea is that a parameter P in a H context is guaranteed to be a supertype of the
+ * (the idea is that a parameter P in a H context is guaranteed to be a supertype of the
* bounded parameter.)
* Analogously, a parameter in a lower bound is clearly dependent if it appears
* in a hole of a context H given by:
@@ -245,18 +245,18 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
* L = []
* L | T
* T | L
- *
+ *
* "Clearly dependent" is not synonymous with "dependent" in the sense
* it is defined in `dependentParams`. Dependent parameters are handled
* in `updateEntry`. The idea of stripping off clearly dependent parameters
- * and to handle them separately is for efficiency, so that type expressions
+ * and to handle them separately is for efficiency, so that type expressions
* used as bounds become smaller.
- *
+ *
* @param isUpper If true, `bound` is an upper bound, else a lower bound.
*/
- private def stripParams(tp: Type, paramBuf: mutable.ListBuffer[PolyParam],
+ private def stripParams(tp: Type, paramBuf: mutable.ListBuffer[PolyParam],
isUpper: Boolean)(implicit ctx: Context): Type = tp match {
- case param: PolyParam if contains(param) =>
+ case param: PolyParam if contains(param) =>
if (!paramBuf.contains(param)) paramBuf += param
NoType
case tp: AndOrType if isUpper == tp.isAnd =>
@@ -268,17 +268,17 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
else tp2
case _ =>
tp
- }
-
+ }
+
/** The bound type `tp` without clearly dependent parameters.
* A top or bottom type if type consists only of dependent parameters.
* @param isUpper If true, `bound` is an upper bound, else a lower bound.
*/
- private def normalizedType(tp: Type, paramBuf: mutable.ListBuffer[PolyParam],
- isUpper: Boolean)(implicit ctx: Context): Type =
+ private def normalizedType(tp: Type, paramBuf: mutable.ListBuffer[PolyParam],
+ isUpper: Boolean)(implicit ctx: Context): Type =
stripParams(tp, paramBuf, isUpper)
.orElse(if (isUpper) defn.AnyType else defn.NothingType)
-
+
def add(poly: PolyType, tvars: List[TypeVar])(implicit ctx: Context): This = {
assert(!contains(poly))
val nparams = poly.paramNames.length
@@ -287,7 +287,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
tvars.copyToArray(entries1, nparams)
newConstraint(boundsMap.updated(poly, entries1), lowerMap, upperMap).init(poly)
}
-
+
/** Split dependent parameters off the bounds for parameters in `poly`.
* Update all bounds to be normalized and update ordering to account for
* dependent parameters.
@@ -311,9 +311,9 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
if (Config.checkConstraintsNonCyclic) checkNonCyclic()
current
}
-
+
// ---------- Updates ------------------------------------------------------------
-
+
/** Add the fact `param1 <: param2` to the constraint `current` and propagate
* `<:<` relationships between parameters ("edges") but not bounds.
*/
@@ -331,31 +331,31 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
def addLess(param1: PolyParam, param2: PolyParam)(implicit ctx: Context): This =
order(this, param1, param2)
-
+
def updateEntry(current: This, param: PolyParam, tp: Type)(implicit ctx: Context): This = {
var current1 = boundsLens.update(this, current, param, tp)
tp match {
case TypeBounds(lo, hi) =>
- for (p <- dependentParams(lo, isUpper = false))
+ for (p <- dependentParams(lo, isUpper = false))
current1 = order(current1, p, param)
- for (p <- dependentParams(hi, isUpper = true))
+ for (p <- dependentParams(hi, isUpper = true))
current1 = order(current1, param, p)
case _ =>
}
current1
}
-
+
def updateEntry(param: PolyParam, tp: Type)(implicit ctx: Context): This =
updateEntry(this, param, tp)
-
+
def unify(p1: PolyParam, p2: PolyParam)(implicit ctx: Context): This = {
val p1Bounds = (nonParamBounds(p1) & nonParamBounds(p2)).substParam(p2, p1)
updateEntry(p1, p1Bounds).replace(p2, p1)
}
-
+
def narrowBound(param: PolyParam, bound: Type, isUpper: Boolean)(implicit ctx: Context): This = {
- val oldBounds @ TypeBounds(lo, hi) = nonParamBounds(param)
- val newBounds =
+ val oldBounds @ TypeBounds(lo, hi) = nonParamBounds(param)
+ val newBounds =
if (isUpper) oldBounds.derivedTypeBounds(lo, hi & bound)
else oldBounds.derivedTypeBounds(lo | bound, hi)
updateEntry(param, newBounds)
@@ -368,40 +368,40 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
* of the parameter elsewhere in the constraint by type `tp`, or a conservative
* approximation of it if that is needed to avoid cycles.
* Occurrences nested inside a refinement or prefix are not affected.
- *
+ *
* The reason we need to substitute top-level occurrences of the parameter
* is to deal with situations like the following. Say we have in the constraint
- *
+ *
* P <: Q & String
* Q
- *
+ *
* and we replace Q with P. Then substitution gives
- *
+ *
* P <: P & String
- *
+ *
* this would be a cyclic constraint is therefore changed by `normalize` and
* `recombine` below to
- *
+ *
* P <: String
- *
- * approximating the RHS occurrence of P with Any. Without the substitution we
+ *
+ * approximating the RHS occurrence of P with Any. Without the substitution we
* would not find out where we need to approximate. Occurrences of parameters
* that are not top-level are not affected.
*/
def replace(param: PolyParam, tp: Type)(implicit ctx: Context): OrderingConstraint = {
val replacement = tp.dealias.stripTypeVar
- if (param == replacement) this
+ if (param == replacement) this
else {
assert(replacement.isValueType)
val poly = param.binder
val idx = param.paramNum
-
- def removeParam(ps: List[PolyParam]) =
+
+ def removeParam(ps: List[PolyParam]) =
ps.filterNot(p => p.binder.eq(poly) && p.paramNum == idx)
-
+
def replaceParam(tp: Type, atPoly: PolyType, atIdx: Int) = tp match {
case bounds @ TypeBounds(lo, hi) =>
-
+
def recombine(andor: AndOrType, op: (Type, Boolean) => Type, isUpper: Boolean): Type = {
val tp1 = op(andor.tp1, isUpper)
val tp2 = op(andor.tp2, isUpper)
@@ -409,7 +409,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
else if (andor.isAnd) tp1 & tp2
else tp1 | tp2
}
-
+
def normalize(tp: Type, isUpper: Boolean): Type = tp match {
case p: PolyParam if p.binder == atPoly && p.paramNum == atIdx =>
if (isUpper) defn.AnyType else defn.NothingType
@@ -422,12 +422,12 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
case tp: AndOrType if isUpper == tp.isAnd => recombine(tp, replaceIn, isUpper)
case _ => tp
}
-
+
bounds.derivedTypeBounds(replaceIn(lo, isUpper = false), replaceIn(hi, isUpper = true))
case _ => tp
}
-
- var current =
+
+ var current =
if (isRemovable(poly, idx)) remove(poly) else updateEntry(param, replacement)
current.foreachParam {(p, i) =>
current = boundsLens.map(this, current, p, i, replaceParam(_, p, i))
@@ -438,7 +438,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
}
}
- def remove(pt: PolyType)(implicit ctx: Context): This =
+ def remove(pt: PolyType)(implicit ctx: Context): This =
newConstraint(boundsMap.remove(pt), lowerMap.remove(pt), upperMap.remove(pt))
def isRemovable(pt: PolyType, removedParam: Int = -1): Boolean = {
@@ -461,7 +461,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
def domainPolys: List[PolyType] = boundsMap.keys
- def domainParams: List[PolyParam] =
+ def domainParams: List[PolyParam] =
for {
(poly, entries) <- boundsMap.toList
n <- 0 until paramCount(entries)
@@ -475,7 +475,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
}
true
}
-
+
def foreachParam(p: (PolyType, Int) => Unit): Unit =
boundsMap.foreachBinding { (poly, entries) =>
0.until(poly.paramNames.length).foreach(p(poly, _))
@@ -513,17 +513,17 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
def checkNonCyclic()(implicit ctx: Context): Unit =
domainParams.foreach(checkNonCyclic)
-
+
private def checkNonCyclic(param: PolyParam)(implicit ctx: Context): Unit =
assert(!isLess(param, param), i"cyclic constraint involving $param in $this")
-
+
// ---------- toText -----------------------------------------------------
override def toText(printer: Printer): Text = {
def entryText(tp: Type) = tp match {
- case tp: TypeBounds =>
+ case tp: TypeBounds =>
tp.toText(printer)
- case _ =>
+ case _ =>
" := " ~ tp.toText(printer)
}
val indent = 3
@@ -547,7 +547,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
ups = minUpper(param)
if ups.nonEmpty
}
- yield
+ yield
(" " * indent) ~ param.toText(printer) ~ " <: " ~
Text(ups.map(_.toText(printer)), ", ")
Text(deps, "\n")