@@ -67,10 +67,26 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
67
67
*/
68
68
var fuel : Int = - 1
69
69
70
+
71
+ /** using fuel stops any inlining and prevents optimizations from triggering.
72
+ * on my tests it gives 20% slowdown, so it is going to be disabled in public builds.
73
+ */
74
+ private final val useFuel = false
75
+
76
+ private var optimisations : List [Optimisation ] = _
77
+
70
78
override def prepareForUnit (tree : Tree )(implicit ctx : Context ) = {
71
79
val maxFuel = ctx.settings.YoptFuel .value
80
+ if (! useFuel && maxFuel != ctx.settings.YoptFuel .default)
81
+ ctx.error(" Optimization fuel-debugging requires enabling in source, see Simplify.scala::useFuel" )
72
82
if (fuel < 0 && maxFuel > 0 ) // Both defaults are at -1
73
83
fuel = maxFuel
84
+
85
+ optimisations = {
86
+ val o = if (ctx.erasedTypes) afterErasure else beforeErasure
87
+ val p = ctx.settings.YoptPhases .value
88
+ if (p.isEmpty) o else o.filter(x => p.contains(x.name))
89
+ }
74
90
this
75
91
}
76
92
@@ -79,17 +95,12 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
79
95
val ctx0 = ctx
80
96
if (ctx.settings.optimise.value && ! tree.symbol.is(Label )) {
81
97
implicit val ctx : Context = ctx0.withOwner(tree.symbol(ctx0))
82
- val optimisations = {
83
- val o = if (ctx.erasedTypes) afterErasure else beforeErasure
84
- val p = ctx.settings.YoptPhases .value
85
- if (p.isEmpty) o else o.filter(x => p.contains(x.name))
86
- }
87
-
98
+
88
99
var rhs0 = tree.rhs
89
100
var rhs1 : Tree = null
90
101
while (rhs1 ne rhs0) {
91
102
rhs1 = rhs0
92
- val context = ctx.withOwner(tree.symbol)
103
+ // val context = ctx.withOwner(tree.symbol)
93
104
optimisations.foreach { optimisation => // TODO: fuse for performance
94
105
// Visit
95
106
rhs0.foreachSubTree(optimisation.visitor)
@@ -100,12 +111,12 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
100
111
val innerCtx = if (tree.isDef && tree.symbol.exists) ctx.withOwner(tree.symbol) else ctx
101
112
val childOptimizedTree = super .transform(tree)(innerCtx)
102
113
103
- if (fuel == 0 )
114
+ if (useFuel && fuel == 0 )
104
115
childOptimizedTree
105
116
else {
106
117
val fullyOptimizedTree = optimisation.transformer(ctx)(childOptimizedTree)
107
118
108
- if (tree ne fullyOptimizedTree) {
119
+ if (useFuel && ( tree ne fullyOptimizedTree) ) {
109
120
if (fuel > 0 ) fuel -= 1
110
121
if (fuel != - 1 && fuel < 10 ) {
111
122
println(s " ${tree.symbol} was simplified by ${optimisation.name} (fuel= $fuel): ${tree.show}" )
0 commit comments