@@ -205,12 +205,12 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
205
205
*/
206
206
val inlineCaseIntrinsics : Optimization = { implicit ctx : Context =>
207
207
val transformer : Transformer = () => localCtx => {
208
- case a : Apply if ! a.tpe.isInstanceOf [MethodicType ] &&
209
- a.symbol.is(Synthetic ) &&
210
- a.symbol.owner.is(Module ) &&
211
- (a.symbol.name == nme.apply) &&
212
- a.symbol.owner.companionClass.is(CaseClass ) &&
213
- ! a.tpe.derivesFrom(defn.EnumClass ) &&
208
+ case a : Apply if ! a.tpe.isInstanceOf [MethodicType ] &&
209
+ a.symbol.is(Synthetic ) &&
210
+ a.symbol.owner.is(Module ) &&
211
+ (a.symbol.name == nme.apply) &&
212
+ a.symbol.owner.companionClass.is(CaseClass ) &&
213
+ ! a.tpe.derivesFrom(defn.EnumClass ) &&
214
214
(isPureExpr(a.fun) || a.fun.symbol.is(Synthetic )) =>
215
215
def unrollArgs (t : Tree , l : List [List [Tree ]]): List [List [Tree ]] = t match {
216
216
case Apply (t, args) => unrollArgs(t, args :: l)
@@ -224,11 +224,11 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
224
224
val constructor = a.symbol.owner.companionClass.primaryConstructor.asTerm
225
225
rollInArgs(argss.tail, New (a.tpe.widenDealias, constructor, argss.head))
226
226
227
- case a : Apply if a.symbol.is(Synthetic ) &&
228
- a.symbol.owner.is(Module ) &&
229
- (a.symbol.name == nme.unapply) &&
230
- a.symbol.owner.companionClass.is(CaseClass ) &&
231
- ! a.tpe.derivesFrom(defn.EnumClass ) &&
227
+ case a : Apply if a.symbol.is(Synthetic ) &&
228
+ a.symbol.owner.is(Module ) &&
229
+ (a.symbol.name == nme.unapply) &&
230
+ a.symbol.owner.companionClass.is(CaseClass ) &&
231
+ ! a.tpe.derivesFrom(defn.EnumClass ) &&
232
232
(isPureExpr(a.fun) || a.fun.symbol.is(Synthetic )) =>
233
233
if (! a.symbol.owner.is(Scala2x )) {
234
234
if (a.tpe.derivesFrom(defn.BooleanClass )) Literal (Constant (true ))
@@ -474,7 +474,9 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
474
474
}
475
475
}
476
476
val visitor : Visitor = {
477
- case vdef : ValDef if (vdef.symbol.info.classSymbol is CaseClass ) && ! vdef.symbol.is(Lazy ) && ! vdef.symbol.info.classSymbol.caseAccessors.exists(x => x.is(Mutable )) =>
477
+ case vdef : ValDef if (vdef.symbol.info.classSymbol is CaseClass ) &&
478
+ ! vdef.symbol.is(Lazy ) &&
479
+ ! vdef.symbol.info.classSymbol.caseAccessors.exists(x => x.is(Mutable )) =>
478
480
followTailPerfect(vdef.rhs, vdef.symbol)
479
481
case Assign (lhs, rhs) if ! lhs.symbol.owner.isClass =>
480
482
checkGood.put(lhs.symbol, checkGood.getOrElse(lhs.symbol, Set .empty) + rhs.symbol)
@@ -898,7 +900,9 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
898
900
cpy.Block (a)(stats = newStats2, newExpr)
899
901
else newExpr
900
902
case a : DefDef =>
901
- if (a.symbol.info.finalResultType.derivesFrom(defn.UnitClass ) && ! a.rhs.tpe.derivesFrom(defn.UnitClass ) && ! a.rhs.tpe.derivesFrom(defn.NothingClass )) {
903
+ if (a.symbol.info.finalResultType.derivesFrom(defn.UnitClass ) &&
904
+ ! a.rhs.tpe.derivesFrom(defn.UnitClass ) &&
905
+ ! a.rhs.tpe.derivesFrom(defn.NothingClass )) {
902
906
def insertUnit (t : Tree ) = {
903
907
if (! t.tpe.derivesFrom(defn.UnitClass )) Block (t :: Nil , unitLiteral)
904
908
else t
@@ -1050,7 +1054,7 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
1050
1054
defined(t.symbol) = t
1051
1055
case t : RefTree if t.symbol.exists && ! t.symbol.is(Method ) && ! t.symbol.owner.isClass =>
1052
1056
if (! firstWrite.contains(t.symbol)) firstRead(t.symbol) = t
1053
- case t @ Assign (l, expr) if ! l.symbol.is(Method ) && ! l.symbol.owner.isClass =>
1057
+ case t @ Assign (l, expr) if ! l.symbol.is(Method ) && ! l.symbol.owner.isClass =>
1054
1058
if (! firstRead.contains(l.symbol)) {
1055
1059
if (firstWrite.contains(l.symbol)) {
1056
1060
if (! secondWrite.contains(l.symbol))
@@ -1116,8 +1120,7 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
1116
1120
// Either a duplicate or a read through series of immutable fields
1117
1121
val copies = mutable.HashMap [Symbol , Tree ]()
1118
1122
def doVisit (tree : Tree , used : mutable.HashMap [Symbol , Int ]): Unit = tree match {
1119
- case valdef : ValDef if ! valdef.symbol.is(Param ) &&
1120
- ! valdef.symbol.is(Mutable | Module | Lazy ) &&
1123
+ case valdef : ValDef if ! valdef.symbol.is(Param | Mutable | Module | Lazy ) &&
1121
1124
valdef.symbol.exists && ! valdef.symbol.owner.isClass =>
1122
1125
defined += valdef.symbol
1123
1126
@@ -1171,7 +1174,7 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
1171
1174
val valsToDrop = defined -- timesUsed.keySet
1172
1175
val copiesToReplaceAsDuplicates = copies.filter { x =>
1173
1176
val rhs = dropCasts(x._2)
1174
- rhs.isInstanceOf [Literal ] || (! rhs.symbol.owner.isClass && ! rhs.symbol.is(Method ) && ! rhs.symbol.is( Mutable ))
1177
+ rhs.isInstanceOf [Literal ] || (! rhs.symbol.owner.isClass && ! rhs.symbol.is(Method | Mutable ))
1175
1178
}
1176
1179
// TODO: if a non-synthetic val is duplicate of a synthetic one, rename a synthetic one and drop synthetic flag?
1177
1180
@@ -1216,7 +1219,7 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
1216
1219
New (newTpt)
1217
1220
}
1218
1221
else t
1219
- case t : RefTree if ! t.symbol.is(Method ) && ! t.symbol.is( Param ) && ! t.symbol.is( Mutable ) =>
1222
+ case t : RefTree if ! t.symbol.is(Method | Param | Mutable ) =>
1220
1223
if (replacements.contains(t.symbol))
1221
1224
deepReplacer.transform(replacements(t.symbol)).ensureConforms(t.tpe.widen)
1222
1225
else t
0 commit comments