@@ -34,6 +34,9 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
34
34
private var symmetricOperations : Set [Symbol ] = null
35
35
var optimize = false
36
36
37
+
38
+ override val cpy = tpd.cpy
39
+
37
40
override def prepareForUnit (tree : Tree )(implicit ctx : Context ): TreeTransform = {
38
41
SeqFactoryClass = ctx.requiredClass(" scala.collection.generic.SeqFactory" )
39
42
symmetricOperations = Set (defn.Boolean_&& , defn.Boolean_|| , defn.Int_+ , defn.Int_* , defn.Long_+ , defn.Long_* )
@@ -118,7 +121,7 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
118
121
transformers = transformers.tail
119
122
}
120
123
}
121
- if (rhs0 ne tree.rhs) cpy.DefDef (tree)(rhs = rhs0)
124
+ if (rhs0 ne tree.rhs) tpd. cpy.DefDef (tree)(rhs = rhs0)
122
125
else tree
123
126
} else tree
124
127
}
@@ -539,8 +542,8 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
539
542
540
543
def splitWrites (t : Tree , target : Symbol ): Tree = {
541
544
t match {
542
- case tree@ Block (stats, expr) => cpy.Block (tree)(stats, splitWrites(expr, target))
543
- case tree@ If (_, thenp, elsep) => cpy.If (tree)(thenp = splitWrites(thenp, target), elsep = splitWrites(elsep, target))
545
+ case tree@ Block (stats, expr) => tpd. cpy.Block (tree)(stats, splitWrites(expr, target))
546
+ case tree@ If (_, thenp, elsep) => tpd. cpy.If (tree)(thenp = splitWrites(thenp, target), elsep = splitWrites(elsep, target))
544
547
case Apply (sel , args) if sel.symbol.isConstructor && t.tpe.widenDealias == target.info.widenDealias.finalResultType.widenDealias =>
545
548
val fieldsByAccessors = newMappings(target)
546
549
var accessors = target.info.classSymbol.caseAccessors.filter(_.isGetter) // TODO: when is this filter needed?
@@ -588,7 +591,7 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
588
591
case ddef : DefDef if ddef.symbol.is(Label ) =>
589
592
newMappings.get(followCases(ddef.symbol)) match {
590
593
case Some (mappings) =>
591
- cpy.DefDef (ddef)(rhs = splitWrites(ddef.rhs, followCases(ddef.symbol)))
594
+ tpd. cpy.DefDef (ddef)(rhs = splitWrites(ddef.rhs, followCases(ddef.symbol)))
592
595
case _ => ddef
593
596
}
594
597
case a : ValDef if toSplit.contains(a.symbol) =>
@@ -597,7 +600,7 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
597
600
val newFields = newMappings(a.symbol).values.toSet
598
601
Thicket (
599
602
newFields.map(x => ValDef (x.asTerm, defaultValue(x.symbol.info.widenDealias))).toList :::
600
- List (cpy.ValDef (a)(rhs = splitWrites(a.rhs, a.symbol))))
603
+ List (tpd. cpy.ValDef (a)(rhs = splitWrites(a.rhs, a.symbol))))
601
604
case ass : Assign =>
602
605
newMappings.get(ass.lhs.symbol) match {
603
606
case None => ass
@@ -685,7 +688,7 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
685
688
}
686
689
val nthenp = dropGoodCastsInStats.transform(thenp)
687
690
688
- cpy.If (t)(thenp = nthenp, elsep = elsep)
691
+ tpd. cpy.If (t)(thenp = nthenp, elsep = elsep)
689
692
case t => t
690
693
}
691
694
(" dropGoodCasts" , BeforeAndAfterErasure , NoVisitor , transformer)
@@ -824,7 +827,7 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
824
827
val nthenp = keepOnlySideEffects(thenp)
825
828
val nelsep = keepOnlySideEffects(elsep)
826
829
if (thenp.isEmpty && elsep.isEmpty) keepOnlySideEffects(cond)
827
- else cpy.If (t)(
830
+ else tpd. cpy.If (t)(
828
831
thenp = nthenp.orElse(if (thenp.isInstanceOf [Literal ]) thenp else unitLiteral),
829
832
elsep = nelsep.orElse(if (elsep.isInstanceOf [Literal ]) elsep else unitLiteral))
830
833
case Select (rec, _) if
@@ -845,7 +848,7 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
845
848
case t : Literal if t.tpe.derivesFrom(defn.UnitClass ) => expr
846
849
case _ => keepOnlySideEffects(expr).orElse(unitLiteral)
847
850
}
848
- cpy.Block (bl)(stats2, expr2)
851
+ tpd. cpy.Block (bl)(stats2, expr2)
849
852
case t : Ident if ! t.symbol.is(Method | Lazy ) && ! t.symbol.info.isInstanceOf [ExprType ] =>
850
853
desugarIdent(t) match {
851
854
case Some (t) => t
@@ -914,7 +917,7 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
914
917
case _ => (newStats1, a.expr)
915
918
}
916
919
if (newStats2.nonEmpty)
917
- cpy.Block (a)(stats = newStats2, newExpr)
920
+ tpd. cpy.Block (a)(stats = newStats2, newExpr)
918
921
else newExpr
919
922
case a : DefDef =>
920
923
if (a.symbol.info.finalResultType.derivesFrom(defn.UnitClass ) &&
@@ -924,7 +927,7 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
924
927
if (! t.tpe.derivesFrom(defn.UnitClass )) Block (t :: Nil , unitLiteral)
925
928
else t
926
929
}
927
- cpy.DefDef (a)(rhs = insertUnit(keepOnlySideEffects(a.rhs)), tpt = TypeTree (defn.UnitType ))
930
+ tpd. cpy.DefDef (a)(rhs = insertUnit(keepOnlySideEffects(a.rhs)), tpt = TypeTree (defn.UnitType ))
928
931
} else a
929
932
case t => t
930
933
}
@@ -1120,7 +1123,7 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
1120
1123
}
1121
1124
1122
1125
if (newStats eq t.stats) t
1123
- else cpy.Block (t)(newStats, t.expr)
1126
+ else tpd. cpy.Block (t)(newStats, t.expr)
1124
1127
case tree => tree
1125
1128
}
1126
1129
0 commit comments