Skip to content

Commit 73142a7

Browse files
committed
Eliminate LambdaAbstract
Use fromParams instead.
1 parent 4bb5baf commit 73142a7

File tree

7 files changed

+34
-34
lines changed

7 files changed

+34
-34
lines changed

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

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -271,25 +271,6 @@ class TypeApplications(val self: Type) extends AnyVal {
271271
self
272272
}
273273

274-
/** Lambda abstract `self` with given type parameters. Examples:
275-
*
276-
* type T[X] = U becomes type T = [X] -> U
277-
* type T[X] >: L <: U becomes type T >: L <: ([X] -> U)
278-
*/
279-
def LambdaAbstract(tparams: List[TypeParamInfo])(implicit ctx: Context): Type = {
280-
def expand(tp: Type) = PolyType/*HKTypeLambda*/.fromParams(tparams, tp)
281-
if (tparams.isEmpty) self
282-
else self match {
283-
case self: TypeAlias =>
284-
self.derivedTypeAlias(expand(self.alias))
285-
case self @ TypeBounds(lo, hi) =>
286-
self.derivedTypeBounds(
287-
if (lo.isRef(defn.NothingClass)) lo else expand(lo),
288-
expand(hi))
289-
case _ => expand(self)
290-
}
291-
}
292-
293274
/** Convert a type constructor `TC` which has type parameters `T1, ..., Tn`
294275
* in a context where type parameters `U1,...,Un` are expected to
295276
*
@@ -302,7 +283,7 @@ class TypeApplications(val self: Type) extends AnyVal {
302283
*/
303284
def EtaExpand(tparams: List[TypeSymbol])(implicit ctx: Context): Type = {
304285
val tparamsToUse = if (variancesConform(typeParams, tparams)) tparams else typeParamSymbols
305-
self.appliedTo(tparams map (_.typeRef)).LambdaAbstract(tparamsToUse)
286+
HKTypeLambda.fromParams(tparamsToUse, self.appliedTo(tparams map (_.typeRef)))
306287
//.ensuring(res => res.EtaReduce =:= self, s"res = $res, core = ${res.EtaReduce}, self = $self, hc = ${res.hashCode}")
307288
}
308289

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

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2562,12 +2562,11 @@ object Types {
25622562

25632563
protected def paramName(param: ParamInfo.Of[N])(implicit ctx: Context): N =
25642564
param.paramName
2565-
protected def paramInfo(param: ParamInfo.Of[N])(implicit ctx: Context): Type =
2566-
param.paramInfo
25672565

2568-
def fromParams[PI <: ParamInfo.Of[N]](params: List[PI], resultType: Type)(implicit ctx: Context): LT =
2569-
apply(params.map(paramName))(
2570-
tl => params.map(param => tl.integrate(params, paramInfo(param)).asInstanceOf[PInfo]),
2566+
def fromParams[PI <: ParamInfo.Of[N]](params: List[PI], resultType: Type)(implicit ctx: Context): Type =
2567+
if (params.isEmpty) resultType
2568+
else apply(params.map(paramName))(
2569+
tl => params.map(param => tl.integrate(params, param.paramInfo).asInstanceOf[PInfo]),
25712570
tl => tl.integrate(params, resultType))
25722571
}
25732572

@@ -2751,6 +2750,25 @@ object Types {
27512750

27522751
override def paramName(param: ParamInfo.Of[TypeName])(implicit ctx: Context): TypeName =
27532752
param.paramName.withVariance(param.paramVariance)
2753+
2754+
/** Distributes Lambda inside type bounds. Examples:
2755+
*
2756+
* type T[X] = U becomes type T = [X] -> U
2757+
* type T[X] <: U becomes type T >: Nothign <: ([X] -> U)
2758+
* type T[X] >: L <: U becomes type T >: ([X] -> L) <: ([X] -> U)
2759+
*/
2760+
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) //###
2762+
resultType match {
2763+
case rt: TypeAlias =>
2764+
rt.derivedTypeAlias(expand(rt.alias))
2765+
case rt @ TypeBounds(lo, hi) =>
2766+
rt.derivedTypeBounds(
2767+
if (lo.isRef(defn.NothingClass)) lo else expand(lo), expand(hi))
2768+
case rt =>
2769+
expand(rt)
2770+
}
2771+
}
27542772
}
27552773

