From 70b3b90d686f3444e6b16cbf9deedc8aed0c62e8 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 17 Mar 2017 13:30:19 +0100 Subject: Rename PolyParam --> TypeParamRef --- compiler/src/dotty/tools/dotc/config/Config.scala | 2 +- compiler/src/dotty/tools/dotc/core/Constants.scala | 2 +- .../src/dotty/tools/dotc/core/Constraint.scala | 42 +++++----- .../dotty/tools/dotc/core/ConstraintHandling.scala | 36 ++++---- .../src/dotty/tools/dotc/core/Definitions.scala | 6 +- compiler/src/dotty/tools/dotc/core/Mode.scala | 2 +- .../dotty/tools/dotc/core/OrderingConstraint.scala | 98 +++++++++++----------- .../dotty/tools/dotc/core/TypeApplications.scala | 8 +- .../src/dotty/tools/dotc/core/TypeComparer.scala | 32 +++---- .../src/dotty/tools/dotc/core/TypeErasure.scala | 6 +- compiler/src/dotty/tools/dotc/core/TypeOps.scala | 2 +- .../src/dotty/tools/dotc/core/TyperState.scala | 2 +- compiler/src/dotty/tools/dotc/core/Types.scala | 33 +++----- .../dotty/tools/dotc/core/tasty/TreePickler.scala | 2 +- .../tools/dotc/core/tasty/TreeUnpickler.scala | 2 +- .../src/dotty/tools/dotc/printing/Formatting.scala | 10 +-- .../dotty/tools/dotc/printing/PlainPrinter.scala | 10 +-- .../dotty/tools/dotc/printing/RefinedPrinter.scala | 2 +- .../dotty/tools/dotc/sbt/ExtractDependencies.scala | 2 +- .../dotc/transform/FullParameterization.scala | 2 +- .../dotty/tools/dotc/transform/TreeChecker.scala | 2 +- .../src/dotty/tools/dotc/typer/Applications.scala | 2 +- .../dotty/tools/dotc/typer/ErrorReporting.scala | 4 +- .../src/dotty/tools/dotc/typer/Inferencing.scala | 2 +- compiler/src/dotty/tools/dotc/typer/Inliner.scala | 2 +- .../src/dotty/tools/dotc/typer/ProtoTypes.scala | 20 ++--- .../src/dotty/tools/dotc/typer/TypeAssigner.scala | 4 +- compiler/src/dotty/tools/dotc/typer/Typer.scala | 2 +- 28 files changed, 166 insertions(+), 173 deletions(-) (limited to 'compiler/src/dotty/tools') diff --git a/compiler/src/dotty/tools/dotc/config/Config.scala b/compiler/src/dotty/tools/dotc/config/Config.scala index 903efd794..46b1896f1 100644 --- a/compiler/src/dotty/tools/dotc/config/Config.scala +++ b/compiler/src/dotty/tools/dotc/config/Config.scala @@ -40,7 +40,7 @@ object Config { * accesses javac's settings.) * * It is recommended to turn this option on only when chasing down - * a PolyParam instantiation error. See comment in Types.TypeVar.instantiate. + * a TypeParamRef instantiation error. See comment in Types.TypeVar.instantiate. */ final val debugCheckConstraintsClosed = false diff --git a/compiler/src/dotty/tools/dotc/core/Constants.scala b/compiler/src/dotty/tools/dotc/core/Constants.scala index e8b27c0ba..ed388b7ec 100644 --- a/compiler/src/dotty/tools/dotc/core/Constants.scala +++ b/compiler/src/dotty/tools/dotc/core/Constants.scala @@ -169,7 +169,7 @@ object Constants { def convertTo(pt: Type)(implicit ctx: Context): Constant = { def classBound(pt: Type): Type = pt.dealias.stripTypeVar match { case tref: TypeRef if !tref.symbol.isClass => classBound(tref.info.bounds.lo) - case param: PolyParam => + case param: TypeParamRef => ctx.typerState.constraint.entry(param) match { case TypeBounds(lo, hi) => if (hi.classSymbol.isPrimitiveValueClass) hi //constrain further with high bound diff --git a/compiler/src/dotty/tools/dotc/core/Constraint.scala b/compiler/src/dotty/tools/dotc/core/Constraint.scala index 50136a26c..fe14aa53c 100644 --- a/compiler/src/dotty/tools/dotc/core/Constraint.scala +++ b/compiler/src/dotty/tools/dotc/core/Constraint.scala @@ -14,9 +14,9 @@ import config.Printers.constr * over values of the following types: * * - PolyType A constraint constrains the type parameters of a set of PolyTypes - * - PolyParam The parameters of the constrained polytypes + * - TypeParamRef The parameters of the constrained polytypes * - TypeVar Every constrained parameter might be associated with a TypeVar - * that has the PolyParam as origin. + * that has the TypeParamRef as origin. */ abstract class Constraint extends Showable { @@ -26,7 +26,7 @@ abstract class Constraint extends Showable { def contains(pt: PolyType): Boolean /** Does the constraint's domain contain the type parameter `param`? */ - def contains(param: PolyParam): Boolean + def contains(param: TypeParamRef): Boolean /** Does this constraint contain the type variable `tvar` and is it uninstantiated? */ def contains(tvar: TypeVar): Boolean @@ -34,43 +34,43 @@ abstract class Constraint extends Showable { /** The constraint entry for given type parameter `param`, or NoType if `param` is not part of * the constraint domain. Note: Low level, implementation dependent. */ - def entry(param: PolyParam): Type + def entry(param: TypeParamRef): Type /** The type variable corresponding to parameter `param`, or * NoType, if `param` is not in constrained or is not paired with a type variable. */ - def typeVarOfParam(param: PolyParam): Type + def typeVarOfParam(param: TypeParamRef): Type /** Is it known that `param1 <:< param2`? */ - def isLess(param1: PolyParam, param2: PolyParam): Boolean + def isLess(param1: TypeParamRef, param2: TypeParamRef): Boolean /** The parameters that are known to be smaller wrt <: than `param` */ - def lower(param: PolyParam): List[PolyParam] + def lower(param: TypeParamRef): List[TypeParamRef] /** The parameters that are known to be greater wrt <: than `param` */ - def upper(param: PolyParam): List[PolyParam] + def upper(param: TypeParamRef): List[TypeParamRef] /** lower(param) \ lower(butNot) */ - def exclusiveLower(param: PolyParam, butNot: PolyParam): List[PolyParam] + def exclusiveLower(param: TypeParamRef, butNot: TypeParamRef): List[TypeParamRef] /** upper(param) \ upper(butNot) */ - def exclusiveUpper(param: PolyParam, butNot: PolyParam): List[PolyParam] + def exclusiveUpper(param: TypeParamRef, butNot: TypeParamRef): List[TypeParamRef] /** The constraint bounds for given type parameter `param`. * Poly params that are known to be smaller or greater than `param` * are not contained in the return bounds. * @pre `param` is not part of the constraint domain. */ - def nonParamBounds(param: PolyParam): TypeBounds + def nonParamBounds(param: TypeParamRef): TypeBounds /** The lower bound of `param` including all known-to-be-smaller parameters */ - def fullLowerBound(param: PolyParam)(implicit ctx: Context): Type + def fullLowerBound(param: TypeParamRef)(implicit ctx: Context): Type /** The upper bound of `param` including all known-to-be-greater parameters */ - def fullUpperBound(param: PolyParam)(implicit ctx: Context): Type + def fullUpperBound(param: TypeParamRef)(implicit ctx: Context): Type /** The bounds of `param` including all known-to-be-smaller and -greater parameters */ - def fullBounds(param: PolyParam)(implicit ctx: Context): TypeBounds + def fullBounds(param: TypeParamRef)(implicit ctx: Context): TypeBounds /** A new constraint which is derived from this constraint by adding * entries for all type parameters of `poly`. @@ -90,18 +90,18 @@ abstract class Constraint extends Showable { * * @pre `this contains param`. */ - def updateEntry(param: PolyParam, tp: Type)(implicit ctx: Context): This + def updateEntry(param: TypeParamRef, tp: Type)(implicit ctx: Context): This /** A constraint that includes the relationship `p1 <: p2`. * `<:` relationships between parameters ("edges") are propagated, but * non-parameter bounds are left alone. */ - def addLess(p1: PolyParam, p2: PolyParam)(implicit ctx: Context): This + def addLess(p1: TypeParamRef, p2: TypeParamRef)(implicit ctx: Context): This /** A constraint resulting from adding p2 = p1 to this constraint, and at the same * time transferring all bounds of p2 to p1 */ - def unify(p1: PolyParam, p2: PolyParam)(implicit ctx: Context): This + def unify(p1: TypeParamRef, p2: TypeParamRef)(implicit ctx: Context): This /** A new constraint which is derived from this constraint by removing * the type parameter `param` from the domain and replacing all top-level occurrences @@ -109,7 +109,7 @@ abstract class Constraint extends Showable { * approximation of it if that is needed to avoid cycles. * Occurrences nested inside a refinement or prefix are not affected. */ - def replace(param: PolyParam, tp: Type)(implicit ctx: Context): This + def replace(param: TypeParamRef, tp: Type)(implicit ctx: Context): This /** Is entry associated with `pt` removable? This is the case if * all type parameters of the entry are associated with type variables @@ -124,10 +124,10 @@ abstract class Constraint extends Showable { def domainPolys: List[PolyType] /** The polytype parameters constrained by this constraint */ - def domainParams: List[PolyParam] + def domainParams: List[TypeParamRef] /** Check whether predicate holds for all parameters in constraint */ - def forallParams(p: PolyParam => Boolean): Boolean + def forallParams(p: TypeParamRef => Boolean): Boolean /** Perform operation `op` on all typevars, or only on uninstantiated * typevars, depending on whether `uninstOnly` is set or not. @@ -143,6 +143,6 @@ abstract class Constraint extends Showable { /** Check that no constrained parameter contains itself as a bound */ def checkNonCyclic()(implicit ctx: Context): Unit - /** Check that constraint only refers to PolyParams bound by itself */ + /** Check that constraint only refers to TypeParamRefs bound by itself */ def checkClosed()(implicit ctx: Context): Unit } diff --git a/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala b/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala index 34662cbff..ab176b632 100644 --- a/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala +++ b/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala @@ -47,7 +47,7 @@ trait ConstraintHandling { */ protected var comparedPolyTypes: Set[PolyType] = Set.empty - private def addOneBound(param: PolyParam, bound: Type, isUpper: Boolean): Boolean = + private def addOneBound(param: TypeParamRef, bound: Type, isUpper: Boolean): Boolean = !constraint.contains(param) || { def occursIn(bound: Type): Boolean = { val b = bound.dealias @@ -75,7 +75,7 @@ trait ConstraintHandling { * If `isUpper` is true, ensure that `param <: `bound`, otherwise ensure * that `param >: bound`. */ - def narrowedBound(param: PolyParam, bound: Type, isUpper: Boolean)(implicit ctx: Context): TypeBounds = { + def narrowedBound(param: TypeParamRef, bound: Type, isUpper: Boolean)(implicit ctx: Context): TypeBounds = { val oldBounds @ TypeBounds(lo, hi) = constraint.nonParamBounds(param) val saved = homogenizeArgs homogenizeArgs = Config.alignArgsInAnd @@ -85,7 +85,7 @@ trait ConstraintHandling { finally homogenizeArgs = saved } - protected def addUpperBound(param: PolyParam, bound: Type): Boolean = { + protected def addUpperBound(param: TypeParamRef, bound: Type): Boolean = { def description = i"constraint $param <: $bound to\n$constraint" if (bound.isRef(defn.NothingClass) && ctx.typerState.isGlobalCommittable) { def msg = s"!!! instantiated to Nothing: $param, constraint = ${constraint.show}" @@ -101,7 +101,7 @@ trait ConstraintHandling { res } - protected def addLowerBound(param: PolyParam, bound: Type): Boolean = { + protected def addLowerBound(param: TypeParamRef, bound: Type): Boolean = { def description = i"constraint $param >: $bound to\n$constraint" constr.println(i"adding $description") val upper = constraint.upper(param) @@ -112,7 +112,7 @@ trait ConstraintHandling { res } - protected def addLess(p1: PolyParam, p2: PolyParam): Boolean = { + protected def addLess(p1: TypeParamRef, p2: TypeParamRef): Boolean = { def description = i"ordering $p1 <: $p2 to\n$constraint" val res = if (constraint.isLess(p2, p1)) unify(p2, p1) @@ -133,7 +133,7 @@ trait ConstraintHandling { /** Make p2 = p1, transfer all bounds of p2 to p1 * @pre less(p1)(p2) */ - private def unify(p1: PolyParam, p2: PolyParam): Boolean = { + private def unify(p1: TypeParamRef, p2: TypeParamRef): Boolean = { constr.println(s"unifying $p1 $p2") assert(constraint.isLess(p1, p2)) val down = constraint.exclusiveLower(p2, p1) @@ -191,7 +191,7 @@ trait ConstraintHandling { * @return the instantiating type * @pre `param` is in the constraint's domain. */ - final def approximation(param: PolyParam, fromBelow: Boolean): Type = { + final def approximation(param: TypeParamRef, fromBelow: Boolean): Type = { val avoidParam = new TypeMap { override def stopAtStatic = true def apply(tp: Type) = mapOver { @@ -235,7 +235,7 @@ trait ConstraintHandling { * a lower bound instantiation can be a singleton type only if the upper bound * is also a singleton type. */ - def instanceType(param: PolyParam, fromBelow: Boolean): Type = { + def instanceType(param: TypeParamRef, fromBelow: Boolean): Type = { def upperBound = constraint.fullUpperBound(param) def isSingleton(tp: Type): Boolean = tp match { case tp: SingletonType => true @@ -301,7 +301,7 @@ trait ConstraintHandling { } /** The current bounds of type parameter `param` */ - final def bounds(param: PolyParam): TypeBounds = { + final def bounds(param: TypeParamRef): TypeBounds = { val e = constraint.entry(param) if (e.exists) e.bounds else param.binder.paramInfos(param.paramNum) } @@ -315,7 +315,7 @@ trait ConstraintHandling { checkPropagated(i"initialized $pt") { constraint = constraint.add(pt, tvars) pt.paramNames.indices.forall { i => - val param = PolyParam(pt, i) + val param = TypeParamRef(pt, i) val bounds = constraint.nonParamBounds(param) val lower = constraint.lower(param) val upper = constraint.upper(param) @@ -328,7 +328,7 @@ trait ConstraintHandling { } /** Can `param` be constrained with new bounds? */ - final def canConstrain(param: PolyParam): Boolean = + final def canConstrain(param: TypeParamRef): Boolean = !frozenConstraint && (constraint contains param) /** Add constraint `param <: bound` if `fromBelow` is false, `param >: bound` otherwise. @@ -338,7 +338,7 @@ trait ConstraintHandling { * not be AndTypes and lower bounds may not be OrTypes. This is assured by the * way isSubType is organized. */ - protected def addConstraint(param: PolyParam, bound: Type, fromBelow: Boolean): Boolean = { + protected def addConstraint(param: TypeParamRef, bound: Type, fromBelow: Boolean): Boolean = { def description = i"constr $param ${if (fromBelow) ">:" else "<:"} $bound:\n$constraint" //checkPropagated(s"adding $description")(true) // DEBUG in case following fails checkPropagated(s"added $description") { @@ -360,7 +360,7 @@ trait ConstraintHandling { if (comparedPolyTypes.nonEmpty) { val approx = new ApproximatingTypeMap { def apply(t: Type): Type = t match { - case t @ PolyParam(pt: PolyType, n) if comparedPolyTypes contains pt => + case t @ TypeParamRef(pt: PolyType, n) if comparedPolyTypes contains pt => val effectiveVariance = if (fromBelow) -variance else variance val bounds = pt.paramInfos(n) if (effectiveVariance > 0) bounds.lo @@ -374,7 +374,7 @@ trait ConstraintHandling { } else tp - def addParamBound(bound: PolyParam) = + def addParamBound(bound: TypeParamRef) = if (fromBelow) addLess(bound, param) else addLess(param, bound) /** Drop all constrained parameters that occur at the toplevel in `bound` and @@ -419,7 +419,7 @@ trait ConstraintHandling { else NoType case bound: TypeVar if constraint contains bound.origin => prune(bound.underlying) - case bound: PolyParam => + case bound: TypeParamRef => constraint.entry(bound) match { case NoType => pruneLambdaParams(bound) case _: TypeBounds => @@ -434,7 +434,7 @@ trait ConstraintHandling { } try bound match { - case bound: PolyParam if constraint contains bound => + case bound: TypeParamRef if constraint contains bound => addParamBound(bound) case _ => val pbound = prune(bound) @@ -446,7 +446,7 @@ trait ConstraintHandling { } /** Instantiate `param` to `tp` if the constraint stays satisfiable */ - protected def tryInstantiate(param: PolyParam, tp: Type): Boolean = { + protected def tryInstantiate(param: TypeParamRef, tp: Type): Boolean = { val saved = constraint constraint = if (addConstraint(param, tp, fromBelow = true) && @@ -461,7 +461,7 @@ trait ConstraintHandling { val saved = frozenConstraint frozenConstraint = true for (p <- constraint.domainParams) { - def check(cond: => Boolean, q: PolyParam, ordering: String, explanation: String): Unit = + def check(cond: => Boolean, q: TypeParamRef, ordering: String, explanation: String): Unit = assert(cond, i"propagation failure for $p $ordering $q: $explanation\n$msg") for (u <- constraint.upper(p)) check(bounds(p).hi <:< bounds(u).hi, u, "<:", "upper bound not propagated") diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index 0c1d6521d..9360cabb1 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -242,7 +242,7 @@ class Definitions { lazy val Any_## = enterMethod(AnyClass, nme.HASHHASH, ExprType(IntType), Final) lazy val Any_getClass = enterMethod(AnyClass, nme.getClass_, MethodType(Nil, ClassClass.typeRef.appliedTo(TypeBounds.empty)), Final) lazy val Any_isInstanceOf = enterT1ParameterlessMethod(AnyClass, nme.isInstanceOf_, _ => BooleanType, Final) - lazy val Any_asInstanceOf = enterT1ParameterlessMethod(AnyClass, nme.asInstanceOf_, PolyParam(_, 0), Final) + lazy val Any_asInstanceOf = enterT1ParameterlessMethod(AnyClass, nme.asInstanceOf_, TypeParamRef(_, 0), Final) def AnyMethods = List(Any_==, Any_!=, Any_equals, Any_hashCode, Any_toString, Any_##, Any_getClass, Any_isInstanceOf, Any_asInstanceOf) @@ -268,7 +268,7 @@ class Definitions { lazy val Object_eq = enterMethod(ObjectClass, nme.eq, methOfAnyRef(BooleanType), Final) lazy val Object_ne = enterMethod(ObjectClass, nme.ne, methOfAnyRef(BooleanType), Final) lazy val Object_synchronized = enterPolyMethod(ObjectClass, nme.synchronized_, 1, - pt => MethodType(List(PolyParam(pt, 0)), PolyParam(pt, 0)), Final) + pt => MethodType(List(TypeParamRef(pt, 0)), TypeParamRef(pt, 0)), Final) lazy val Object_clone = enterMethod(ObjectClass, nme.clone_, MethodType(Nil, ObjectType), Protected) lazy val Object_finalize = enterMethod(ObjectClass, nme.finalize_, MethodType(Nil, UnitType), Protected) lazy val Object_notify = enterMethod(ObjectClass, nme.notify_, MethodType(Nil, UnitType)) @@ -283,7 +283,7 @@ class Definitions { /** Dummy method needed by elimByName */ lazy val dummyApply = enterPolyMethod( OpsPackageClass, nme.dummyApply, 1, - pt => MethodType(List(FunctionOf(Nil, PolyParam(pt, 0))), PolyParam(pt, 0))) + pt => MethodType(List(FunctionOf(Nil, TypeParamRef(pt, 0))), TypeParamRef(pt, 0))) /** Method representing a throw */ lazy val throwMethod = enterMethod(OpsPackageClass, nme.THROWkw, diff --git a/compiler/src/dotty/tools/dotc/core/Mode.scala b/compiler/src/dotty/tools/dotc/core/Mode.scala index 406a84af6..c835f677e 100644 --- a/compiler/src/dotty/tools/dotc/core/Mode.scala +++ b/compiler/src/dotty/tools/dotc/core/Mode.scala @@ -34,7 +34,7 @@ object Mode { * context with typerstate and constraint. This is typically done when we * cache the eligibility of implicits. Caching needs to be done across different constraints. * Therefore, if TypevarsMissContext is set, subtyping becomes looser, and assumes - * that PolyParams can be sub- and supertypes of anything. See TypeComparer. + * that TypeParamRefs can be sub- and supertypes of anything. See TypeComparer. */ val TypevarsMissContext = newMode(4, "TypevarsMissContext") val CheckCyclic = newMode(5, "CheckCyclic") diff --git a/compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala b/compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala index 3387f20e3..dbb952369 100644 --- a/compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala +++ b/compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala @@ -20,7 +20,7 @@ object OrderingConstraint { type ParamBounds = ArrayValuedMap[Type] /** The type of `OrderingConstraint#lowerMap`, `OrderingConstraint#upperMap` */ - type ParamOrdering = ArrayValuedMap[List[PolyParam]] + type ParamOrdering = ArrayValuedMap[List[TypeParamRef]] /** A new constraint with given maps */ private def newConstraint(boundsMap: ParamBounds, lowerMap: ParamOrdering, upperMap: ParamOrdering)(implicit ctx: Context) : OrderingConstraint = { @@ -68,7 +68,7 @@ object OrderingConstraint { } def update(prev: OrderingConstraint, current: OrderingConstraint, - param: PolyParam, entry: T)(implicit ctx: Context): OrderingConstraint = + param: TypeParamRef, entry: T)(implicit ctx: Context): OrderingConstraint = update(prev, current, param.binder, param.paramNum, entry) def map(prev: OrderingConstraint, current: OrderingConstraint, @@ -76,7 +76,7 @@ object 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 = + param: TypeParamRef, f: T => T)(implicit ctx: Context): OrderingConstraint = map(prev, current, param.binder, param.paramNum, f) } @@ -88,18 +88,18 @@ object OrderingConstraint { def initial = NoType } - val lowerLens = new ConstraintLens[List[PolyParam]] { - def entries(c: OrderingConstraint, poly: PolyType): Array[List[PolyParam]] = + val lowerLens = new ConstraintLens[List[TypeParamRef]] { + def entries(c: OrderingConstraint, poly: PolyType): Array[List[TypeParamRef]] = 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[TypeParamRef]])(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]] = + val upperLens = new ConstraintLens[List[TypeParamRef]] { + def entries(c: OrderingConstraint, poly: PolyType): Array[List[TypeParamRef]] = 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[TypeParamRef]])(implicit ctx: Context): OrderingConstraint = newConstraint(c.boundsMap, c.lowerMap, c.upperMap.updated(poly, entries)) def initial = Nil } @@ -141,7 +141,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds, entries(paramCount(entries) + n) /** The `boundsMap` entry corresponding to `param` */ - def entry(param: PolyParam): Type = { + def entry(param: TypeParamRef): Type = { val entries = boundsMap(param.binder) if (entries == null) NoType else entries(param.paramNum) @@ -151,7 +151,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds, def contains(pt: PolyType): Boolean = boundsMap(pt) != null - def contains(param: PolyParam): Boolean = { + def contains(param: TypeParamRef): Boolean = { val entries = boundsMap(param.binder) entries != null && isBounds(entries(param.paramNum)) } @@ -167,43 +167,43 @@ class OrderingConstraint(private val boundsMap: ParamBounds, // ---------- 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 lower(param: TypeParamRef): List[TypeParamRef] = lowerLens(this, param.binder, param.paramNum) + def upper(param: TypeParamRef): List[TypeParamRef] = upperLens(this, param.binder, param.paramNum) - def minLower(param: PolyParam): List[PolyParam] = { + def minLower(param: TypeParamRef): List[TypeParamRef] = { val all = lower(param) all.filterNot(p => all.exists(isLess(p, _))) } - def minUpper(param: PolyParam): List[PolyParam] = { + def minUpper(param: TypeParamRef): List[TypeParamRef] = { val all = upper(param) all.filterNot(p => all.exists(isLess(_, p))) } - def exclusiveLower(param: PolyParam, butNot: PolyParam): List[PolyParam] = + def exclusiveLower(param: TypeParamRef, butNot: TypeParamRef): List[TypeParamRef] = lower(param).filterNot(isLess(_, butNot)) - def exclusiveUpper(param: PolyParam, butNot: PolyParam): List[PolyParam] = + def exclusiveUpper(param: TypeParamRef, butNot: TypeParamRef): List[TypeParamRef] = upper(param).filterNot(isLess(butNot, _)) -// ---------- Info related to PolyParams ------------------------------------------- +// ---------- Info related to TypeParamRefs ------------------------------------------- - def isLess(param1: PolyParam, param2: PolyParam): Boolean = + def isLess(param1: TypeParamRef, param2: TypeParamRef): Boolean = upper(param1).contains(param2) - def nonParamBounds(param: PolyParam): TypeBounds = + def nonParamBounds(param: TypeParamRef): TypeBounds = entry(param).asInstanceOf[TypeBounds] - def fullLowerBound(param: PolyParam)(implicit ctx: Context): Type = + def fullLowerBound(param: TypeParamRef)(implicit ctx: Context): Type = (nonParamBounds(param).lo /: minLower(param))(_ | _) - def fullUpperBound(param: PolyParam)(implicit ctx: Context): Type = + def fullUpperBound(param: TypeParamRef)(implicit ctx: Context): Type = (nonParamBounds(param).hi /: minUpper(param))(_ & _) - def fullBounds(param: PolyParam)(implicit ctx: Context): TypeBounds = + def fullBounds(param: TypeParamRef)(implicit ctx: Context): TypeBounds = nonParamBounds(param).derivedTypeBounds(fullLowerBound(param), fullUpperBound(param)) - def typeVarOfParam(param: PolyParam): Type = { + def typeVarOfParam(param: TypeParamRef): Type = { val entries = boundsMap(param.binder) if (entries == null) NoType else { @@ -219,8 +219,8 @@ class OrderingConstraint(private val boundsMap: ParamBounds, * 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) => + def dependentParams(tp: Type, isUpper: Boolean): List[TypeParamRef] = tp match { + case param: TypeParamRef if contains(param) => param :: (if (isUpper) upper(param) else lower(param)) case tp: AndOrType => val ps1 = dependentParams(tp.tp1, isUpper) @@ -255,9 +255,9 @@ class OrderingConstraint(private val boundsMap: ParamBounds, * * @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[TypeParamRef], isUpper: Boolean)(implicit ctx: Context): Type = tp match { - case param: PolyParam if contains(param) => + case param: TypeParamRef if contains(param) => if (!paramBuf.contains(param)) paramBuf += param NoType case tp: AndOrType if isUpper == tp.isAnd => @@ -275,7 +275,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds, * 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], + private def normalizedType(tp: Type, paramBuf: mutable.ListBuffer[TypeParamRef], isUpper: Boolean)(implicit ctx: Context): Type = stripParams(tp, paramBuf, isUpper) .orElse(if (isUpper) defn.AnyType else defn.NothingType) @@ -295,10 +295,10 @@ class OrderingConstraint(private val boundsMap: ParamBounds, */ private def init(poly: PolyType)(implicit ctx: Context): This = { var current = this - val loBuf, hiBuf = new mutable.ListBuffer[PolyParam] + val loBuf, hiBuf = new mutable.ListBuffer[TypeParamRef] var i = 0 while (i < poly.paramNames.length) { - val param = PolyParam(poly, i) + val param = TypeParamRef(poly, i) val bounds = nonParamBounds(param) val lo = normalizedType(bounds.lo, loBuf, isUpper = false) val hi = normalizedType(bounds.hi, hiBuf, isUpper = true) @@ -318,7 +318,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds, /** Add the fact `param1 <: param2` to the constraint `current` and propagate * `<:<` relationships between parameters ("edges") but not bounds. */ - private def order(current: This, param1: PolyParam, param2: PolyParam)(implicit ctx: Context): This = + private def order(current: This, param1: TypeParamRef, param2: TypeParamRef)(implicit ctx: Context): This = if (param1 == param2 || current.isLess(param1, param2)) this else { assert(contains(param1)) @@ -330,10 +330,10 @@ class OrderingConstraint(private val boundsMap: ParamBounds, current2 } - def addLess(param1: PolyParam, param2: PolyParam)(implicit ctx: Context): This = + def addLess(param1: TypeParamRef, param2: TypeParamRef)(implicit ctx: Context): This = order(this, param1, param2) - def updateEntry(current: This, param: PolyParam, tp: Type)(implicit ctx: Context): This = { + def updateEntry(current: This, param: TypeParamRef, tp: Type)(implicit ctx: Context): This = { var current1 = boundsLens.update(this, current, param, tp) tp match { case TypeBounds(lo, hi) => @@ -346,10 +346,10 @@ class OrderingConstraint(private val boundsMap: ParamBounds, current1 } - def updateEntry(param: PolyParam, tp: Type)(implicit ctx: Context): This = + def updateEntry(param: TypeParamRef, tp: Type)(implicit ctx: Context): This = updateEntry(this, param, tp) - def unify(p1: PolyParam, p2: PolyParam)(implicit ctx: Context): This = { + def unify(p1: TypeParamRef, p2: TypeParamRef)(implicit ctx: Context): This = { val p1Bounds = (nonParamBounds(p1) & nonParamBounds(p2)).substParam(p2, p1) updateEntry(p1, p1Bounds).replace(p2, p1) } @@ -381,7 +381,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds, * 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 = { + def replace(param: TypeParamRef, tp: Type)(implicit ctx: Context): OrderingConstraint = { val replacement = tp.dealias.stripTypeVar if (param == replacement) this else { @@ -389,7 +389,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds, val poly = param.binder val idx = param.paramNum - def removeParam(ps: List[PolyParam]) = + def removeParam(ps: List[TypeParamRef]) = ps.filterNot(p => p.binder.eq(poly) && p.paramNum == idx) def replaceParam(tp: Type, atPoly: PolyType, atIdx: Int): Type = tp match { @@ -404,7 +404,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds, } def normalize(tp: Type, isUpper: Boolean): Type = tp match { - case p: PolyParam if p.binder == atPoly && p.paramNum == atIdx => + case p: TypeParamRef if p.binder == atPoly && p.paramNum == atIdx => if (isUpper) defn.AnyType else defn.NothingType case tp: AndOrType if isUpper == tp.isAnd => recombine(tp, normalize, isUpper) case _ => tp @@ -434,7 +434,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds, def remove(pt: PolyType)(implicit ctx: Context): This = { def removeFromOrdering(po: ParamOrdering) = { - def removeFromBoundss(key: PolyType, bndss: Array[List[PolyParam]]): Array[List[PolyParam]] = { + def removeFromBoundss(key: PolyType, bndss: Array[List[TypeParamRef]]): Array[List[TypeParamRef]] = { val bndss1 = bndss.map(_.filterConserve(_.binder ne pt)) if (bndss.corresponds(bndss1)(_ eq _)) bndss else bndss1 } @@ -458,17 +458,17 @@ class OrderingConstraint(private val boundsMap: ParamBounds, def domainPolys: List[PolyType] = boundsMap.keys - def domainParams: List[PolyParam] = + def domainParams: List[TypeParamRef] = for { (poly, entries) <- boundsMap.toList n <- 0 until paramCount(entries) if entries(n).exists - } yield PolyParam(poly, n) + } yield TypeParamRef(poly, n) - def forallParams(p: PolyParam => Boolean): Boolean = { + def forallParams(p: TypeParamRef => Boolean): Boolean = { boundsMap.foreachBinding { (poly, entries) => for (i <- 0 until paramCount(entries)) - if (isBounds(entries(i)) && !p(PolyParam(poly, i))) return false + if (isBounds(entries(i)) && !p(TypeParamRef(poly, i))) return false } true } @@ -503,7 +503,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds, merged } - def mergeParams(ps1: List[PolyParam], ps2: List[PolyParam]) = + def mergeParams(ps1: List[TypeParamRef], ps2: List[TypeParamRef]) = (ps1 /: ps2)((ps1, p2) => if (ps1.contains(p2)) ps1 else p2 :: ps1) def mergeEntries(e1: Type, e2: Type): Type = e1 match { @@ -532,13 +532,13 @@ class OrderingConstraint(private val boundsMap: ParamBounds, } override def checkClosed()(implicit ctx: Context): Unit = { - def isFreePolyParam(tp: Type) = tp match { - case PolyParam(binder: PolyType, _) => !contains(binder) + def isFreeTypeParamRef(tp: Type) = tp match { + case TypeParamRef(binder: PolyType, _) => !contains(binder) case _ => false } def checkClosedType(tp: Type, where: String) = if (tp != null) - assert(!tp.existsPart(isFreePolyParam), i"unclosed constraint: $this refers to $tp in $where") + assert(!tp.existsPart(isFreeTypeParamRef), i"unclosed constraint: $this refers to $tp in $where") boundsMap.foreachBinding((_, tps) => tps.foreach(checkClosedType(_, "bounds"))) lowerMap.foreachBinding((_, paramss) => paramss.foreach(_.foreach(checkClosedType(_, "lower")))) upperMap.foreachBinding((_, paramss) => paramss.foreach(_.foreach(checkClosedType(_, "upper")))) @@ -567,7 +567,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds, def checkNonCyclic()(implicit ctx: Context): Unit = domainParams.foreach(checkNonCyclic) - private def checkNonCyclic(param: PolyParam)(implicit ctx: Context): Unit = + private def checkNonCyclic(param: TypeParamRef)(implicit ctx: Context): Unit = assert(!isLess(param, param), i"cyclic constraint involving $param in $this") // ---------- toText ----------------------------------------------------- diff --git a/compiler/src/dotty/tools/dotc/core/TypeApplications.scala b/compiler/src/dotty/tools/dotc/core/TypeApplications.scala index 931f0dc74..77767a38c 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeApplications.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeApplications.scala @@ -163,15 +163,15 @@ object TypeApplications { class Reducer(tycon: PolyType, args: List[Type])(implicit ctx: Context) extends TypeMap { private var available = (0 until args.length).toSet var allReplaced = true - def hasWildcardArg(p: PolyParam) = + def hasWildcardArg(p: TypeParamRef) = p.binder == tycon && args(p.paramNum).isInstanceOf[TypeBounds] - def canReduceWildcard(p: PolyParam) = + def canReduceWildcard(p: TypeParamRef) = !ctx.mode.is(Mode.AllowLambdaWildcardApply) || available.contains(p.paramNum) def apply(t: Type) = t match { - case t @ TypeAlias(p: PolyParam) if hasWildcardArg(p) && canReduceWildcard(p) => + case t @ TypeAlias(p: TypeParamRef) if hasWildcardArg(p) && canReduceWildcard(p) => available -= p.paramNum args(p.paramNum) - case p: PolyParam if p.binder == tycon => + case p: TypeParamRef if p.binder == tycon => args(p.paramNum) match { case TypeBounds(lo, hi) => if (ctx.mode.is(Mode.AllowLambdaWildcardApply)) { allReplaced = false; p } diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index 9f4db5edd..a4ea1d28f 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -280,7 +280,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling { case _ => } thirdTry(tp1, tp2) - case tp1: PolyParam => + case tp1: TypeParamRef => def flagNothingBound = { if (!frozenConstraint && tp2.isRef(defn.NothingClass) && state.isGlobalCommittable) { def msg = s"!!! instantiated to Nothing: $tp1, constraint = ${constraint.show}" @@ -289,13 +289,13 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling { } true } - def comparePolyParam = + def compareTypeParamRef = ctx.mode.is(Mode.TypevarsMissContext) || isSubTypeWhenFrozen(bounds(tp1).hi, tp2) || { if (canConstrain(tp1)) addConstraint(tp1, tp2, fromBelow = false) && flagNothingBound else thirdTry(tp1, tp2) } - comparePolyParam + compareTypeParamRef case tp1: ThisType => val cls1 = tp1.cls tp2 match { @@ -373,8 +373,8 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling { private def thirdTry(tp1: Type, tp2: Type): Boolean = tp2 match { case tp2: NamedType => thirdTryNamed(tp1, tp2) - case tp2: PolyParam => - def comparePolyParam = + case tp2: TypeParamRef => + def compareTypeParamRef = (ctx.mode is Mode.TypevarsMissContext) || { val alwaysTrue = // The following condition is carefully formulated to catch all cases @@ -391,7 +391,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling { else fourthTry(tp1, tp2) } } - comparePolyParam + compareTypeParamRef case tp2: RefinedType => def compareRefinedSlow: Boolean = { val name2 = tp2.refinedName @@ -618,7 +618,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling { def isMatchingApply(tp1: Type): Boolean = tp1 match { case HKApply(tycon1, args1) => tycon1.dealias match { - case tycon1: PolyParam => + case tycon1: TypeParamRef => (tycon1 == tycon2 || canConstrain(tycon1) && tryInstantiate(tycon1, tycon2)) && isSubArgs(args1, args2, tparams) @@ -646,7 +646,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling { * and the resulting type application is a supertype of `tp1`, * or fallback to fourthTry. */ - def canInstantiate(tycon2: PolyParam): Boolean = { + def canInstantiate(tycon2: TypeParamRef): Boolean = { /** Let * @@ -672,7 +672,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling { tycon1b = PolyType(tparams1.map(_.paramName))( tl => tparams1.map(tparam => tl.lifted(tparams, tparam.paramInfo).bounds), tl => tycon1a.appliedTo(args1.take(lengthDiff) ++ - tparams1.indices.toList.map(PolyParam(tl, _)))) + tparams1.indices.toList.map(TypeParamRef(tl, _)))) (ctx.mode.is(Mode.TypevarsMissContext) || tryInstantiate(tycon2, tycon1b.ensureHK)) && isSubType(tp1, tycon1b.appliedTo(args2)) @@ -725,7 +725,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling { fallback(tycon2bounds.lo) tycon2 match { - case param2: PolyParam => + case param2: TypeParamRef => isMatchingApply(tp1) || { if (canConstrain(param2)) canInstantiate(param2) else compareLower(bounds(param2), tyconIsTypeRef = false) @@ -746,7 +746,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling { */ def compareHkApply1(tp1: HKApply, tycon1: Type, args1: List[Type], tp2: Type): Boolean = tycon1 match { - case param1: PolyParam => + case param1: TypeParamRef => def canInstantiate = tp2 match { case AppliedType(tycon2, args2) => tryInstantiate(param1, tycon2.ensureHK) && isSubArgs(args1, args2, tycon2.typeParams) @@ -806,7 +806,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling { def fix(tp: Type): Type = tp.stripTypeVar match { case tp: RecType => fix(tp.parent).substRecThis(tp, anchor) case tp @ RefinedType(parent, rname, rinfo) => tp.derivedRefinedType(fix(parent), rname, rinfo) - case tp: PolyParam => fixOrElse(bounds(tp).hi, tp) + case tp: TypeParamRef => fixOrElse(bounds(tp).hi, tp) case tp: TypeProxy => fixOrElse(tp.underlying, tp) case tp: AndOrType => tp.derivedAndOrType(fix(tp.tp1), fix(tp.tp2)) case tp => tp @@ -967,7 +967,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling { /** Defer constraining type variables when compared against prototypes */ def isMatchedByProto(proto: ProtoType, tp: Type) = tp.stripTypeVar match { - case tp: PolyParam if constraint contains tp => true + case tp: TypeParamRef if constraint contains tp => true case _ => proto.isMatchedBy(tp) } @@ -978,7 +978,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling { * type variable with (the corresponding type in) `tp2` instead. */ private def isCappable(tp: Type): Boolean = tp match { - case tp: PolyParam => constraint contains tp + case tp: TypeParamRef => constraint contains tp case tp: TypeProxy => isCappable(tp.underlying) case tp: AndOrType => isCappable(tp.tp1) || isCappable(tp.tp2) case _ => false @@ -1424,7 +1424,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling { def showGoal(tp1: Type, tp2: Type)(implicit ctx: Context) = { println(ex"assertion failure for $tp1 <:< $tp2, frozen = $frozenConstraint") def explainPoly(tp: Type) = tp match { - case tp: PolyParam => ctx.echo(s"polyparam ${tp.show} found in ${tp.binder.show}") + case tp: TypeParamRef => ctx.echo(s"TypeParamRef ${tp.show} found in ${tp.binder.show}") case tp: TypeRef if tp.symbol.exists => ctx.echo(s"typeref ${tp.show} found in ${tp.symbol.owner.show}") case tp: TypeVar => ctx.echo(s"typevar ${tp.show}, origin = ${tp.origin}") case _ => ctx.echo(s"${tp.show} is a ${tp.getClass}") @@ -1503,7 +1503,7 @@ class ExplainingTypeComparer(initctx: Context) extends TypeComparer(initctx) { super.glb(tp1, tp2) } - override def addConstraint(param: PolyParam, bound: Type, fromBelow: Boolean): Boolean = + override def addConstraint(param: TypeParamRef, bound: Type, fromBelow: Boolean): Boolean = traceIndented(i"add constraint $param ${if (fromBelow) ">:" else "<:"} $bound $frozenConstraint, constraint = ${ctx.typerState.constraint}") { super.addConstraint(param, bound, fromBelow) } diff --git a/compiler/src/dotty/tools/dotc/core/TypeErasure.scala b/compiler/src/dotty/tools/dotc/core/TypeErasure.scala index b716318c1..07d613c57 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeErasure.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeErasure.scala @@ -28,7 +28,7 @@ import scala.annotation.tailrec * WildcardType * ErrorType * - * only for isInstanceOf, asInstanceOf: PolyType, PolyParam, TypeBounds + * only for isInstanceOf, asInstanceOf: PolyType, TypeParamRef, TypeBounds * */ object TypeErasure { @@ -204,7 +204,7 @@ object TypeErasure { !tp.symbol.isClass && !tp.derivesFrom(defn.ObjectClass) && !tp.symbol.is(JavaDefined) - case tp: PolyParam => + case tp: TypeParamRef => !tp.derivesFrom(defn.ObjectClass) && !tp.binder.resultType.isInstanceOf[JavaMethodType] case tp: TypeAlias => isUnboundedGeneric(tp.alias) @@ -304,7 +304,7 @@ object TypeErasure { case _: ClassInfo => true case _ => false } - case tp: PolyParam => false + case tp: TypeParamRef => false case tp: TypeProxy => hasStableErasure(tp.superType) case tp: AndOrType => hasStableErasure(tp.tp1) && hasStableErasure(tp.tp2) case _ => false diff --git a/compiler/src/dotty/tools/dotc/core/TypeOps.scala b/compiler/src/dotty/tools/dotc/core/TypeOps.scala index 3d2906320..9593bfe93 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeOps.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeOps.scala @@ -157,7 +157,7 @@ trait TypeOps { this: Context => // TODO: Make standalone object. tp2 case tp1 => tp1 } - case tp: PolyParam => + case tp: TypeParamRef => typerState.constraint.typeVarOfParam(tp) orElse tp case _: ThisType | _: BoundType | NoPrefix => tp diff --git a/compiler/src/dotty/tools/dotc/core/TyperState.scala b/compiler/src/dotty/tools/dotc/core/TyperState.scala index 206438d86..08bef86b7 100644 --- a/compiler/src/dotty/tools/dotc/core/TyperState.scala +++ b/compiler/src/dotty/tools/dotc/core/TyperState.scala @@ -42,7 +42,7 @@ class TyperState(r: Reporter) extends DotClass with Showable { */ def instType(tvar: TypeVar)(implicit ctx: Context): Type = constraint.entry(tvar.origin) match { case _: TypeBounds => NoType - case tp: PolyParam => + case tp: TypeParamRef => var tvar1 = constraint.typeVarOfParam(tp) if (tvar1.exists) tvar1 else tp case tp => tp diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 5629668c1..59c84910b 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -57,7 +57,7 @@ object Types { * | | +--- TermParamRef * | | +----RecThis * | | +--- SkolemType - * | +- PolyParam + * | +- TypeParamRef * | +- RefinedOrRecType -+-- RefinedType * | | -+-- RecType * | +- HKApply @@ -446,7 +446,7 @@ object Types { if mt.paramInfos.isEmpty && (tp.symbol is Stable) => mt.resultType case tp1 => tp1 }) - case tp: PolyParam => + case tp: TypeParamRef => goParam(tp) case tp: RecType => goRec(tp) @@ -563,7 +563,7 @@ object Types { // loadClassWithPrivateInnerAndSubSelf in ShowClassTests go(tp.cls.typeRef) orElse d } - def goParam(tp: PolyParam) = { + def goParam(tp: TypeParamRef) = { val next = tp.underlying ctx.typerState.constraint.entry(tp) match { case bounds: TypeBounds if bounds ne next => @@ -1180,8 +1180,8 @@ object Types { final def substDealias(from: List[Symbol], to: List[Type])(implicit ctx: Context): Type = ctx.substDealias(this, from, to, null) - /** Substitute all types of the form `PolyParam(from, N)` by - * `PolyParam(to, N)`. + /** Substitute all types of the form `TypeParamRef(from, N)` by + * `TypeParamRef(to, N)`. */ final def subst(from: BindingType, to: BindingType)(implicit ctx: Context): Type = ctx.subst(this, from, to, null) @@ -2673,7 +2673,7 @@ object Types { def isDependent(implicit ctx: Context) = true def isParamDependent(implicit ctx: Context) = true - def newParamRef(n: Int) = PolyParam(this, n) + def newParamRef(n: Int) = TypeParamRef(this, n) /** Instantiate parameter bounds by substituting parameters with given arguments */ final def instantiateBounds(argTypes: List[Type])(implicit ctx: Context): List[Type] = @@ -2709,7 +2709,7 @@ object Types { case that: PolyType => val shift = new TypeMap { def apply(t: Type) = t match { - case PolyParam(`that`, n) => PolyParam(that, n + paramNames.length) + case TypeParamRef(`that`, n) => TypeParamRef(that, n + paramNames.length) case t => mapOver(t) } } @@ -2742,11 +2742,6 @@ object Types { override def computeHash = doHash(paramNames, resType, paramInfos) } - object PolyParam { - def apply(pt: PolyType, n: Int) = new TypeParamRef(pt, n) - def unapply(poly: PolyParam) = Some(poly.binder, poly.paramNum) - } - object PolyType { def apply(paramNames: List[TypeName])( paramInfosExp: PolyType => List[TypeBounds], @@ -2772,8 +2767,8 @@ object Types { def paramInfoAsSeenFrom(pre: Type)(implicit ctx: Context): Type = paramInfo def paramInfoOrCompleter(implicit ctx: Context): Type = paramInfo def paramVariance(implicit ctx: Context): Int = tl.paramNames(n).variance - def toArg: Type = PolyParam(tl, n) - def paramRef(implicit ctx: Context): Type = PolyParam(tl, n) + def toArg: Type = TypeParamRef(tl, n) + def paramRef(implicit ctx: Context): Type = TypeParamRef(tl, n) } /** A higher kinded type application `C[T_1, ..., T_n]` */ @@ -2826,7 +2821,7 @@ object Types { protected def checkInst(implicit ctx: Context): this.type = { def check(tycon: Type): Unit = tycon.stripTypeVar match { case tycon: TypeRef if !tycon.symbol.isClass => - case _: PolyParam | _: ErrorType | _: WildcardType => + case _: TypeParamRef | _: ErrorType | _: WildcardType => case _: PolyType => assert(args.exists(_.isInstanceOf[TypeBounds]), s"unreduced type apply: $this") case tycon: AnnotatedType => @@ -2846,7 +2841,7 @@ object Types { unique(new CachedHKApply(tycon, args)).checkInst } - // ----- Bound types: MethodParam, PolyParam -------------------------- + // ----- Bound types: MethodParam, TypeParamRef -------------------------- abstract class BoundType extends CachedProxyType with ValueType { type BT <: Type @@ -2907,8 +2902,6 @@ object Types { } } - type PolyParam = TypeParamRef - /** a self-reference to an enclosing recursive type. */ case class RecThis(binder: RecType) extends BoundType with SingletonType { type BT = RecType @@ -2977,7 +2970,7 @@ object Types { * `owningTree` and `owner` are used to determine whether a type-variable can be instantiated * at some given point. See `Inferencing#interpolateUndetVars`. */ - final class TypeVar(val origin: PolyParam, creatorState: TyperState, val bindingTree: untpd.Tree, val owner: Symbol) extends CachedProxyType with ValueType { + final class TypeVar(val origin: TypeParamRef, creatorState: TyperState, val bindingTree: untpd.Tree, val owner: Symbol) extends CachedProxyType with ValueType { /** The permanent instance type of the variable, or NoType is none is given yet */ private[core] var inst: Type = NoType @@ -3854,7 +3847,7 @@ object Types { apply(x, tp.underlying) case tp: TermParamRef => apply(x, tp.underlying) - case tp: PolyParam => + case tp: TypeParamRef => apply(x, tp.underlying) case _ => foldOver(x, tp) diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala index a9cd9be1d..0b361f1f4 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala @@ -259,7 +259,7 @@ class TreePickler(pickler: TastyPickler) { case tpe: MethodType if richTypes => writeByte(METHODtype) pickleMethodic(tpe.resultType, tpe.paramNames, tpe.paramInfos) - case tpe: PolyParam => + case tpe: TypeParamRef => if (!pickleParamType(tpe)) // TODO figure out why this case arises in e.g. pickling AbstractFileReader. ctx.typerState.constraint.entry(tpe) match { diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala index 067fd6076..c4ff3898c 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala @@ -283,7 +283,7 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table, posUnpickle result case PARAMtype => readTypeRef() match { - case binder: PolyType => PolyParam(binder, readNat()) + case binder: PolyType => TypeParamRef(binder, readNat()) case binder: MethodType => binder.newParamRef(readNat()) } case CLASSconst => diff --git a/compiler/src/dotty/tools/dotc/printing/Formatting.scala b/compiler/src/dotty/tools/dotc/printing/Formatting.scala index 760b22689..e8fa45403 100644 --- a/compiler/src/dotty/tools/dotc/printing/Formatting.scala +++ b/compiler/src/dotty/tools/dotc/printing/Formatting.scala @@ -107,7 +107,7 @@ object Formatting { else nonSensicalStartTag + str + nonSensicalEndTag } - private type Recorded = AnyRef /*Symbol | PolyParam*/ + private type Recorded = AnyRef /*Symbol | TypeParamRef*/ private class Seen extends mutable.HashMap[String, List[Recorded]] { @@ -135,8 +135,8 @@ object Formatting { if ((sym is ModuleClass) && sym.sourceModule.exists) simpleNameString(sym.sourceModule) else seen.record(super.simpleNameString(sym), sym) - override def polyParamNameString(param: PolyParam): String = - seen.record(super.polyParamNameString(param), param) + override def TypeParamRefNameString(param: TypeParamRef): String = + seen.record(super.TypeParamRefNameString(param), param) } /** Create explanation for single `Recorded` type or symbol */ @@ -161,7 +161,7 @@ object Formatting { } entry match { - case param: PolyParam => + case param: TypeParamRef => s"is a type variable${addendum("constraint", ctx.typeComparer.bounds(param))}" case sym: Symbol => s"is a ${ctx.printer.kindString(sym)}${sym.showExtendedLocation}${addendum("bounds", sym.info)}" @@ -175,7 +175,7 @@ object Formatting { */ private def explanations(seen: Seen)(implicit ctx: Context): String = { def needsExplanation(entry: Recorded) = entry match { - case param: PolyParam => ctx.typerState.constraint.contains(param) + case param: TypeParamRef => ctx.typerState.constraint.contains(param) case _ => false } diff --git a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala index a4f9921db..94621056f 100644 --- a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala @@ -182,8 +182,8 @@ class PlainPrinter(_ctx: Context) extends Printer { "]" ~ (" => " provided !tp.resultType.isInstanceOf[MethodType]) ~ toTextGlobal(tp.resultType) } - case tp: PolyParam => - polyParamNameString(tp) ~ lambdaHash(tp.binder) + case tp: TypeParamRef => + TypeParamRefNameString(tp) ~ lambdaHash(tp.binder) case AnnotatedType(tpe, annot) => toTextLocal(tpe) ~ " " ~ toText(annot) case HKApply(tycon, args) => @@ -206,10 +206,10 @@ class PlainPrinter(_ctx: Context) extends Printer { } }.close - protected def polyParamNameString(name: TypeName): String = name.toString + protected def TypeParamRefNameString(name: TypeName): String = name.toString - protected def polyParamNameString(param: PolyParam): String = - polyParamNameString(param.binder.paramNames(param.paramNum)) + protected def TypeParamRefNameString(param: TypeParamRef): String = + TypeParamRefNameString(param.binder.paramNames(param.paramNum)) /** The name of the symbol without a unique id. Under refined printing, * the decoded original name. diff --git a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala index 8a33472b8..488e66d8d 100644 --- a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala @@ -604,7 +604,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { def optText[T >: Untyped](tree: List[Tree[T]])(encl: Text => Text): Text = if (tree.exists(!_.isEmpty)) encl(blockText(tree)) else "" - override protected def polyParamNameString(name: TypeName): String = + override protected def TypeParamRefNameString(name: TypeName): String = name.unexpandedName.toString override protected def treatAsTypeParam(sym: Symbol): Boolean = sym is TypeParam diff --git a/compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala b/compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala index d608dc7c4..28ce9aa5a 100644 --- a/compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala +++ b/compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala @@ -258,7 +258,7 @@ private class ExtractDependenciesCollector(implicit val ctx: Context) extends tp traverse(tp.underlying) case tp: TermParamRef => traverse(tp.underlying) - case tp: PolyParam => + case tp: TypeParamRef => traverse(tp.underlying) case _ => traverseChildren(tp) diff --git a/compiler/src/dotty/tools/dotc/transform/FullParameterization.scala b/compiler/src/dotty/tools/dotc/transform/FullParameterization.scala index dd318861a..0b9ec9085 100644 --- a/compiler/src/dotty/tools/dotc/transform/FullParameterization.scala +++ b/compiler/src/dotty/tools/dotc/transform/FullParameterization.scala @@ -113,7 +113,7 @@ trait FullParameterization { /** Replace class type parameters by the added type parameters of the polytype `pt` */ def mapClassParams(tp: Type, pt: PolyType): Type = { val classParamsRange = (mtparamCount until mtparamCount + ctparams.length).toList - tp.substDealias(ctparams, classParamsRange map (PolyParam(pt, _))) + tp.substDealias(ctparams, classParamsRange map (TypeParamRef(pt, _))) } /** The bounds for the added type parameters of the polytype `pt` */ diff --git a/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala b/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala index dd4d95257..dde037938 100644 --- a/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala +++ b/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala @@ -287,7 +287,7 @@ class TreeChecker extends Phase with SymTransformer { res } - /** Check that PolyParams and MethodParams refer to an enclosing type */ + /** Check that TypeParamRefs and MethodParams refer to an enclosing type */ def checkNoOrphans(tp: Type)(implicit ctx: Context) = new TypeMap() { val definedBinders = mutable.Set[Type]() def apply(tp: Type): Type = { diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index d1a73fd65..ceaf3471a 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -195,7 +195,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic => } /** The function's type after widening and instantiating polytypes - * with polyparams in constraint set + * with TypeParamRefs in constraint set */ val methType = funType.widen match { case funType: MethodType => funType diff --git a/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala b/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala index ff998e233..5f9eae3da 100644 --- a/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala +++ b/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala @@ -121,12 +121,12 @@ object ErrorReporting { } def typeMismatchMsg(found: Type, expected: Type, postScript: String = "") = { - // replace constrained polyparams and their typevars by their bounds where possible + // replace constrained TypeParamRefs and their typevars by their bounds where possible object reported extends TypeMap { def setVariance(v: Int) = variance = v val constraint = ctx.typerState.constraint def apply(tp: Type): Type = tp match { - case tp: PolyParam => + case tp: TypeParamRef => constraint.entry(tp) match { case bounds: TypeBounds => if (variance < 0) apply(constraint.fullUpperBound(tp)) diff --git a/compiler/src/dotty/tools/dotc/typer/Inferencing.scala b/compiler/src/dotty/tools/dotc/typer/Inferencing.scala index 20efd4083..18a1982e1 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inferencing.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inferencing.scala @@ -176,7 +176,7 @@ object Inferencing { * -1 (minimize) if constraint is uniformly from below, * 0 if unconstrained, or constraint is from below and above. */ - private def instDirection(param: PolyParam)(implicit ctx: Context): Int = { + private def instDirection(param: TypeParamRef)(implicit ctx: Context): Int = { val constrained = ctx.typerState.constraint.fullBounds(param) val original = param.binder.paramInfos(param.paramNum) val cmp = ctx.typeComparer diff --git a/compiler/src/dotty/tools/dotc/typer/Inliner.scala b/compiler/src/dotty/tools/dotc/typer/Inliner.scala index 8520dcdfc..cf3076fce 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inliner.scala @@ -358,7 +358,7 @@ class Inliner(call: tpd.Tree, rhs: tpd.Tree)(implicit ctx: Context) { * 2. If given type refers to a parameter, make `paramProxy` refer to the entry stored * in `paramNames` under the parameter's name. This roundabout way to bind parameter * references to proxies is done because we not known a priori what the parameter - * references of a method are (we only know the method's type, but that contains PolyParams + * references of a method are (we only know the method's type, but that contains TypeParamRefs * and MethodParams, not TypeRefs or TermRefs. */ private def registerType(tpe: Type): Unit = tpe match { diff --git a/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala b/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala index 89e4f93e2..2dccbbcc1 100644 --- a/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala +++ b/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala @@ -192,7 +192,7 @@ object ProtoTypes { /** Forget the types of any arguments that have been typed producing a constraint in a * typer state that is not yet committed into the one of the current context `ctx`. - * This is necessary to avoid "orphan" PolyParams that are referred to from + * This is necessary to avoid "orphan" TypeParamRefs that are referred to from * type variables in the typed arguments, but that are not registered in the * current constraint. A test case is pos/t1756.scala. * @return True if all arguments have types (in particular, no types were forgotten). @@ -385,7 +385,7 @@ object ProtoTypes { for (n <- (0 until pt.paramNames.length).toList) yield { val tt = new TypeTree().withPos(owningTree.pos) - tt.withType(new TypeVar(PolyParam(pt, n), state, tt, ctx.owner)) + tt.withType(new TypeVar(TypeParamRef(pt, n), state, tt, ctx.owner)) } val added = @@ -399,22 +399,22 @@ object ProtoTypes { /** Same as `constrained(pt, EmptyTree)`, but returns just the created polytype */ def constrained(pt: PolyType)(implicit ctx: Context): PolyType = constrained(pt, EmptyTree)._1 - /** Create a new polyparam that represents a dependent method parameter singleton */ - def newDepPolyParam(tp: Type)(implicit ctx: Context): PolyParam = { + /** Create a new TypeParamRef that represents a dependent method parameter singleton */ + def newDepTypeParamRef(tp: Type)(implicit ctx: Context): TypeParamRef = { val poly = PolyType(ctx.freshName(nme.DEP_PARAM_PREFIX).toTypeName :: Nil)( pt => TypeBounds.upper(AndType(tp, defn.SingletonType)) :: Nil, pt => defn.AnyType) ctx.typeComparer.addToConstraint(poly, Nil) - PolyParam(poly, 0) + TypeParamRef(poly, 0) } /** The result type of `mt`, where all references to parameters of `mt` are - * replaced by either wildcards (if typevarsMissContext) or polyparams. + * replaced by either wildcards (if typevarsMissContext) or TypeParamRefs. */ def resultTypeApprox(mt: MethodType)(implicit ctx: Context): Type = if (mt.isDependent) { def replacement(tp: Type) = - if (ctx.mode.is(Mode.TypevarsMissContext)) WildcardType else newDepPolyParam(tp) + if (ctx.mode.is(Mode.TypevarsMissContext)) WildcardType else newDepTypeParamRef(tp) mt.resultType.substParams(mt, mt.paramInfos.map(replacement)) } else mt.resultType @@ -458,7 +458,7 @@ object ProtoTypes { /** Approximate occurrences of parameter types and uninstantiated typevars * by wildcard types. */ - final def wildApprox(tp: Type, theMap: WildApproxMap, seen: Set[PolyParam])(implicit ctx: Context): Type = tp match { + final def wildApprox(tp: Type, theMap: WildApproxMap, seen: Set[TypeParamRef])(implicit ctx: Context): Type = tp match { case tp: NamedType => // default case, inlined for speed if (tp.symbol.isStatic) tp else tp.derivedSelect(wildApprox(tp.prefix, theMap, seen)) @@ -469,7 +469,7 @@ object ProtoTypes { wildApprox(tp.refinedInfo, theMap, seen)) case tp: TypeAlias => // default case, inlined for speed tp.derivedTypeAlias(wildApprox(tp.alias, theMap, seen)) - case tp @ PolyParam(poly, pnum) => + case tp @ TypeParamRef(poly, pnum) => def wildApproxBounds(bounds: TypeBounds) = if (bounds.lo.isInstanceOf[NamedType] && bounds.hi.isInstanceOf[NamedType]) WildcardType(wildApprox(bounds, theMap, seen).bounds) @@ -532,7 +532,7 @@ object ProtoTypes { @sharable object AssignProto extends UncachedGroundType with MatchAlways - private[ProtoTypes] class WildApproxMap(val seen: Set[PolyParam])(implicit ctx: Context) extends TypeMap { + private[ProtoTypes] class WildApproxMap(val seen: Set[TypeParamRef])(implicit ctx: Context) extends TypeMap { def apply(tp: Type) = wildApprox(tp, this, seen) } diff --git a/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala b/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala index 717429848..ed71f2239 100644 --- a/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala +++ b/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala @@ -348,7 +348,7 @@ trait TypeAssigner { val newIndex = gapBuf.length gapBuf += idx // Re-index unassigned type arguments that remain after transformation - PolyParam(pt, newIndex) + TypeParamRef(pt, newIndex) } // Type parameters after naming assignment, conserving paramNames order @@ -358,7 +358,7 @@ trait TypeAssigner { val transform = new TypeMap { def apply(t: Type) = t match { - case PolyParam(`pt`, idx) => normArgs(idx) + case TypeParamRef(`pt`, idx) => normArgs(idx) case _ => mapOver(t) } } diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 5e845a807..145410f65 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -1871,7 +1871,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit case TypeBounds(lo, hi) if (lo eq hi) || (hi <:< lo)(ctx.fresh.setExploreTyperState) => inst(lo) - case tp: PolyParam => + case tp: TypeParamRef => constraint.typeVarOfParam(tp).orElse(tp) case _ => tp } -- cgit v1.2.3