Skip to content

Commit 09cc237

Browse files
authored
Merge pull request #2121 from dotty-staging/change-merge-method-poly
Refactor lambda types
2 parents 62c2a1e + e800987 commit 09cc237

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1032
-988
lines changed

compiler/src/dotty/tools/backend/jvm/scalaPrimitives.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class DottyPrimitives(ctx: Context) {
142142
ctx.error(s"Unknown primitive method $cls.$method")
143143
else alts foreach (s =>
144144
addPrimitive(s,
145-
s.info.paramTypess match {
145+
s.info.paramInfoss match {
146146
case List(tp :: _) if code == ADD && tp =:= ctx.definitions.StringType => CONCAT
147147
case _ => code
148148
}

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ object desugar {
154154
case ContextBounds(tbounds, cxbounds) =>
155155
epbuf ++= makeImplicitParameters(cxbounds, isPrimaryConstructor)
156156
tbounds
157-
case PolyTypeTree(tparams, body) =>
158-
cpy.PolyTypeTree(rhs)(tparams, desugarContextBounds(body))
157+
case LambdaTypeTree(tparams, body) =>
158+
cpy.LambdaTypeTree(rhs)(tparams, desugarContextBounds(body))
159159
case _ =>
160160
rhs
161161
}

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ trait UntypedTreeInfo extends TreeInfo[Untyped] { self: Trees.Instance[Untyped]
262262
case mdef: TypeDef =>
263263
def isBounds(rhs: Tree): Boolean = rhs match {
264264
case _: TypeBoundsTree => true
265-
case PolyTypeTree(_, body) => isBounds(body)
265+
case LambdaTypeTree(_, body) => isBounds(body)
266266
case _ => false
267267
}
268268
mdef.rhs.isEmpty || isBounds(mdef.rhs)

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -578,9 +578,9 @@ object Trees {
578578
}
579579

580580
/** [typeparams] -> tpt */
581-
case class PolyTypeTree[-T >: Untyped] private[ast] (tparams: List[TypeDef[T]], body: Tree[T])
581+
case class LambdaTypeTree[-T >: Untyped] private[ast] (tparams: List[TypeDef[T]], body: Tree[T])
582582
extends TypTree[T] {
583-
type ThisTree[-T >: Untyped] = PolyTypeTree[T]
583+
type ThisTree[-T >: Untyped] = LambdaTypeTree[T]
584584
}
585585

586586
/** => T */
@@ -833,7 +833,7 @@ object Trees {
833833
type OrTypeTree = Trees.OrTypeTree[T]
834834
type RefinedTypeTree = Trees.RefinedTypeTree[T]
835835
type AppliedTypeTree = Trees.AppliedTypeTree[T]
836-
type PolyTypeTree = Trees.PolyTypeTree[T]
836+
type LambdaTypeTree = Trees.LambdaTypeTree[T]
837837
type ByNameTypeTree = Trees.ByNameTypeTree[T]
838838
type TypeBoundsTree = Trees.TypeBoundsTree[T]
839839
type Bind = Trees.Bind[T]
@@ -998,9 +998,9 @@ object Trees {
998998
case tree: AppliedTypeTree if (tpt eq tree.tpt) && (args eq tree.args) => tree
999999
case _ => finalize(tree, untpd.AppliedTypeTree(tpt, args))
10001000
}
1001-
def PolyTypeTree(tree: Tree)(tparams: List[TypeDef], body: Tree): PolyTypeTree = tree match {
1002-
case tree: PolyTypeTree if (tparams eq tree.tparams) && (body eq tree.body) => tree
1003-
case _ => finalize(tree, untpd.PolyTypeTree(tparams, body))
1001+
def LambdaTypeTree(tree: Tree)(tparams: List[TypeDef], body: Tree): LambdaTypeTree = tree match {
1002+
case tree: LambdaTypeTree if (tparams eq tree.tparams) && (body eq tree.body) => tree
1003+
case _ => finalize(tree, untpd.LambdaTypeTree(tparams, body))
10041004
}
10051005
def ByNameTypeTree(tree: Tree)(result: Tree): ByNameTypeTree = tree match {
10061006
case tree: ByNameTypeTree if result eq tree.result => tree
@@ -1144,8 +1144,8 @@ object Trees {
11441144
cpy.RefinedTypeTree(tree)(transform(tpt), transformSub(refinements))
11451145
case AppliedTypeTree(tpt, args) =>
11461146
cpy.AppliedTypeTree(tree)(transform(tpt), transform(args))
1147-
case PolyTypeTree(tparams, body) =>
1148-
cpy.PolyTypeTree(tree)(transformSub(tparams), transform(body))
1147+
case LambdaTypeTree(tparams, body) =>
1148+
cpy.LambdaTypeTree(tree)(transformSub(tparams), transform(body))
11491149
case ByNameTypeTree(result) =>
11501150
cpy.ByNameTypeTree(tree)(transform(result))
11511151
case TypeBoundsTree(lo, hi) =>
@@ -1248,7 +1248,7 @@ object Trees {
12481248
this(this(x, tpt), refinements)
12491249
case AppliedTypeTree(tpt, args) =>
12501250
this(this(x, tpt), args)
1251-
case PolyTypeTree(tparams, body) =>
1251+
case LambdaTypeTree(tparams, body) =>
12521252
implicit val ctx = localCtx
12531253
this(this(x, tparams), body)
12541254
case ByNameTypeTree(result) =>

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
145145
def ByNameTypeTree(result: Tree)(implicit ctx: Context): ByNameTypeTree =
146146
ta.assignType(untpd.ByNameTypeTree(result), result)
147147

148-
def PolyTypeTree(tparams: List[TypeDef], body: Tree)(implicit ctx: Context): PolyTypeTree =
149-
ta.assignType(untpd.PolyTypeTree(tparams, body), tparams, body)
148+
def LambdaTypeTree(tparams: List[TypeDef], body: Tree)(implicit ctx: Context): LambdaTypeTree =
149+
ta.assignType(untpd.LambdaTypeTree(tparams, body), tparams, body)
150150

151151
def TypeBoundsTree(lo: Tree, hi: Tree)(implicit ctx: Context): TypeBoundsTree =
152152
ta.assignType(untpd.TypeBoundsTree(lo, hi), lo, hi)
@@ -190,7 +190,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
190190
val maybeImplicit = if (tp.isInstanceOf[ImplicitMethodType]) Implicit else EmptyFlags
191191
ctx.newSymbol(sym, name, TermParam | maybeImplicit, info)
192192
}
193-
val params = (tp.paramNames, tp.paramTypes).zipped.map(valueParam)
193+
val params = (tp.paramNames, tp.paramInfos).zipped.map(valueParam)
194194
val (paramss, rtp) = valueParamss(tp.instantiate(params map (_.termRef)))
195195
(params :: paramss, rtp)
196196
case tp => (Nil, tp.widenExpr)
@@ -221,7 +221,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
221221
case ctpe: PolyType =>
222222
isApplicable(ctpe.instantiate(firstParent.argTypes))
223223
case ctpe: MethodType =>
224-
(superArgs corresponds ctpe.paramTypes)(_.tpe <:< _)
224+
(superArgs corresponds ctpe.paramInfos)(_.tpe <:< _)
225225
case _ =>
226226
false
227227
}
@@ -836,7 +836,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
836836
val selected =
837837
if (denot.isOverloaded) {
838838
def typeParamCount(tp: Type) = tp.widen match {
839-
case tp: PolyType => tp.paramBounds.length
839+
case tp: PolyType => tp.paramInfos.length
840840
case _ => 0
841841
}
842842
var allAlts = denot.alternatives
@@ -859,7 +859,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
859859
def adaptLastArg(lastParam: Tree, expectedType: Type) = {
860860
if (isAnnotConstructor && !(lastParam.tpe <:< expectedType)) {
861861
val defn = ctx.definitions
862-
val prefix = args.take(selected.widen.paramTypess.head.size - 1)
862+
val prefix = args.take(selected.widen.paramInfoss.head.size - 1)
863863
expectedType match {
864864
case defn.ArrayOf(el) =>
865865
lastParam.tpe match {
@@ -878,7 +878,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
878878
}
879879

880880
val callArgs: List[Tree] = if (args.isEmpty) Nil else {
881-
val expectedType = selected.widen.paramTypess.head.last
881+
val expectedType = selected.widen.paramInfoss.head.last
882882
val lastParam = args.last
883883
adaptLastArg(lastParam, expectedType)
884884
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
270270
def OrTypeTree(left: Tree, right: Tree): OrTypeTree = new OrTypeTree(left, right)
271271
def RefinedTypeTree(tpt: Tree, refinements: List[Tree]): RefinedTypeTree = new RefinedTypeTree(tpt, refinements)
272272
def AppliedTypeTree(tpt: Tree, args: List[Tree]): AppliedTypeTree = new AppliedTypeTree(tpt, args)
273-
def PolyTypeTree(tparams: List[TypeDef], body: Tree): PolyTypeTree = new PolyTypeTree(tparams, body)
273+
def LambdaTypeTree(tparams: List[TypeDef], body: Tree): LambdaTypeTree = new LambdaTypeTree(tparams, body)
274274
def ByNameTypeTree(result: Tree): ByNameTypeTree = new ByNameTypeTree(result)
275275
def TypeBoundsTree(lo: Tree, hi: Tree): TypeBoundsTree = new TypeBoundsTree(lo, hi)
276276
def Bind(name: Name, body: Tree): Bind = new Bind(name, body)
@@ -361,7 +361,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
361361
ValDef(nme.syntheticParamName(n), tpt, EmptyTree).withFlags(SyntheticTermParam)
362362

363363
def lambdaAbstract(tparams: List[TypeDef], tpt: Tree)(implicit ctx: Context) =
364-
if (tparams.isEmpty) tpt else PolyTypeTree(tparams, tpt)
364+
if (tparams.isEmpty) tpt else LambdaTypeTree(tparams, tpt)
365365

366366
/** A reference to given definition. If definition is a repeated
367367
* parameter, the reference will be a repeated argument.

compiler/src/dotty/tools/dotc/config/Config.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ object Config {
4040
* accesses javac's settings.)
4141
*
4242
* It is recommended to turn this option on only when chasing down
43-
* a PolyParam instantiation error. See comment in Types.TypeVar.instantiate.
43+
* a TypeParamRef instantiation error. See comment in Types.TypeVar.instantiate.
4444
*/
4545
final val debugCheckConstraintsClosed = false
4646

compiler/src/dotty/tools/dotc/core/Constants.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,12 @@ object Constants {
169169
def convertTo(pt: Type)(implicit ctx: Context): Constant = {
170170
def classBound(pt: Type): Type = pt.dealias.stripTypeVar match {
171171
case tref: TypeRef if !tref.symbol.isClass => classBound(tref.info.bounds.lo)
172-
case param: PolyParam =>
172+
case param: TypeParamRef =>
173173
ctx.typerState.constraint.entry(param) match {
174174
case TypeBounds(lo, hi) =>
175175
if (hi.classSymbol.isPrimitiveValueClass) hi //constrain further with high bound
176176
else classBound(lo)
177-
case NoType => classBound(param.binder.paramBounds(param.paramNum).lo)
177+
case NoType => classBound(param.binder.paramInfos(param.paramNum).lo)
178178
case inst => classBound(inst)
179179
}
180180
case pt => pt

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

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,64 +13,64 @@ import config.Printers.constr
1313
/** Constraint over undetermined type parameters. Constraints are built
1414
* over values of the following types:
1515
*
16-
* - PolyType A constraint constrains the type parameters of a set of PolyTypes
17-
* - PolyParam The parameters of the constrained polytypes
18-
* - TypeVar Every constrained parameter might be associated with a TypeVar
19-
* that has the PolyParam as origin.
16+
* - TypeLambda A constraint constrains the type parameters of a set of TypeLambdas
17+
* - TypeParamRef The parameters of the constrained type lambdas
18+
* - TypeVar Every constrained parameter might be associated with a TypeVar
19+
* that has the TypeParamRef as origin.
2020
*/
2121
abstract class Constraint extends Showable {
2222

2323
type This <: Constraint
2424

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

2828
/** Does the constraint's domain contain the type parameter `param`? */
29-
def contains(param: PolyParam): Boolean
29+
def contains(param: TypeParamRef): Boolean
3030

3131
/** Does this constraint contain the type variable `tvar` and is it uninstantiated? */
3232
def contains(tvar: TypeVar): Boolean
3333

3434
/** The constraint entry for given type parameter `param`, or NoType if `param` is not part of
3535
* the constraint domain. Note: Low level, implementation dependent.
3636
*/
37-
def entry(param: PolyParam): Type
37+
def entry(param: TypeParamRef): Type
3838

3939
/** The type variable corresponding to parameter `param`, or
4040
* NoType, if `param` is not in constrained or is not paired with a type variable.
4141
*/
42-
def typeVarOfParam(param: PolyParam): Type
42+
def typeVarOfParam(param: TypeParamRef): Type
4343

4444
/** Is it known that `param1 <:< param2`? */
45-
def isLess(param1: PolyParam, param2: PolyParam): Boolean
45+
def isLess(param1: TypeParamRef, param2: TypeParamRef): Boolean
4646

4747
/** The parameters that are known to be smaller wrt <: than `param` */
48-
def lower(param: PolyParam): List[PolyParam]
48+
def lower(param: TypeParamRef): List[TypeParamRef]
4949

5050
/** The parameters that are known to be greater wrt <: than `param` */
51-
def upper(param: PolyParam): List[PolyParam]
51+
def upper(param: TypeParamRef): List[TypeParamRef]
5252

5353
/** lower(param) \ lower(butNot) */
54-
def exclusiveLower(param: PolyParam, butNot: PolyParam): List[PolyParam]
54+
def exclusiveLower(param: TypeParamRef, butNot: TypeParamRef): List[TypeParamRef]
5555

5656
/** upper(param) \ upper(butNot) */
57-
def exclusiveUpper(param: PolyParam, butNot: PolyParam): List[PolyParam]
57+
def exclusiveUpper(param: TypeParamRef, butNot: TypeParamRef): List[TypeParamRef]
5858

5959
/** The constraint bounds for given type parameter `param`.
6060
* Poly params that are known to be smaller or greater than `param`
6161
* are not contained in the return bounds.
6262
* @pre `param` is not part of the constraint domain.
6363
*/
64-
def nonParamBounds(param: PolyParam): TypeBounds
64+
def nonParamBounds(param: TypeParamRef): TypeBounds
6565

6666
/** The lower bound of `param` including all known-to-be-smaller parameters */
67-
def fullLowerBound(param: PolyParam)(implicit ctx: Context): Type
67+
def fullLowerBound(param: TypeParamRef)(implicit ctx: Context): Type
6868

6969
/** The upper bound of `param` including all known-to-be-greater parameters */
70-
def fullUpperBound(param: PolyParam)(implicit ctx: Context): Type
70+
def fullUpperBound(param: TypeParamRef)(implicit ctx: Context): Type
7171

7272
/** The bounds of `param` including all known-to-be-smaller and -greater parameters */
73-
def fullBounds(param: PolyParam)(implicit ctx: Context): TypeBounds
73+
def fullBounds(param: TypeParamRef)(implicit ctx: Context): TypeBounds
7474

7575
/** A new constraint which is derived from this constraint by adding
7676
* entries for all type parameters of `poly`.
@@ -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: PolyType, tvars: List[TypeVar])(implicit ctx: Context): This
82+
def add(poly: TypeLambda, 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`.
@@ -90,44 +90,44 @@ abstract class Constraint extends Showable {
9090
*
9191
* @pre `this contains param`.
9292
*/
93-
def updateEntry(param: PolyParam, tp: Type)(implicit ctx: Context): This
93+
def updateEntry(param: TypeParamRef, tp: Type)(implicit ctx: Context): This
9494

9595
/** A constraint that includes the relationship `p1 <: p2`.
9696
* `<:` relationships between parameters ("edges") are propagated, but
9797
* non-parameter bounds are left alone.
9898
*/
99-
def addLess(p1: PolyParam, p2: PolyParam)(implicit ctx: Context): This
99+
def addLess(p1: TypeParamRef, p2: TypeParamRef)(implicit ctx: Context): This
100100

101101
/** A constraint resulting from adding p2 = p1 to this constraint, and at the same
102102
* time transferring all bounds of p2 to p1
103103
*/
104-
def unify(p1: PolyParam, p2: PolyParam)(implicit ctx: Context): This
104+
def unify(p1: TypeParamRef, p2: TypeParamRef)(implicit ctx: Context): This
105105

106106
/** A new constraint which is derived from this constraint by removing
107107
* the type parameter `param` from the domain and replacing all top-level occurrences
108108
* of the parameter elsewhere in the constraint by type `tp`, or a conservative
109109
* approximation of it if that is needed to avoid cycles.
110110
* Occurrences nested inside a refinement or prefix are not affected.
111111
*/
112-
def replace(param: PolyParam, tp: Type)(implicit ctx: Context): This
112+
def replace(param: TypeParamRef, tp: Type)(implicit ctx: Context): This
113113

114114
/** Is entry associated with `pt` removable? This is the case if
115115
* all type parameters of the entry are associated with type variables
116116
* which have their `inst` fields set.
117117
*/
118-
def isRemovable(pt: PolyType): Boolean
118+
def isRemovable(pt: TypeLambda): Boolean
119119

120120
/** A new constraint with all entries coming from `pt` removed. */
121-
def remove(pt: PolyType)(implicit ctx: Context): This
121+
def remove(pt: TypeLambda)(implicit ctx: Context): This
122122

123-
/** The polytypes constrained by this constraint */
124-
def domainPolys: List[PolyType]
123+
/** The type lambdas constrained by this constraint */
124+
def domainLambdas: List[TypeLambda]
125125

126-
/** The polytype parameters constrained by this constraint */
127-
def domainParams: List[PolyParam]
126+
/** The type lambda parameters constrained by this constraint */
127+
def domainParams: List[TypeParamRef]
128128

129129
/** Check whether predicate holds for all parameters in constraint */
130-
def forallParams(p: PolyParam => Boolean): Boolean
130+
def forallParams(p: TypeParamRef => Boolean): Boolean
131131

132132
/** Perform operation `op` on all typevars, or only on uninstantiated
133133
* typevars, depending on whether `uninstOnly` is set or not.
@@ -143,6 +143,6 @@ abstract class Constraint extends Showable {
143143
/** Check that no constrained parameter contains itself as a bound */
144144
def checkNonCyclic()(implicit ctx: Context): Unit
145145

146-
/** Check that constraint only refers to PolyParams bound by itself */
146+
/** Check that constraint only refers to TypeParamRefs bound by itself */
147147
def checkClosed()(implicit ctx: Context): Unit
148148
}

0 commit comments

Comments
 (0)