27562774
object PolyType extends TypeLambdaCompanion[PolyType] {

compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ object Scala2Unpickler {
4242

4343
/** Convert temp poly type to poly type and leave other types alone. */
4444
def translateTempPoly(tp: Type)(implicit ctx: Context): Type = tp match {
45-
case TempPolyType(tparams, restpe) => restpe.LambdaAbstract(tparams) // PolyType.fromParams(tparams, restpe)
45+
case TempPolyType(tparams, restpe) =>
46+
(if (tparams.head.owner.isTerm) PolyType else HKTypeLambda)
47+
.fromParams(tparams, restpe)
4648
case tp => tp
4749
}
4850

4951
def addConstructorTypeParams(denot: SymDenotation)(implicit ctx: Context) = {
5052
assert(denot.isConstructor)
51-
denot.info = denot.info.LambdaAbstract(denot.owner.typeParams)
53+
denot.info = PolyType.fromParams(denot.owner.typeParams, denot.info)
5254
}
5355

5456
/** Convert array parameters denoting a repeated parameter of a Java method

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ object Checking {
7676
val orderedArgs = if (hasNamedArg(args)) tparams.map(argNamed) else args
7777
val bounds = tparams.map(_.paramInfoAsSeenFrom(tycon.tpe).bounds)
7878
def instantiate(bound: Type, args: List[Type]) =
79-
bound.LambdaAbstract(tparams).appliedTo(args)
79+
HKTypeLambda.fromParams(tparams, bound).appliedTo(args)
8080
checkBounds(orderedArgs, bounds, instantiate)
8181

8282
def checkWildcardHKApply(tp: Type, pos: Position): Unit = tp match {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ object Inliner {
120120
// Abstract accessed type over local refs
121121
def abstractQualType(mtpe: Type): Type =
122122
if (localRefs.isEmpty) mtpe
123-
else PolyType.fromParams(localRefs.map(_.symbol.asType), mtpe).flatten
123+
else PolyType.fromParams(localRefs.map(_.symbol.asType), mtpe)
124+
.asInstanceOf[PolyType].flatten
124125

125126
val accessorType = abstractQualType(addQualType(dealiasMap(accessedType)))
126127
val accessor = accessorSymbol(tree, accessorType).asTerm

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ trait NamerContextOps { this: Context =>
115115
if (param.info.isDirectRef(defn.ObjectClass)) param.info = defn.AnyType
116116
make.fromSymbols(params.asInstanceOf[List[TermSymbol]], resultType)
117117
}
118-
if (typeParams.nonEmpty) monotpe.LambdaAbstract(typeParams.asInstanceOf[List[TypeSymbol]])
118+
if (typeParams.nonEmpty) PolyType.fromParams(typeParams.asInstanceOf[List[TypeSymbol]], monotpe)
119119
else if (valueParamss.isEmpty) ExprType(monotpe)
120120
else monotpe
121121
}
@@ -1122,9 +1122,7 @@ class Namer { typer: Typer =>
11221122
}
11231123

11241124
def typeDefSig(tdef: TypeDef, sym: Symbol, tparamSyms: List[TypeSymbol])(implicit ctx: Context): Type = {
1125-
def abstracted(tp: Type): Type =
1126-
if (tparamSyms.nonEmpty) tp.LambdaAbstract(tparamSyms) else tp
1127-
1125+
def abstracted(tp: Type): Type = HKTypeLambda.fromParams(tparamSyms, tp)
11281126
val dummyInfo = abstracted(TypeBounds.empty)
11291127
sym.info = dummyInfo
11301128
// Temporarily set info of defined type T to ` >: Nothing <: Any.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ trait TypeAssigner {
458458
}
459459

460460
def assignType(tree: untpd.LambdaTypeTree, tparamDefs: List[TypeDef], body: Tree)(implicit ctx: Context) =
461-
tree.withType(body.tpe.LambdaAbstract(tparamDefs.map(_.symbol.asType)))
461+
tree.withType(HKTypeLambda.fromParams(tparamDefs.map(_.symbol.asType), body.tpe))
462462

463463
def assignType(tree: untpd.ByNameTypeTree, result: Tree)(implicit ctx: Context) =
464464
tree.withType(ExprType(result.tpe))

0 commit comments

Comments
 (0)