Skip to content

Commit eb71034

Browse files
committed
Merge GenericType, TypeLambda and PolyType
1 parent 81eb004 commit eb71034

32 files changed

+185
-260
lines changed

dottydoc/src/dotty/tools/dottydoc/model/factories.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ object factories {
4343
}
4444

4545
def expandTpe(t: Type, params: List[Reference] = Nil): Reference = t match {
46-
case tl: TypeLambda =>
46+
case tl: PolyType =>
4747
//FIXME: should be handled correctly
4848
// example, in `Option`:
4949
//

src/dotty/tools/backend/jvm/CollectEntryPoints.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ object CollectEntryPoints{
107107
else (possibles exists(x=> isJavaMainMethod(x.symbol))) || {
108108
possibles exists { m =>
109109
toDenot(m.symbol).info match {
110-
case t:PolyType =>
110+
case t: PolyType =>
111111
fail("main methods cannot be generic.")
112112
case t@MethodType(paramNames, paramTypes) =>
113113
if (t.resultType :: paramTypes exists (_.typeSymbol.isAbstractType))

src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -565,9 +565,9 @@ object Trees {
565565
}
566566

567567
/** [typeparams] -> tpt */
568-
case class TypeLambdaTree[-T >: Untyped] private[ast] (tparams: List[TypeDef[T]], body: Tree[T])
568+
case class PolyTypeTree[-T >: Untyped] private[ast] (tparams: List[TypeDef[T]], body: Tree[T])
569569
extends TypTree[T] {
570-
type ThisTree[-T >: Untyped] = TypeLambdaTree[T]
570+
type ThisTree[-T >: Untyped] = PolyTypeTree[T]
571571
}
572572

573573
/** => T */
@@ -823,7 +823,7 @@ object Trees {
823823
type OrTypeTree = Trees.OrTypeTree[T]
824824
type RefinedTypeTree = Trees.RefinedTypeTree[T]
825825
type AppliedTypeTree = Trees.AppliedTypeTree[T]
826-
type TypeLambdaTree = Trees.TypeLambdaTree[T]
826+
type PolyTypeTree = Trees.PolyTypeTree[T]
827827
type ByNameTypeTree = Trees.ByNameTypeTree[T]
828828
type TypeBoundsTree = Trees.TypeBoundsTree[T]
829829
type Bind = Trees.Bind[T]
@@ -987,9 +987,9 @@ object Trees {
987987
case tree: AppliedTypeTree if (tpt eq tree.tpt) && (args eq tree.args) => tree
988988
case _ => finalize(tree, untpd.AppliedTypeTree(tpt, args))
989989
}
990-
def TypeLambdaTree(tree: Tree)(tparams: List[TypeDef], body: Tree): TypeLambdaTree = tree match {
991-
case tree: TypeLambdaTree if (tparams eq tree.tparams) && (body eq tree.body) => tree
992-
case _ => finalize(tree, untpd.TypeLambdaTree(tparams, body))
990+
def PolyTypeTree(tree: Tree)(tparams: List[TypeDef], body: Tree): PolyTypeTree = tree match {
991+
case tree: PolyTypeTree if (tparams eq tree.tparams) && (body eq tree.body) => tree
992+
case _ => finalize(tree, untpd.PolyTypeTree(tparams, body))
993993
}
994994
def ByNameTypeTree(tree: Tree)(result: Tree): ByNameTypeTree = tree match {
995995
case tree: ByNameTypeTree if result eq tree.result => tree
@@ -1121,8 +1121,8 @@ object Trees {
11211121
cpy.RefinedTypeTree(tree)(transform(tpt), transformSub(refinements))
11221122
case AppliedTypeTree(tpt, args) =>
11231123
cpy.AppliedTypeTree(tree)(transform(tpt), transform(args))
1124-
case TypeLambdaTree(tparams, body) =>
1125-
cpy.TypeLambdaTree(tree)(transformSub(tparams), transform(body))
1124+
case PolyTypeTree(tparams, body) =>
1125+
cpy.PolyTypeTree(tree)(transformSub(tparams), transform(body))
11261126
case ByNameTypeTree(result) =>
11271127
cpy.ByNameTypeTree(tree)(transform(result))
11281128
case TypeBoundsTree(lo, hi) =>
@@ -1225,7 +1225,7 @@ object Trees {
12251225
this(this(x, tpt), refinements)
12261226
case AppliedTypeTree(tpt, args) =>
12271227
this(this(x, tpt), args)
1228-
case TypeLambdaTree(tparams, body) =>
1228+
case PolyTypeTree(tparams, body) =>
12291229
implicit val ctx: Context = localCtx
12301230
this(this(x, tparams), body)
12311231
case ByNameTypeTree(result) =>

src/dotty/tools/dotc/ast/untpd.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
212212
def OrTypeTree(left: Tree, right: Tree): OrTypeTree = new OrTypeTree(left, right)
213213
def RefinedTypeTree(tpt: Tree, refinements: List[Tree]): RefinedTypeTree = new RefinedTypeTree(tpt, refinements)
214214
def AppliedTypeTree(tpt: Tree, args: List[Tree]): AppliedTypeTree = new AppliedTypeTree(tpt, args)
215-
def TypeLambdaTree(tparams: List[TypeDef], body: Tree): TypeLambdaTree = new TypeLambdaTree(tparams, body)
215+
def PolyTypeTree(tparams: List[TypeDef], body: Tree): PolyTypeTree = new PolyTypeTree(tparams, body)
216216
def ByNameTypeTree(result: Tree): ByNameTypeTree = new ByNameTypeTree(result)
217217
def TypeBoundsTree(lo: Tree, hi: Tree): TypeBoundsTree = new TypeBoundsTree(lo, hi)
218218
def Bind(name: Name, body: Tree): Bind = new Bind(name, body)

src/dotty/tools/dotc/core/Constraint.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ abstract class Constraint extends Showable {
2323
type This <: Constraint
2424

2525
/** Does the constraint's domain contain the type parameters of `pt`? */
26-
def contains(pt: GenericType): Boolean
26+
def contains(pt: PolyType): Boolean
2727

2828
/** Does the constraint's domain contain the type parameter `param`? */
2929
def contains(param: PolyParam): Boolean
@@ -79,7 +79,7 @@ abstract class Constraint extends Showable {
7979
* satisfiability but will solved to give instances of
8080
* type variables.
8181
*/
82-
def add(poly: GenericType, tvars: List[TypeVar])(implicit ctx: Context): This
82+
def add(poly: PolyType, tvars: List[TypeVar])(implicit ctx: Context): This
8383

8484
/** A new constraint which is derived from this constraint by updating
8585
* the entry for parameter `param` to `tp`.
@@ -121,13 +121,13 @@ abstract class Constraint extends Showable {
121121
* all type parameters of the entry are associated with type variables
122122
* which have their `inst` fields set.
123123
*/
124-
def isRemovable(pt: GenericType): Boolean
124+
def isRemovable(pt: PolyType): Boolean
125125

126126
/** A new constraint with all entries coming from `pt` removed. */
127-
def remove(pt: GenericType)(implicit ctx: Context): This
127+
def remove(pt: PolyType)(implicit ctx: Context): This
128128

129129
/** The polytypes constrained by this constraint */
130-
def domainPolys: List[GenericType]
130+
def domainPolys: List[PolyType]
131131

132132
/** The polytype parameters constrained by this constraint */
133133
def domainParams: List[PolyParam]

src/dotty/tools/dotc/core/ConstraintHandling.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ trait ConstraintHandling {
3535
/** If the constraint is frozen we cannot add new bounds to the constraint. */
3636
protected var frozenConstraint = false
3737

38-
/** We are currently comparing lambdas. Used as a flag for
38+
/** We are currently comparing polytypes. Used as a flag for
3939
* optimization: when `false`, no need to do an expensive `pruneLambdaParams`
4040
*/
41-
protected var comparingLambdas = false
41+
protected var comparedPolyTypes: Set[PolyType] = Set.empty
4242

4343
private def addOneBound(param: PolyParam, bound: Type, isUpper: Boolean): Boolean =
4444
!constraint.contains(param) || {
@@ -307,12 +307,12 @@ trait ConstraintHandling {
307307
* missing.
308308
*/
309309
def pruneLambdaParams(tp: Type) =
310-
if (comparingLambdas && param.binder.isInstanceOf[PolyType]) {
310+
if (comparedPolyTypes.nonEmpty) {
311311
val approx = new ApproximatingTypeMap {
312312
def apply(t: Type): Type = t match {
313-
case t @ PolyParam(tl: TypeLambda, n) =>
313+
case t @ PolyParam(pt: PolyType, n) if comparedPolyTypes contains pt =>
314314
val effectiveVariance = if (fromBelow) -variance else variance
315-
val bounds = tl.paramBounds(n)
315+
val bounds = pt.paramBounds(n)
316316
if (effectiveVariance > 0) bounds.lo
317317
else if (effectiveVariance < 0) bounds.hi
318318
else NoType

src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,17 @@ class Definitions {
9292
}
9393

9494
private def newPolyMethod(cls: ClassSymbol, name: TermName, typeParamCount: Int,
95-
resultTypeFn: GenericType => Type, flags: FlagSet = EmptyFlags) = {
95+
resultTypeFn: PolyType => Type, flags: FlagSet = EmptyFlags) = {
9696
val tparamNames = tpnme.syntheticTypeParamNames(typeParamCount)
9797
val tparamBounds = tparamNames map (_ => TypeBounds.empty)
9898
val ptype = PolyType(tparamNames)(_ => tparamBounds, resultTypeFn)
9999
newMethod(cls, name, ptype, flags)
100100
}
101101

102-
private def newT1ParameterlessMethod(cls: ClassSymbol, name: TermName, resultTypeFn: GenericType => Type, flags: FlagSet) =
102+
private def newT1ParameterlessMethod(cls: ClassSymbol, name: TermName, resultTypeFn: PolyType => Type, flags: FlagSet) =
103103
newPolyMethod(cls, name, 1, resultTypeFn, flags)
104104

105-
private def newT1EmptyParamsMethod(cls: ClassSymbol, name: TermName, resultTypeFn: GenericType => Type, flags: FlagSet) =
105+
private def newT1EmptyParamsMethod(cls: ClassSymbol, name: TermName, resultTypeFn: PolyType => Type, flags: FlagSet) =
106106
newPolyMethod(cls, name, 1, pt => MethodType(Nil, resultTypeFn(pt)), flags)
107107

108108
private def mkArityArray(name: String, arity: Int, countFrom: Int): Array[TypeRef] = {

src/dotty/tools/dotc/core/OrderingConstraint.scala

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import annotation.tailrec
1414

1515
object OrderingConstraint {
1616

17-
type ArrayValuedMap[T] = SimpleMap[GenericType, Array[T]]
17+
type ArrayValuedMap[T] = SimpleMap[PolyType, Array[T]]
1818

1919
/** The type of `OrderingConstraint#boundsMap` */
2020
type ParamBounds = ArrayValuedMap[Type]
@@ -32,11 +32,11 @@ object OrderingConstraint {
3232

3333
/** A lens for updating a single entry array in one of the three constraint maps */
3434
abstract class ConstraintLens[T <: AnyRef: ClassTag] {
35-
def entries(c: OrderingConstraint, poly: GenericType): Array[T]
36-
def updateEntries(c: OrderingConstraint, poly: GenericType, entries: Array[T])(implicit ctx: Context): OrderingConstraint
35+
def entries(c: OrderingConstraint, poly: PolyType): Array[T]
36+
def updateEntries(c: OrderingConstraint, poly: PolyType, entries: Array[T])(implicit ctx: Context): OrderingConstraint
3737
def initial: T
3838

39-
def apply(c: OrderingConstraint, poly: GenericType, idx: Int) = {
39+
def apply(c: OrderingConstraint, poly: PolyType, idx: Int) = {
4040
val es = entries(c, poly)
4141
if (es == null) initial else es(idx)
4242
}
@@ -47,7 +47,7 @@ object OrderingConstraint {
4747
* parts of `current` which are not shared by `prev`.
4848
*/
4949
def update(prev: OrderingConstraint, current: OrderingConstraint,
50-
poly: GenericType, idx: Int, entry: T)(implicit ctx: Context): OrderingConstraint = {
50+
poly: PolyType, idx: Int, entry: T)(implicit ctx: Context): OrderingConstraint = {
5151
var es = entries(current, poly)
5252
if (es != null && (es(idx) eq entry)) current
5353
else {
@@ -72,7 +72,7 @@ object OrderingConstraint {
7272
update(prev, current, param.binder, param.paramNum, entry)
7373

7474
def map(prev: OrderingConstraint, current: OrderingConstraint,
75-
poly: GenericType, idx: Int, f: T => T)(implicit ctx: Context): OrderingConstraint =
75+
poly: PolyType, idx: Int, f: T => T)(implicit ctx: Context): OrderingConstraint =
7676
update(prev, current, poly, idx, f(apply(current, poly, idx)))
7777

7878
def map(prev: OrderingConstraint, current: OrderingConstraint,
@@ -81,25 +81,25 @@ object OrderingConstraint {
8181
}
8282

8383
val boundsLens = new ConstraintLens[Type] {
84-
def entries(c: OrderingConstraint, poly: GenericType): Array[Type] =
84+
def entries(c: OrderingConstraint, poly: PolyType): Array[Type] =
8585
c.boundsMap(poly)
86-
def updateEntries(c: OrderingConstraint, poly: GenericType, entries: Array[Type])(implicit ctx: Context): OrderingConstraint =
86+
def updateEntries(c: OrderingConstraint, poly: PolyType, entries: Array[Type])(implicit ctx: Context): OrderingConstraint =
8787
newConstraint(c.boundsMap.updated(poly, entries), c.lowerMap, c.upperMap)
8888
def initial = NoType
8989
}
9090

9191
val lowerLens = new ConstraintLens[List[PolyParam]] {
92-
def entries(c: OrderingConstraint, poly: GenericType): Array[List[PolyParam]] =
92+
def entries(c: OrderingConstraint, poly: PolyType): Array[List[PolyParam]] =
9393
c.lowerMap(poly)
94-
def updateEntries(c: OrderingConstraint, poly: GenericType, entries: Array[List[PolyParam]])(implicit ctx: Context): OrderingConstraint =
94+
def updateEntries(c: OrderingConstraint, poly: PolyType, entries: Array[List[PolyParam]])(implicit ctx: Context): OrderingConstraint =
9595
newConstraint(c.boundsMap, c.lowerMap.updated(poly, entries), c.upperMap)
9696
def initial = Nil
9797
}
9898

9999
val upperLens = new ConstraintLens[List[PolyParam]] {
100-
def entries(c: OrderingConstraint, poly: GenericType): Array[List[PolyParam]] =
100+
def entries(c: OrderingConstraint, poly: PolyType): Array[List[PolyParam]] =
101101
c.upperMap(poly)
102-
def updateEntries(c: OrderingConstraint, poly: GenericType, entries: Array[List[PolyParam]])(implicit ctx: Context): OrderingConstraint =
102+
def updateEntries(c: OrderingConstraint, poly: PolyType, entries: Array[List[PolyParam]])(implicit ctx: Context): OrderingConstraint =
103103
newConstraint(c.boundsMap, c.lowerMap, c.upperMap.updated(poly, entries))
104104
def initial = Nil
105105
}
@@ -149,7 +149,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
149149

150150
// ----------- Contains tests --------------------------------------------------
151151

152-
def contains(pt: GenericType): Boolean = boundsMap(pt) != null
152+
def contains(pt: PolyType): Boolean = boundsMap(pt) != null
153153

154154
def contains(param: PolyParam): Boolean = {
155155
val entries = boundsMap(param.binder)
@@ -280,7 +280,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
280280
stripParams(tp, paramBuf, isUpper)
281281
.orElse(if (isUpper) defn.AnyType else defn.NothingType)
282282

283-
def add(poly: GenericType, tvars: List[TypeVar])(implicit ctx: Context): This = {
283+
def add(poly: PolyType, tvars: List[TypeVar])(implicit ctx: Context): This = {
284284
assert(!contains(poly))
285285
val nparams = poly.paramNames.length
286286
val entries1 = new Array[Type](nparams * 2)
@@ -293,7 +293,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
293293
* Update all bounds to be normalized and update ordering to account for
294294
* dependent parameters.
295295
*/
296-
private def init(poly: GenericType)(implicit ctx: Context): This = {
296+
private def init(poly: PolyType)(implicit ctx: Context): This = {
297297
var current = this
298298
val loBuf, hiBuf = new mutable.ListBuffer[PolyParam]
299299
var i = 0
@@ -400,7 +400,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
400400
def removeParam(ps: List[PolyParam]) =
401401
ps.filterNot(p => p.binder.eq(poly) && p.paramNum == idx)
402402

403-
def replaceParam(tp: Type, atPoly: GenericType, atIdx: Int): Type = tp match {
403+
def replaceParam(tp: Type, atPoly: PolyType, atIdx: Int): Type = tp match {
404404
case bounds @ TypeBounds(lo, hi) =>
405405

406406
def recombine(andor: AndOrType, op: (Type, Boolean) => Type, isUpper: Boolean): Type = {
@@ -440,9 +440,9 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
440440
}
441441
}
442442

443-
def remove(pt: GenericType)(implicit ctx: Context): This = {
443+
def remove(pt: PolyType)(implicit ctx: Context): This = {
444444
def removeFromOrdering(po: ParamOrdering) = {
445-
def removeFromBoundss(key: GenericType, bndss: Array[List[PolyParam]]): Array[List[PolyParam]] = {
445+
def removeFromBoundss(key: PolyType, bndss: Array[List[PolyParam]]): Array[List[PolyParam]] = {
446446
val bndss1 = bndss.map(_.filterConserve(_.binder ne pt))
447447
if (bndss.corresponds(bndss1)(_ eq _)) bndss else bndss1
448448
}
@@ -451,7 +451,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
451451
newConstraint(boundsMap.remove(pt), removeFromOrdering(lowerMap), removeFromOrdering(upperMap))
452452
}
453453

454-
def isRemovable(pt: GenericType): Boolean = {
454+
def isRemovable(pt: PolyType): Boolean = {
455455
val entries = boundsMap(pt)
456456
@tailrec def allRemovable(last: Int): Boolean =
457457
if (last < 0) true
@@ -464,7 +464,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
464464

465465
// ---------- Exploration --------------------------------------------------------
466466

467-
def domainPolys: List[GenericType] = boundsMap.keys
467+
def domainPolys: List[PolyType] = boundsMap.keys
468468

469469
def domainParams: List[PolyParam] =
470470
for {
@@ -481,7 +481,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
481481
true
482482
}
483483

484-
def foreachParam(p: (GenericType, Int) => Unit): Unit =
484+
def foreachParam(p: (PolyType, Int) => Unit): Unit =
485485
boundsMap.foreachBinding { (poly, entries) =>
486486
0.until(poly.paramNames.length).foreach(p(poly, _))
487487
}
@@ -536,7 +536,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
536536

537537
override def checkClosed()(implicit ctx: Context): Unit = {
538538
def isFreePolyParam(tp: Type) = tp match {
539-
case PolyParam(binder: GenericType, _) => !contains(binder)
539+
case PolyParam(binder: PolyType, _) => !contains(binder)
540540
case _ => false
541541
}
542542
def checkClosedType(tp: Type, where: String) =

src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,7 @@ object SymDenotations {
11501150
case tp: NamedType => hasSkolems(tp.prefix)
11511151
case tp: RefinedType => hasSkolems(tp.parent) || hasSkolems(tp.refinedInfo)
11521152
case tp: RecType => hasSkolems(tp.parent)
1153-
case tp: GenericType => tp.paramBounds.exists(hasSkolems) || hasSkolems(tp.resType)
1153+
case tp: PolyType => tp.paramBounds.exists(hasSkolems) || hasSkolems(tp.resType)
11541154
case tp: MethodType => tp.paramTypes.exists(hasSkolems) || hasSkolems(tp.resType)
11551155
case tp: ExprType => hasSkolems(tp.resType)
11561156
case tp: HKApply => hasSkolems(tp.tycon) || tp.args.exists(hasSkolems)

0 commit comments

Comments
 (0)