Skip to content

Commit 9c152e8

Browse files
DropNoEffects: Remove TypeApply case, this is covered by DropGoodCasts
1 parent 0ed8e0a commit 9c152e8

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

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

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,27 +67,38 @@ import transform.SymUtils._
6767
def collectTypeTests(t: Tree)(implicit ctx: Context): List[(Symbol, Type)] = {
6868
def recur(t: Tree): List[(Symbol, Type)] =
6969
t match {
70-
case Apply(x, _) if (x.symbol == defn.Boolean_! || x.symbol == defn.Boolean_||) => List.empty
71-
case Apply(fun @ Select(x, _), y) if (fun.symbol == defn.Boolean_&&) => recur(x) ++ recur(y.head)
72-
case TypeApply(fun @ Select(x, _), List(tp)) if fun.symbol eq defn.Any_isInstanceOf =>
73-
if (x.symbol.exists && !x.symbol.owner.isClass && !x.symbol.is(Method|Mutable))
74-
(x.symbol, tp.tpe) :: Nil
75-
else Nil
76-
case _ => List.empty
70+
case Apply(x, _) if (x.symbol == defn.Boolean_! || x.symbol == defn.Boolean_||) =>
71+
Nil
72+
73+
case Apply(fun @ Select(x, _), y) if (fun.symbol == defn.Boolean_&&) =>
74+
recur(x) ++ recur(y.head)
75+
76+
case TypeApply(fun @ Select(x, _), List(tp))
77+
if fun.symbol.eq(defn.Any_isInstanceOf) &&
78+
!x.symbol.is(Method | Mutable) &&
79+
x.symbol.exists && !x.symbol.owner.isClass =>
80+
(x.symbol, tp.tpe) :: Nil
81+
82+
case _ => Nil
7783
}
7884
recur(t)
7985
}
8086

8187
def collectNullTests(t: Tree)(implicit ctx: Context): List[Symbol] = {
8288
def recur(t: Tree): List[Symbol] =
8389
t match {
84-
case Apply(x, _) if (x.symbol == defn.Boolean_! || x.symbol == defn.Boolean_||) => List.empty
85-
case Apply(fun @ Select(x, _), y) if (fun.symbol == defn.Boolean_&&) => recur(x) ++ recur(y.head)
86-
case Apply(fun @ Select(x, _), List(tp)) if fun.symbol eq defn.Object_ne =>
87-
if (x.symbol.exists && !x.symbol.owner.isClass && !x.symbol.is(Method|Mutable))
88-
x.symbol :: Nil
89-
else Nil
90-
case _ => List.empty
90+
case Apply(x, _) if (x.symbol == defn.Boolean_! || x.symbol == defn.Boolean_||) => Nil
91+
92+
case Apply(fun @ Select(x, _), y) if (fun.symbol == defn.Boolean_&&) =>
93+
recur(x) ++ recur(y.head)
94+
95+
case Apply(fun @ Select(x, _), List(tp))
96+
if fun.symbol.eq(defn.Object_ne) &&
97+
!x.symbol.is(Method | Mutable) &&
98+
x.symbol.exists && !x.symbol.owner.isClass =>
99+
x.symbol :: Nil
100+
101+
case _ => Nil
91102
}
92103
recur(t)
93104
}

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,6 @@ class DropNoEffects(val simplifyPhase: Simplify)(implicit val ctx: Context) exte
142142
}
143143
Block(prefix, unitLiteral)
144144

145-
case t @ TypeApply(Select(rec, _), List(testType)) if t.symbol.eq(defn.Any_asInstanceOf) && testType.tpe.widenDealias.typeSymbol.exists =>
146-
val receiverType = TypeErasure.erasure(rec.tpe)
147-
val erazedTestedType = TypeErasure.erasure(testType.tpe)
148-
if (receiverType.derivesFrom(erazedTestedType.typeSymbol))
149-
rec
150-
else t
151-
152145
case t => t
153146
}
154147

0 commit comments

Comments
 (0)