Skip to content

Commit 31437f7

Browse files
committed
Optimise away erased phantom statements
1 parent 2a72ffb commit 31437f7

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

compiler/src/dotty/tools/dotc/transform/localopt/Simplify.scala

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
6060
new Devalify ::
6161
new Jumpjump ::
6262
new DropGoodCasts ::
63+
new DropNoEffects(this) ::
6364
new ConstantFold(this) ::
6465
Nil
6566

@@ -168,13 +169,16 @@ object Simplify {
168169
}
169170

170171
def isImmutableAccessor(t: Tree)(implicit ctx: Context): Boolean = {
171-
val isImmutableGetter = t.symbol.isGetter && !t.symbol.is(Mutable | Lazy)
172-
val isCaseAccessor = t.symbol.is(CaseAccessor) && !t.symbol.is(Mutable | Lazy)
173-
val isProductAccessor = t.symbol.exists &&
174-
t.symbol.owner.derivesFrom(defn.ProductClass) &&
175-
t.symbol.owner.is(CaseClass) &&
176-
t.symbol.name.isSelectorName &&
177-
!t.symbol.info.decls.exists(_.is(Mutable | Lazy)) // Conservatively covers case class A(var x: Int)
178-
isImmutableGetter || isCaseAccessor || isProductAccessor
172+
val sym = t.symbol
173+
val isImmutableGetter = sym.isGetter && !sym.is(Mutable | Lazy)
174+
val isCaseAccessor = sym.is(CaseAccessor) && !sym.is(Mutable | Lazy)
175+
val isProductAccessor = sym.exists &&
176+
sym.owner.derivesFrom(defn.ProductClass) &&
177+
sym.owner.is(CaseClass) &&
178+
sym.name.isSelectorName &&
179+
!sym.info.decls.exists(_.is(Mutable | Lazy)) // Conservatively covers case class A(var x: Int)
180+
val isBoxedUnit = (sym eq defn.BoxedUnit_UNIT) ||
181+
(sym eq defn.ErasedPhantom_UNIT)
182+
isImmutableGetter || isCaseAccessor || isProductAccessor || isBoxedUnit
179183
}
180184
}

0 commit comments

Comments
 (0)