Skip to content

Commit 7d414eb

Browse files
committed
Roll Uncurry into Erasure
Making cpy recompute types uncovered errors in uncurry. In a nutshell, the intermediate Apply nodes of a curried function were ill-typed, which caused errors produced by TypeAssigner. These nodes were eliminated down the road, but the errors are already issued. I did not find a good way to treat uncurry as a treetransform. Since it is rather trivial, it did not seem warranted to make it a full transformer either. So in the end the uncurry functionality became part of erasure.
1 parent c54cd3e commit 7d414eb

File tree

4 files changed

+31
-58
lines changed

4 files changed

+31
-58
lines changed

src/dotty/tools/dotc/Compiler.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ class Compiler {
3232
new TypeTestsCasts,
3333
new InterceptedMethods,
3434
new Literalize),
35-
List(new Erasure)//,
36-
//List(new UncurryTreeTransform
37-
// /* , new Constructors */)
35+
List(new Erasure)
3836
)
3937

4038
var runId = 1

src/dotty/tools/dotc/core/transform/Erasure.scala

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ class Erasure(isJava: Boolean, isSemi: Boolean, isConstructor: Boolean, wildcard
107107
* - For T1 & T2, erasure(T1) (??)
108108
* - For T1 | T2, the first base class in the linearization of T which is also a base class of T2
109109
* - For a method type (Fs)scala.Unit, (|Fs|)scala.Unit.
110-
* - For any other method type (Fs)T, (|Fs|)|T|.
110+
* - For any other uncurried method type (Fs)T, (|Fs|)|T|.
111+
* - For a curried method type (Fs1)(Fs2)T, (|Fs1|,Es2)ET where (Es2)ET = |(Fs2)T|.
111112
* - For a polymorphic type, the erasure of its result type.
112113
* - For the class info type of java.lang.Object, the same type without any parents.
113114
* - For a class info type of a value class, the same type without any parents.
@@ -140,8 +141,13 @@ class Erasure(isJava: Boolean, isSemi: Boolean, isConstructor: Boolean, wildcard
140141
this(tp.baseTypeRef(lubClass(tp1, tp2)))
141142
case tp: MethodType =>
142143
val paramErasure = erasureFn(tp.isJava, isSemi, isConstructor, wildcardOK)(_)
143-
tp.derivedMethodType(
144-
tp.paramNames, tp.paramTypes.mapConserve(paramErasure), eraseResult(tp.resultType))
144+
val formals = tp.paramTypes.mapConserve(paramErasure)
145+
eraseResult(tp.resultType) match {
146+
case rt: MethodType =>
147+
tp.derivedMethodType(tp.paramNames ++ rt.paramNames, formals ++ rt.paramTypes, rt.resultType)
148+
case rt =>
149+
tp.derivedMethodType(tp.paramNames, formals, rt)
150+
}
145151
case tp: PolyType =>
146152
this(tp.resultType)
147153
case tp @ ClassInfo(pre, cls, classParents, decls, _) =>

src/dotty/tools/dotc/transform/Erasure.scala

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,28 @@ object Erasure {
264264

265265
override def typedApply(tree: untpd.Apply, pt: Type)(implicit ctx: Context): Tree = {
266266
val Apply(fun, args) = tree
267-
val fun1 = typedExpr(fun, WildcardType)
268-
fun1.tpe.widen match {
269-
case mt: MethodType =>
270-
val args1 = args.zipWithConserve(mt.paramTypes)(typedExpr)
271-
untpd.cpy.Apply(tree)(fun1, args1) withType mt.resultType
267+
fun match {
268+
case fun: Apply =>
269+
typedApply(fun, pt)(ctx.fresh.setTree(tree))
272270
case _ =>
273-
throw new MatchError(i"tree $tree has uxpected type of function ${fun1.tpe.widen}, was ${fun.typeOpt.widen}")
271+
def nextOuter(ctx: Context): Context =
272+
if (ctx.outer.tree eq tree) nextOuter(ctx.outer) else ctx.outer
273+
def contextArgs(tree: untpd.Apply)(implicit ctx: Context): List[untpd.Tree] =
274+
ctx.tree match {
275+
case enclApp @ Apply(enclFun, enclArgs) if enclFun eq tree =>
276+
enclArgs ++ contextArgs(enclApp)(nextOuter(ctx))
277+
case _ =>
278+
Nil
279+
}
280+
val allArgs = args ++ contextArgs(tree)
281+
val fun1 = typedExpr(fun, WildcardType)
282+
fun1.tpe.widen match {
283+
case mt: MethodType =>
284+
val allArgs1 = allArgs.zipWithConserve(mt.paramTypes)(typedExpr)
285+
untpd.cpy.Apply(tree)(fun1, allArgs1) withType mt.resultType
286+
case _ =>
287+
throw new MatchError(i"tree $tree has unexpected type of function ${fun1.tpe.widen}, was ${fun.typeOpt.widen}")
288+
}
274289
}
275290
}
276291

src/dotty/tools/dotc/transform/UncurryTreeTransform.scala

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)