Skip to content

Commit d7545ec

Browse files
committed
Simplify interplay between Uncurry Info- and Tree-Transformers
Now, the InfoTransformer is responsible for erasing the path dependent types of formal parameters, at the same place where it flattens nested method types. This is preferable to having the tree transformer overwrite the result of the info transformer, as used to be the case after my previous work on SI-6135 / 493197f.
1 parent 3ac185b commit d7545ec

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

src/compiler/scala/tools/nsc/transform/UnCurry.scala

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,8 @@ abstract class UnCurry extends InfoTransform
818818
*
819819
* This transformation erases the dependent method types by:
820820
* - Widening the formal parameter type to existentially abstract
821-
* over the prior parameters (using `packSymbols`)
821+
* over the prior parameters (using `packSymbols`). This transformation
822+
* is performed in the the `InfoTransform`er [[scala.reflect.internal.transform.UnCurry]].
822823
* - Inserting casts in the method body to cast to the original,
823824
* precise type.
824825
*
@@ -846,15 +847,14 @@ abstract class UnCurry extends InfoTransform
846847
*/
847848
def erase(dd: DefDef): (List[List[ValDef]], Tree) = {
848849
import dd.{ vparamss, rhs }
849-
val vparamSyms = vparamss flatMap (_ map (_.symbol))
850-
851850
val paramTransforms: List[ParamTransform] =
852-
vparamss.flatten.map { p =>
853-
val declaredType = p.symbol.info
854-
// existentially abstract over value parameters
855-
val packedType = typer.packSymbols(vparamSyms, declaredType)
856-
if (packedType =:= declaredType) Identity(p)
851+
map2(vparamss.flatten, dd.symbol.info.paramss.flatten) { (p, infoParam) =>
852+
val packedType = infoParam.info
853+
if (packedType =:= p.symbol.info) Identity(p)
857854
else {
855+
// The Uncurry info transformer existentially abstracted over value parameters
856+
// from the previous parameter lists.
857+
858858
// Change the type of the param symbol
859859
p.symbol updateInfo packedType
860860

@@ -866,8 +866,8 @@ abstract class UnCurry extends InfoTransform
866866
// the method body to refer to this, rather than the parameter.
867867
val tempVal: ValDef = {
868868
val tempValName = unit freshTermName (p.name + "$")
869-
val newSym = dd.symbol.newTermSymbol(tempValName, p.pos, SYNTHETIC).setInfo(declaredType)
870-
atPos(p.pos)(ValDef(newSym, gen.mkAttributedCast(Ident(p.symbol), declaredType)))
869+
val newSym = dd.symbol.newTermSymbol(tempValName, p.pos, SYNTHETIC).setInfo(p.symbol.info)
870+
atPos(p.pos)(ValDef(newSym, gen.mkAttributedCast(Ident(p.symbol), p.symbol.info)))
871871
}
872872
Packed(newParam, tempVal)
873873
}
@@ -885,13 +885,6 @@ abstract class UnCurry extends InfoTransform
885885
Block(tempVals, rhsSubstituted)
886886
}
887887

888-
// update the type of the method after uncurry.
889-
dd.symbol updateInfo {
890-
val GenPolyType(tparams, tp) = dd.symbol.info
891-
logResult("erased dependent param types for ${dd.symbol.info}") {
892-
GenPolyType(tparams, MethodType(allParams map (_.symbol), tp.finalResultType))
893-
}
894-
}
895888
(allParams :: Nil, rhs1)
896889
}
897890
}

src/reflect/scala/reflect/internal/transform/UnCurry.scala

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@ trait UnCurry {
1717
val tp = expandAlias(tp0)
1818
tp match {
1919
case MethodType(params, MethodType(params1, restpe)) =>
20-
apply(MethodType(params ::: params1, restpe))
20+
// This transformation is described in UnCurryTransformer.dependentParamTypeErasure
21+
val packSymbolsMap = new TypeMap {
22+
// Wrapping in a TypeMap to reuse the code that opts for a fast path if the function is an identity.
23+
def apply(tp: Type): Type = packSymbols(params, tp)
24+
}
25+
val existentiallyAbstractedParam1s = packSymbolsMap.mapOver(params1)
26+
val substitutedResult = restpe.substSym(params1, existentiallyAbstractedParam1s)
27+
apply(MethodType(params ::: existentiallyAbstractedParam1s, substitutedResult))
2128
case MethodType(params, ExistentialType(tparams, restpe @ MethodType(_, _))) =>
2229
abort("unexpected curried method types with intervening existential")
2330
case MethodType(h :: t, restpe) if h.isImplicit =>
@@ -60,4 +67,4 @@ trait UnCurry {
6067
*/
6168
def transformInfo(sym: Symbol, tp: Type): Type =
6269
if (sym.isType) uncurryType(tp) else uncurry(tp)
63-
}
70+
}

0 commit comments

Comments
 (0)