Skip to content

Commit 49cef12

Browse files
committed
Replace PolyType.fromSymbols with LambdaAbstract
As a side effect, avoid creating synthetic parameters in lambda abstract.
1 parent 4902271 commit 49cef12

File tree

7 files changed

+14
-33
lines changed

7 files changed

+14
-33
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,10 +340,11 @@ class TypeApplications(val self: Type) extends AnyVal {
340340
def LambdaAbstract(tparams: List[TypeParamInfo])(implicit ctx: Context): Type = {
341341
def expand(tp: Type) =
342342
PolyType(
343-
tpnme.syntheticLambdaParamNames(tparams.length), tparams.map(_.paramVariance))(
343+
tparams.map(_.paramName), tparams.map(_.paramVariance))(
344344
tl => tparams.map(tparam => tl.lifted(tparams, tparam.paramBounds).bounds),
345345
tl => tl.lifted(tparams, tp))
346-
self match {
346+
if (tparams.isEmpty) self
347+
else self match {
347348
case self: TypeAlias =>
348349
self.derivedTypeAlias(expand(self.alias))
349350
case self @ TypeBounds(lo, hi) =>

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2524,7 +2524,7 @@ object Types {
25242524
case _: MethodType => true
25252525
case _ => false
25262526
}
2527-
2527+
25282528
/** Is this polytype a higher-kinded type lambda as opposed to a polymorphic?
25292529
* method type? Only type lambdas get created with variances, that's how we can tell.
25302530
*/
@@ -2619,12 +2619,6 @@ object Types {
26192619
unique(new PolyType(paramNames, vs)(paramBoundsExp, resultTypeExp))
26202620
}
26212621

2622-
def fromSymbols(tparams: List[Symbol], resultType: Type)(implicit ctx: Context): Type =
2623-
if (tparams.isEmpty) resultType
2624-
else apply(tparams map (_.name.asTypeName), tparams.map(_.variance))(
2625-
pt => tparams.map(tparam => pt.lifted(tparams, tparam.info).bounds),
2626-
pt => pt.lifted(tparams, resultType))
2627-
26282622
def unapply(tl: PolyType): Some[(List[LambdaParam], Type)] =
26292623
Some((tl.typeParams, tl.resType))
26302624

src/dotty/tools/dotc/core/classfile/ClassfileParser.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ class ClassfileParser(
217217
if (isEnum) denot.info = ConstantType(Constant(sym))
218218
if (isConstructor) stripOuterParamFromConstructor()
219219
setPrivateWithin(denot, jflags)
220-
denot.info = depoly(parseAttributes(sym, denot.info), denot)
220+
denot.info = translateTempPoly(parseAttributes(sym, denot.info))
221221
if (isConstructor) normalizeConstructorInfo()
222222

223223
if ((denot is Flags.Method) && (jflags & JAVA_ACC_VARARGS) != 0)

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

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,29 +40,15 @@ object Scala2Unpickler {
4040
/** Temporary type for classinfos, will be decomposed on completion of the class */
4141
case class TempClassInfoType(parentTypes: List[Type], decls: Scope, clazz: Symbol) extends UncachedGroundType
4242

43-
/** Convert temp poly type to some native Dotty idiom.
44-
* @param denot The denotation that gets the converted type as info.
45-
* If `denot` is not an abstract type, this simply returns an equivalent `PolyType`.
46-
* If `denot` is an abstract type, it converts a
47-
*
48-
* TempPolyType(List(v_1 T_1, ..., v_n T_n), lo .. hi)
49-
*
50-
* to a type lambda using `parameterizeWith/LambdaAbstract`.
51-
*/
52-
def depoly(tp: Type, denot: SymDenotation)(implicit ctx: Context): Type = tp match {
53-
case TempPolyType(tparams, restpe) =>
54-
if (denot.isType) {
55-
assert(!denot.isClass)
56-
restpe.LambdaAbstract(tparams)
57-
}
58-
else
59-
PolyType.fromSymbols(tparams, restpe)
43+
/** Convert temp poly type to poly type and leave other types alone. */
44+
def translateTempPoly(tp: Type)(implicit ctx: Context): Type = tp match {
45+
case TempPolyType(tparams, restpe) => restpe.LambdaAbstract(tparams)
6046
case tp => tp
6147
}
6248

6349
def addConstructorTypeParams(denot: SymDenotation)(implicit ctx: Context) = {
6450
assert(denot.isConstructor)
65-
denot.info = PolyType.fromSymbols(denot.owner.typeParams, denot.info)
51+
denot.info = denot.info.LambdaAbstract(denot.owner.typeParams)
6652
}
6753

6854
/** Convert array parameters denoting a repeated parameter of a Java method
@@ -549,7 +535,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
549535
val selfInfo = if (atEnd) NoType else readTypeRef()
550536
setClassInfo(denot, tp, selfInfo)
551537
case denot =>
552-
val tp1 = depoly(tp, denot)
538+
val tp1 = translateTempPoly(tp)
553539
denot.info =
554540
if (tag == ALIASsym) TypeAlias(tp1)
555541
else if (denot.isType) checkNonCyclic(denot.symbol, tp1, reportErrors = false)

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

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

125125
val accessorType = abstractQualType(addQualType(dealiasMap(accessedType)))
126126
val accessor = accessorSymbol(tree, accessorType).asTerm

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ trait NamerContextOps { this: Context =>
113113
if (param.info.isDirectRef(defn.ObjectClass)) param.info = defn.AnyType
114114
make.fromSymbols(params, resultType)
115115
}
116-
if (typeParams.nonEmpty) PolyType.fromSymbols(typeParams, monotpe)
116+
if (typeParams.nonEmpty) monotpe.LambdaAbstract(typeParams)
117117
else if (valueParamss.isEmpty) ExprType(monotpe)
118118
else monotpe
119119
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ trait TypeAssigner {
431431
def assignType(tree: untpd.OrTypeTree, left: Tree, right: Tree)(implicit ctx: Context) =
432432
tree.withType(left.tpe | right.tpe)
433433

434-
/** Assign type of RefinedType.
434+
/** Assign type of RefinedType.
435435
* Refinements are typed as if they were members of refinement class `refineCls`.
436436
*/
437437
def assignType(tree: untpd.RefinedTypeTree, parent: Tree, refinements: List[Tree], refineCls: ClassSymbol)(implicit ctx: Context) = {
@@ -467,7 +467,7 @@ trait TypeAssigner {
467467
}
468468

469469
def assignType(tree: untpd.PolyTypeTree, tparamDefs: List[TypeDef], body: Tree)(implicit ctx: Context) =
470-
tree.withType(PolyType.fromSymbols(tparamDefs.map(_.symbol), body.tpe))
470+
tree.withType(body.tpe.LambdaAbstract(tparamDefs.map(_.symbol)))
471471

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

0 commit comments

Comments
 (0)