@@ -3,10 +3,12 @@ package transform.localopt
3
3
4
4
import core .Contexts .Context
5
5
import core .DenotTransformers .IdentityDenotTransformer
6
+ import core .Symbols ._
6
7
import core .Types ._
8
+ import core .Flags ._
9
+ import core .Decorators ._
7
10
import transform .TreeTransforms .{MiniPhaseTransform , TransformerInfo }
8
11
import config .Printers .simplify
9
- import core .Flags ._
10
12
import ast .tpd
11
13
12
14
/** This phase consists of a series of small, simple, local optimisations
@@ -26,14 +28,17 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
26
28
override def phaseName : String = " simplify"
27
29
override val cpy = tpd.cpy
28
30
31
+ private [localopt] var SeqFactoryClass : Symbol = null
32
+ private [localopt] var CommutativePrimitiveOperations : Set [Symbol ] = null
33
+
29
34
/** The original intention is to run most optimizations both before and after erasure.
30
35
* Erasure creates new inefficiencies as well as new optimization opportunities.
31
36
*
32
37
* The order of optimizations is tuned to converge faster.
33
38
* Reordering them may require quadratically more rounds to finish.
34
39
*/
35
40
private def beforeErasure : List [Optimisation ] =
36
- new InlineCaseIntrinsics ::
41
+ new InlineCaseIntrinsics ( this ) ::
37
42
new RemoveUnnecessaryNullChecks ::
38
43
new InlineOptions ::
39
44
new InlineLabelsCalledOnce ::
@@ -45,7 +50,7 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
45
50
// new InlineLocalObjects :: // followCases needs to be fixed, see ./tests/pos/rbtree.scala
46
51
// new Varify :: // varify could stop other transformations from being applied. postponed.
47
52
// new BubbleUpNothing ::
48
- new ConstantFold ::
53
+ new ConstantFold ( this ) ::
49
54
Nil
50
55
51
56
/** See comment on beforeErasure */
@@ -54,7 +59,7 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
54
59
new Devalify ::
55
60
new Jumpjump ::
56
61
new DropGoodCasts ::
57
- new ConstantFold ::
62
+ new ConstantFold ( this ) ::
58
63
Nil
59
64
60
65
/** Optimisation fuel, for debugging. Decremented every time Simplify
@@ -68,6 +73,8 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
68
73
var fuel : Int = - 1
69
74
70
75
override def prepareForUnit (tree : Tree )(implicit ctx : Context ) = {
76
+ SeqFactoryClass = ctx.requiredClass(" scala.collection.generic.SeqFactory" )
77
+ CommutativePrimitiveOperations = Set (defn.Boolean_&& , defn.Boolean_|| , defn.Int_+ , defn.Int_* , defn.Long_+ , defn.Long_* )
71
78
val maxFuel = ctx.settings.YoptFuel .value
72
79
if (fuel < 0 && maxFuel > 0 ) // Both defaults are at -1
73
80
fuel = maxFuel
0 commit comments