Skip to content

Commit 29c3818

Browse files
committed
Split HKTypeLambda from PolyType
1 parent 64e8185 commit 29c3818

File tree

9 files changed

+28
-31
lines changed

9 files changed

+28
-31
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ object TypeApplications {
7474
}
7575

7676
def unapply(tp: Type)(implicit ctx: Context): Option[TypeRef] = tp match {
77-
case tp @ PolyType/*###*/(tparams, AppliedType(fn: TypeRef, args)) if (args == tparams.map(_.toArg)) => Some(fn)
77+
case tp @ HKTypeLambda(tparams, AppliedType(fn: TypeRef, args)) if (args == tparams.map(_.toArg)) => Some(fn)
7878
case _ => None
7979
}
8080
}
@@ -252,7 +252,7 @@ class TypeApplications(val self: Type) extends AnyVal {
252252
def isHK(implicit ctx: Context): Boolean = self.dealias match {
253253
case self: TypeRef => self.info.isHK
254254
case self: RefinedType => false
255-
case self: TypeLambda => true
255+
case self: HKTypeLambda => true
256256
case self: SingletonType => false
257257
case self: TypeVar =>
258258
// Using `origin` instead of `underlying`, as is done for typeParams,
@@ -338,10 +338,10 @@ class TypeApplications(val self: Type) extends AnyVal {
338338
if (hkParams.isEmpty) self
339339
else {
340340
def adaptArg(arg: Type): Type = arg match {
341-
case arg @ PolyType(tparams, body) if /*###*/
341+
case arg @ HKTypeLambda(tparams, body) if
342342
!tparams.corresponds(hkParams)(_.paramVariance == _.paramVariance) &&
343343
tparams.corresponds(hkParams)(varianceConforms) =>
344-
PolyType(/*###*/
344+
HKTypeLambda(
345345
(tparams, hkParams).zipped.map((tparam, hkparam) =>
346346
tparam.paramName.withVariance(hkparam.paramVariance)))(
347347
tl => arg.paramInfos.map(_.subst(arg, tl).bounds),

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
669669
val tparams1 = tparams1a.drop(lengthDiff)
670670
variancesConform(tparams1, tparams) && {
671671
if (lengthDiff > 0)
672-
tycon1b = PolyType(tparams1.map(_.paramName))(/*###*/
672+
tycon1b = HKTypeLambda(tparams1.map(_.paramName))(
673673
tl => tparams1.map(tparam => tl.integrate(tparams, tparam.paramInfo).bounds),
674674
tl => tycon1a.appliedTo(args1.take(lengthDiff) ++
675675
tparams1.indices.toList.map(TypeParamRef(tl, _))))
@@ -1278,7 +1278,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
12781278
else if (tparams2.isEmpty)
12791279
original(tp1.appliedTo(tp1.typeParams.map(_.paramInfoAsSeenFrom(tp1))), tp2)
12801280
else
1281-
PolyType(/*###*/
1281+
HKTypeLambda(
12821282
paramNames = (tpnme.syntheticTypeParamNames(tparams1.length), tparams1, tparams2)
12831283
.zipped.map((pname, tparam1, tparam2) =>
12841284
pname.withVariance((tparam1.paramVariance + tparam2.paramVariance) / 2)))(

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2758,7 +2758,7 @@ object Types {
27582758
* type T[X] >: L <: U becomes type T >: ([X] -> L) <: ([X] -> U)
27592759
*/
27602760
override def fromParams[PI <: ParamInfo.Of[TypeName]](params: List[PI], resultType: Type)(implicit ctx: Context): Type = {
2761-
def expand(tp: Type) = PolyType.fromParams(params, tp) //###
2761+
def expand(tp: Type) = super.fromParams(params, tp)
27622762
resultType match {
27632763
case rt: TypeAlias =>
27642764
rt.derivedTypeAlias(expand(rt.alias))
@@ -2784,9 +2784,6 @@ object Types {
27842784
def any(n: Int)(implicit ctx: Context) =
27852785
apply(syntheticParamNames(n))(
27862786
pt => List.fill(n)(TypeBounds.empty), pt => defn.AnyType)
2787-
2788-
override def paramName(param: ParamInfo.Of[TypeName])(implicit ctx: Context): TypeName =
2789-
param.paramName.withVariance(param.paramVariance) //###
27902787
}
27912788

27922789
private object DepStatus {

compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ class TreePickler(pickler: TastyPickler) {
255255
pickleType(tpe.underlying)
256256
case tpe: HKTypeLambda =>
257257
pickleMethodic(TYPELAMBDAtype, tpe)
258-
case tpe: PolyType /*if richTypes*/ => //###
258+
case tpe: PolyType if richTypes =>
259259
pickleMethodic(POLYtype, tpe)
260260
case tpe: MethodType if richTypes =>
261261
pickleMethodic(METHODtype, tpe)

compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,9 @@ private class ExtractAPICollector(implicit val ctx: Context) extends ThunkHolder
373373
val apiTycon = simpleType(tycon)
374374
val apiArgs = args.map(processArg)
375375
new api.Parameterized(apiTycon, apiArgs.toArray)
376-
case PolyType(tparams, res) => /*###*/
377-
val apiTparams = tparams.map(apiTypeParameter)
378-
val apiRes = apiType(res)
376+
case tl: TypeLambda =>
377+
val apiTparams = tl.typeParams.map(apiTypeParameter)
378+
val apiRes = apiType(tl.resType)
379379
new api.Polymorphic(apiRes, apiTparams.toArray)
380380
case rt: RefinedType =>
381381
val name = rt.refinedName.toString

compiler/src/dotty/tools/dotc/typer/Inferencing.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ object Inferencing {
119119
}
120120
}
121121

122-
/** If `tree` has a PolyType, infer its type parameters by comparing with expected type `pt` */
122+
/** If `tree` has a type lambda type, infer its type parameters by comparing with expected type `pt` */
123123
def inferTypeParams(tree: Tree, pt: Type)(implicit ctx: Context): Tree = tree.tpe match {
124-
case poly: PolyType =>
124+
case poly: TypeLambda =>
125125
val (poly1, tvars) = constrained(poly, tree)
126126
val tree1 = tree.withType(poly1).appliedToTypeTrees(tvars)
127127
tree1.tpe <:< pt

compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -369,35 +369,35 @@ object ProtoTypes {
369369
/** A prototype for type constructors that are followed by a type application */
370370
@sharable object AnyTypeConstructorProto extends UncachedGroundType with MatchAlways
371371

372-
/** Add all parameters in given polytype `pt` to the constraint's domain.
372+
/** Add all parameters of given type lambda `tl` to the constraint's domain.
373373
* If the constraint contains already some of these parameters in its domain,
374-
* make a copy of the polytype and add the copy's type parameters instead.
375-
* Return either the original polytype, or the copy, if one was made.
374+
* make a copy of the type lambda and add the copy's type parameters instead.
375+
* Return either the original type lambda, or the copy, if one was made.
376376
* Also, if `owningTree` is non-empty, add a type variable for each parameter.
377-
* @return The added polytype, and the list of created type variables.
377+
* @return The added type lambda, and the list of created type variables.
378378
*/
379-
def constrained(pt: PolyType, owningTree: untpd.Tree)(implicit ctx: Context): (PolyType, List[TypeTree]) = {
379+
def constrained(tl: TypeLambda, owningTree: untpd.Tree)(implicit ctx: Context): (TypeLambda, List[TypeTree]) = {
380380
val state = ctx.typerState
381381
assert(!(ctx.typerState.isCommittable && owningTree.isEmpty),
382382
s"inconsistent: no typevars were added to committable constraint ${state.constraint}")
383383

384-
def newTypeVars(pt: PolyType): List[TypeTree] =
385-
for (n <- (0 until pt.paramNames.length).toList)
384+
def newTypeVars(tl: TypeLambda): List[TypeTree] =
385+
for (n <- (0 until tl.paramNames.length).toList)
386386
yield {
387387
val tt = new TypeTree().withPos(owningTree.pos)
388-
tt.withType(new TypeVar(TypeParamRef(pt, n), state, tt, ctx.owner))
388+
tt.withType(new TypeVar(TypeParamRef(tl, n), state, tt, ctx.owner))
389389
}
390390

391391
val added =
392-
if (state.constraint contains pt) pt.newLikeThis(pt.paramNames, pt.paramInfos, pt.resultType)
393-
else pt
392+
if (state.constraint contains tl) tl.newLikeThis(tl.paramNames, tl.paramInfos, tl.resultType)
393+
else tl
394394
val tvars = if (owningTree.isEmpty) Nil else newTypeVars(added)
395395
ctx.typeComparer.addToConstraint(added, tvars.tpes.asInstanceOf[List[TypeVar]])
396396
(added, tvars)
397397
}
398398

399-
/** Same as `constrained(pt, EmptyTree)`, but returns just the created polytype */
400-
def constrained(pt: PolyType)(implicit ctx: Context): PolyType = constrained(pt, EmptyTree)._1
399+
/** Same as `constrained(tl, EmptyTree)`, but returns just the created type lambda */
400+
def constrained(tl: TypeLambda)(implicit ctx: Context): TypeLambda = constrained(tl, EmptyTree)._1
401401

402402
/** Create a new TypeParamRef that represents a dependent method parameter singleton */
403403
def newDepTypeParamRef(tp: Type)(implicit ctx: Context): TypeParamRef = {

compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ trait TypeAssigner {
327327

328328
def assignType(tree: untpd.TypeApply, fn: Tree, args: List[Tree])(implicit ctx: Context) = {
329329
val ownType = fn.tpe.widen match {
330-
case pt: PolyType =>
330+
case pt: TypeLambda =>
331331
val paramNames = pt.paramNames
332332
if (hasNamedArg(args)) {
333333
// Type arguments which are specified by name (immutable after this first loop)

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
10551055
typr.println(s"adding refinement $refinement")
10561056
checkRefinementNonCyclic(refinement, refineCls, seen)
10571057
val rsym = refinement.symbol
1058-
if (rsym.info.isInstanceOf[PolyType] && rsym.allOverriddenSymbols.isEmpty)
1058+
if (rsym.info.isInstanceOf[TypeLambda] && rsym.allOverriddenSymbols.isEmpty)
10591059
ctx.error(i"polymorphic refinement $rsym without matching type in parent $tpt1 is no longer allowed", refinement.pos) }
10601060
assignType(cpy.RefinedTypeTree(tree)(tpt1, refinements1), tpt1, refinements1, refineCls)
10611061
}
@@ -1841,7 +1841,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
18411841
}
18421842

18431843
def adaptToArgs(wtp: Type, pt: FunProto): Tree = wtp match {
1844-
case _: MethodType | _: PolyType =>
1844+
case _: MethodOrPoly =>
18451845
if (pt.args.lengthCompare(1) > 0 && isUnary(wtp) && ctx.canAutoTuple)
18461846
adaptInterpolated(tree, pt.tupled, original)
18471847
else

0 commit comments

Comments
 (0)