@@ -205,12 +205,12 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
205205 */
206206 val inlineCaseIntrinsics : Optimization = { implicit ctx : Context =>
207207 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 ) &&
214214 (isPureExpr(a.fun) || a.fun.symbol.is(Synthetic )) =>
215215 def unrollArgs (t : Tree , l : List [List [Tree ]]): List [List [Tree ]] = t match {
216216 case Apply (t, args) => unrollArgs(t, args :: l)
@@ -224,11 +224,11 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
224224 val constructor = a.symbol.owner.companionClass.primaryConstructor.asTerm
225225 rollInArgs(argss.tail, New (a.tpe.widenDealias, constructor, argss.head))
226226
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 ) &&
232232 (isPureExpr(a.fun) || a.fun.symbol.is(Synthetic )) =>
233233 if (! a.symbol.owner.is(Scala2x )) {
234234 if (a.tpe.derivesFrom(defn.BooleanClass )) Literal (Constant (true ))
@@ -474,7 +474,9 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
474474 }
475475 }
476476 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 )) =>
478480 followTailPerfect(vdef.rhs, vdef.symbol)
479481 case Assign (lhs, rhs) if ! lhs.symbol.owner.isClass =>
480482 checkGood.put(lhs.symbol, checkGood.getOrElse(lhs.symbol, Set .empty) + rhs.symbol)
@@ -898,7 +900,9 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
898900 cpy.Block (a)(stats = newStats2, newExpr)
899901 else newExpr
900902 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 )) {
902906 def insertUnit (t : Tree ) = {
903907 if (! t.tpe.derivesFrom(defn.UnitClass )) Block (t :: Nil , unitLiteral)
904908 else t
@@ -1050,7 +1054,7 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
10501054 defined(t.symbol) = t
10511055 case t : RefTree if t.symbol.exists && ! t.symbol.is(Method ) && ! t.symbol.owner.isClass =>
10521056 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 =>
10541058 if (! firstRead.contains(l.symbol)) {
10551059 if (firstWrite.contains(l.symbol)) {
10561060 if (! secondWrite.contains(l.symbol))
@@ -1116,8 +1120,7 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
11161120 // Either a duplicate or a read through series of immutable fields
11171121 val copies = mutable.HashMap [Symbol , Tree ]()
11181122 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 ) &&
11211124 valdef.symbol.exists && ! valdef.symbol.owner.isClass =>
11221125 defined += valdef.symbol
11231126
@@ -1171,7 +1174,7 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
11711174 val valsToDrop = defined -- timesUsed.keySet
11721175 val copiesToReplaceAsDuplicates = copies.filter { x =>
11731176 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 ))
11751178 }
11761179 // TODO: if a non-synthetic val is duplicate of a synthetic one, rename a synthetic one and drop synthetic flag?
11771180
@@ -1216,7 +1219,7 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
12161219 New (newTpt)
12171220 }
12181221 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 ) =>
12201223 if (replacements.contains(t.symbol))
12211224 deepReplacer.transform(replacements(t.symbol)).ensureConforms(t.tpe.widen)
12221225 else t
0 commit comments