@@ -67,10 +67,26 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
6767 */
6868 var fuel : Int = - 1
6969
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+
7078 override def prepareForUnit (tree : Tree )(implicit ctx : Context ) = {
7179 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" )
7282 if (fuel < 0 && maxFuel > 0 ) // Both defaults are at -1
7383 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+ }
7490 this
7591 }
7692
@@ -79,17 +95,12 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
7995 val ctx0 = ctx
8096 if (ctx.settings.optimise.value && ! tree.symbol.is(Label )) {
8197 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+
8899 var rhs0 = tree.rhs
89100 var rhs1 : Tree = null
90101 while (rhs1 ne rhs0) {
91102 rhs1 = rhs0
92- val context = ctx.withOwner(tree.symbol)
103+ // val context = ctx.withOwner(tree.symbol)
93104 optimisations.foreach { optimisation => // TODO: fuse for performance
94105 // Visit
95106 rhs0.foreachSubTree(optimisation.visitor)
@@ -100,12 +111,12 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
100111 val innerCtx = if (tree.isDef && tree.symbol.exists) ctx.withOwner(tree.symbol) else ctx
101112 val childOptimizedTree = super .transform(tree)(innerCtx)
102113
103- if (fuel == 0 )
114+ if (useFuel && fuel == 0 )
104115 childOptimizedTree
105116 else {
106117 val fullyOptimizedTree = optimisation.transformer(ctx)(childOptimizedTree)
107118
108- if (tree ne fullyOptimizedTree) {
119+ if (useFuel && ( tree ne fullyOptimizedTree) ) {
109120 if (fuel > 0 ) fuel -= 1
110121 if (fuel != - 1 && fuel < 10 ) {
111122 println(s " ${tree.symbol} was simplified by ${optimisation.name} (fuel= $fuel): ${tree.show}" )
0 commit comments