Skip to content

Commit 1c62d05

Browse files
authored
Merge pull request #1560 from dotty-staging/change-one-polytype
Harmonize PolyType and TypeLambda
2 parents f738201 + 9e74d72 commit 1c62d05

39 files changed

+446
-481
lines changed

docs/syntax-summary.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ grammar.
9696
ClassQualifier ::= `[' id `]'
9797

9898
Type ::= FunArgTypes `=>' Type Function(ts, t)
99-
| HkTypeParamClause `->' Type TypeLambda(ps, t)
99+
| HkTypeParamClause `=>' Type TypeLambda(ps, t)
100100
| InfixType
101101
FunArgTypes ::= InfixType
102102
| `(' [ FunArgType {`,' FunArgType } ] `)'

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
@@ -562,9 +562,9 @@ object Trees {
562562
}
563563

564564
/** [typeparams] -> tpt */
565-
case class TypeLambdaTree[-T >: Untyped] private[ast] (tparams: List[TypeDef[T]], body: Tree[T])
565+
case class PolyTypeTree[-T >: Untyped] private[ast] (tparams: List[TypeDef[T]], body: Tree[T])
566566
extends TypTree[T] {
567-
type ThisTree[-T >: Untyped] = TypeLambdaTree[T]
567+
type ThisTree[-T >: Untyped] = PolyTypeTree[T]
568568
}
569569

570570
/** => T */
@@ -820,7 +820,7 @@ object Trees {
820820
type OrTypeTree = Trees.OrTypeTree[T]
821821
type RefinedTypeTree = Trees.RefinedTypeTree[T]
822822
type AppliedTypeTree = Trees.AppliedTypeTree[T]
823-
type TypeLambdaTree = Trees.TypeLambdaTree[T]
823+
type PolyTypeTree = Trees.PolyTypeTree[T]
824824
type ByNameTypeTree = Trees.ByNameTypeTree[T]
825825
type TypeBoundsTree = Trees.TypeBoundsTree[T]
826826
type Bind = Trees.Bind[T]
@@ -984,9 +984,9 @@ object Trees {
984984
case tree: AppliedTypeTree if (tpt eq tree.tpt) && (args eq tree.args) => tree
985985
case _ => finalize(tree, untpd.AppliedTypeTree(tpt, args))
986986
}
987-
def TypeLambdaTree(tree: Tree)(tparams: List[TypeDef], body: Tree): TypeLambdaTree = tree match {
988-
case tree: TypeLambdaTree if (tparams eq tree.tparams) && (body eq tree.body) => tree
989-
case _ => finalize(tree, untpd.TypeLambdaTree(tparams, body))
987+
def PolyTypeTree(tree: Tree)(tparams: List[TypeDef], body: Tree): PolyTypeTree = tree match {
988+
case tree: PolyTypeTree if (tparams eq tree.tparams) && (body eq tree.body) => tree
989+
case _ => finalize(tree, untpd.PolyTypeTree(tparams, body))
990990
}
991991
def ByNameTypeTree(tree: Tree)(result: Tree): ByNameTypeTree = tree match {
992992
case tree: ByNameTypeTree if result eq tree.result => tree
@@ -1118,8 +1118,8 @@ object Trees {
11181118
cpy.RefinedTypeTree(tree)(transform(tpt), transformSub(refinements))
11191119
case AppliedTypeTree(tpt, args) =>
11201120
cpy.AppliedTypeTree(tree)(transform(tpt), transform(args))
1121-
case TypeLambdaTree(tparams, body) =>
1122-
cpy.TypeLambdaTree(tree)(transformSub(tparams), transform(body))
1121+
case PolyTypeTree(tparams, body) =>
1122+
cpy.PolyTypeTree(tree)(transformSub(tparams), transform(body))
11231123
case ByNameTypeTree(result) =>
11241124
cpy.ByNameTypeTree(tree)(transform(result))
11251125
case TypeBoundsTree(lo, hi) =>
@@ -1222,7 +1222,7 @@ object Trees {
12221222
this(this(x, tpt), refinements)
12231223
case AppliedTypeTree(tpt, args) =>
12241224
this(this(x, tpt), args)
1225-
case TypeLambdaTree(tparams, body) =>
1225+
case PolyTypeTree(tparams, body) =>
12261226
implicit val ctx: Context = localCtx
12271227
this(this(x, tparams), body)
12281228
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
@@ -44,10 +44,10 @@ trait ConstraintHandling {
4444
try op finally alwaysFluid = saved
4545
}
4646

47-
/** We are currently comparing lambdas. Used as a flag for
47+
/** We are currently comparing polytypes. Used as a flag for
4848
* optimization: when `false`, no need to do an expensive `pruneLambdaParams`
4949
*/
50-
protected var comparingLambdas = false
50+
protected var comparedPolyTypes: Set[PolyType] = Set.empty
5151

5252
private def addOneBound(param: PolyParam, bound: Type, isUpper: Boolean): Boolean =
5353
!constraint.contains(param) || {
@@ -316,12 +316,12 @@ trait ConstraintHandling {
316316
* missing.
317317
*/
318318
def pruneLambdaParams(tp: Type) =
319-
if (comparingLambdas && param.binder.isInstanceOf[PolyType]) {
319+
if (comparedPolyTypes.nonEmpty) {
320320
val approx = new ApproximatingTypeMap {
321321
def apply(t: Type): Type = t match {
322-
case t @ PolyParam(tl: TypeLambda, n) =>
322+
case t @ PolyParam(pt: PolyType, n) if comparedPolyTypes contains pt =>
323323
val effectiveVariance = if (fromBelow) -variance else variance
324-
val bounds = tl.paramBounds(n)
324+
val bounds = pt.paramBounds(n)
325325
if (effectiveVariance > 0) bounds.lo
326326
else if (effectiveVariance < 0) bounds.hi
327327
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] = {

0 commit comments

Comments
 (0)