Index: pkg/compiler/lib/src/tree_ir/optimization/statement_rewriter.dart |
diff --git a/pkg/compiler/lib/src/tree_ir/optimization/statement_rewriter.dart b/pkg/compiler/lib/src/tree_ir/optimization/statement_rewriter.dart |
index 5cd7ee7f9e1fdb4605dd0641ea1a901bee7b4e07..4949bc9539bc7be5d801f8b105e475eb72de9044 100644 |
--- a/pkg/compiler/lib/src/tree_ir/optimization/statement_rewriter.dart |
+++ b/pkg/compiler/lib/src/tree_ir/optimization/statement_rewriter.dart |
@@ -207,15 +207,19 @@ class StatementRewriter extends Transformer implements Pass { |
return newJump != null ? newJump : jump; |
} |
- void inEmptyEnvironment(void action()) { |
+ void inEmptyEnvironment(void action(), {bool keepConstants: true}) { |
List oldEnvironment = environment; |
Map oldConstantEnvironment = constantEnvironment; |
environment = <Expression>[]; |
- constantEnvironment = <Variable, Expression>{}; |
+ if (!keepConstants) { |
+ constantEnvironment = <Variable, Expression>{}; |
+ } |
action(); |
assert(environment.isEmpty); |
environment = oldEnvironment; |
- constantEnvironment = oldConstantEnvironment; |
+ if (!keepConstants) { |
+ constantEnvironment = oldConstantEnvironment; |
+ } |
} |
/// Left-hand side of the given assignment, or `null` if not an assignment. |
@@ -657,9 +661,11 @@ class StatementRewriter extends Transformer implements Pass { |
Statement visitWhileTrue(WhileTrue node) { |
// Do not propagate assignments into loops. Doing so is not safe for |
// variables modified in the loop (the initial value will be propagated). |
+ // Do not propagate effective constant expressions into loops, since |
+ // computing them is not free (e.g. interceptors are expensive). |
inEmptyEnvironment(() { |
node.body = visitStatement(node.body); |
- }); |
+ }, keepConstants: false); |
return node; |
} |