Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(169)

Unified Diff: pkg/compiler/lib/src/closure.dart

Issue 1409933004: dart2js: Fix marking of boxed loop variables. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Add comment Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/language/language_dart2js.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/closure.dart
diff --git a/pkg/compiler/lib/src/closure.dart b/pkg/compiler/lib/src/closure.dart
index da13773cc34c247e567a2aa38ac694ee64c1fe2d..d630beb80c19a9adbd6f9445a92c29553e6a255f 100644
--- a/pkg/compiler/lib/src/closure.dart
+++ b/pkg/compiler/lib/src/closure.dart
@@ -906,6 +906,7 @@ class ClosureTranslator extends Visitor {
}
visitFor(For node) {
+ List<LocalVariableElement> boxedLoopVariables = <LocalVariableElement>[];
inNewScope(node, () {
// First visit initializer and update so we can easily check if a loop
// variable was captured in one of these subexpressions.
@@ -929,24 +930,27 @@ class ClosureTranslator extends Visitor {
// condition or body are indeed flagged as mutated.
if (node.conditionStatement != null) visit(node.conditionStatement);
if (node.body != null) visit(node.body);
+
+ // See if we have declared loop variables that need to be boxed.
+ if (node.initializer == null) return;
+ VariableDefinitions definitions =
+ node.initializer.asVariableDefinitions();
+ if (definitions == null) return;
+ for (Link<Node> link = definitions.definitions.nodes;
+ !link.isEmpty;
+ link = link.tail) {
+ Node definition = link.head;
+ LocalVariableElement element = elements[definition];
+ // Non-mutated variables should not be boxed. The mutatedVariables set
+ // gets cleared when 'inNewScope' returns, so check it here.
+ if (isCapturedVariable(element) && mutatedVariables.contains(element)) {
+ boxedLoopVariables.add(element);
+ }
+ }
});
- // See if we have declared loop variables that need to be boxed.
- if (node.initializer == null) return;
- VariableDefinitions definitions = node.initializer.asVariableDefinitions();
- if (definitions == null) return;
ClosureScope scopeData = closureData.capturingScopes[node];
if (scopeData == null) return;
- List<LocalVariableElement> result = <LocalVariableElement>[];
- for (Link<Node> link = definitions.definitions.nodes;
- !link.isEmpty;
- link = link.tail) {
- Node definition = link.head;
- LocalVariableElement element = elements[definition];
- if (isCapturedVariable(element)) {
- result.add(element);
- }
- }
- scopeData.boxedLoopVariables = result;
+ scopeData.boxedLoopVariables = boxedLoopVariables;
}
/** Returns a non-unique name for the given closure element. */
« no previous file with comments | « no previous file | tests/language/language_dart2js.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698