@@ -11,7 +11,12 @@ import ast.Trees._
11
11
import transform .SymUtils ._
12
12
import Simplify .desugarIdent
13
13
14
- /** Inline case class specific methods using desugarings assumptions. */
14
+ /** Inline case class specific methods using desugarings assumptions.
15
+ *
16
+ * Note: to run this optimisation after erasure one would need to specialize
17
+ * it for constructor with outer pointer and values classes. There is
18
+ * probably no need to run this more than once.
19
+ */
15
20
class InlineCaseIntrinsics (implicit val ctx : Context ) extends Optimisation {
16
21
import ast .tpd ._
17
22
@@ -20,13 +25,14 @@ class InlineCaseIntrinsics(implicit val ctx: Context) extends Optimisation {
20
25
def transformer (localCtx : Context ): Tree => Tree = {
21
26
// For synthetic applies on case classes (both dotty/scalac)
22
27
// - CC.apply(args) → new CC(args)
23
- case a : Apply if ! a.tpe.isInstanceOf [MethodicType ] &&
24
- a.symbol.is(Synthetic ) &&
25
- a.symbol.owner.is(Module ) &&
26
- (a.symbol.name == nme.apply) &&
27
- a.symbol.owner.companionClass.is(CaseClass ) &&
28
- ! a.tpe.derivesFrom(defn.EnumClass ) &&
29
- (isPureExpr(a.fun) || a.fun.symbol.is(Synthetic )) =>
28
+ case a : Apply
29
+ if ! a.tpe.isInstanceOf [MethodicType ] &&
30
+ a.symbol.is(Synthetic ) &&
31
+ a.symbol.owner.is(Module ) &&
32
+ a.symbol.name == nme.apply &&
33
+ a.symbol.owner.companionClass.is(CaseClass ) &&
34
+ ! a.tpe.derivesFrom(defn.EnumClass ) &&
35
+ (isPureExpr(a.fun) || a.fun.symbol.is(Synthetic )) =>
30
36
31
37
def unrollArgs (t : Tree , l : List [List [Tree ]]): List [List [Tree ]] = t match {
32
38
case Apply (t, args) => unrollArgs(t, args :: l)
@@ -44,12 +50,13 @@ class InlineCaseIntrinsics(implicit val ctx: Context) extends Optimisation {
44
50
// - CC.unapply(arg): CC → arg
45
51
// - CC.unapply(arg): Boolean → true, dotty only
46
52
// - CC.unapply(arg): Option[CC] → new Some(new scala.TupleN(arg._1, ..., arg._N))
47
- case a : Apply if a.symbol.is(Synthetic ) &&
48
- a.symbol.owner.is(Module ) &&
49
- (a.symbol.name == nme.unapply) &&
50
- a.symbol.owner.companionClass.is(CaseClass ) &&
51
- ! a.tpe.derivesFrom(defn.EnumClass ) &&
52
- (isPureExpr(a.fun) || a.fun.symbol.is(Synthetic )) =>
53
+ case a : Apply
54
+ if a.symbol.is(Synthetic ) &&
55
+ a.symbol.owner.is(Module ) &&
56
+ a.symbol.name == nme.unapply &&
57
+ a.symbol.owner.companionClass.is(CaseClass ) &&
58
+ ! a.tpe.derivesFrom(defn.EnumClass ) &&
59
+ (isPureExpr(a.fun) || a.fun.symbol.is(Synthetic )) =>
53
60
54
61
val args = a.args.head
55
62
val isDottyUnapply = ! a.symbol.owner.is(Scala2x )
@@ -88,10 +95,11 @@ class InlineCaseIntrinsics(implicit val ctx: Context) extends Optimisation {
88
95
89
96
// Seq.unapplySeq(arg) → new Some(arg)
90
97
// Where Seq is any companion of type <: SeqFactoryClass
91
- case a : Apply if (a.symbol.name == nme.unapplySeq) &&
92
- a.symbol.owner.derivesFrom(defn.SeqFactoryClass ) &&
93
- a.symbol.extendedOverriddenSymbols.isEmpty &&
94
- (isPureExpr(a.fun) || a.fun.symbol.is(Synthetic )) =>
98
+ case a : Apply
99
+ if a.symbol.name == nme.unapplySeq &&
100
+ a.symbol.owner.derivesFrom(defn.SeqFactoryClass ) &&
101
+ a.symbol.extendedOverriddenSymbols.isEmpty &&
102
+ (isPureExpr(a.fun) || a.fun.symbol.is(Synthetic )) =>
95
103
96
104
def receiver (t : Tree ): Type = t match {
97
105
case t : Apply => receiver(t.fun)
@@ -127,8 +135,4 @@ class InlineCaseIntrinsics(implicit val ctx: Context) extends Optimisation {
127
135
else
128
136
Block (recv :: Nil , res)
129
137
}
130
-
131
- // To run this optimisation after erasure one would need to specialize it
132
- // for constructor with outer pointer and values classes. There is probably
133
- // no need to run this more than once.
134
138
}
0 commit comments