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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/closure.dart

Issue 12385076: Infer types of catpured variables and use the types in the SSA builder. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/ssa/builder.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library closureToClassMapper; 5 library closureToClassMapper;
6 6
7 import "elements/elements.dart"; 7 import "elements/elements.dart";
8 import "dart2jslib.dart"; 8 import "dart2jslib.dart";
9 import "dart_types.dart"; 9 import "dart_types.dart";
10 import "scanner/scannerlib.dart" show Token; 10 import "scanner/scannerlib.dart" show Token;
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 this.callElement, 186 this.callElement,
187 this.thisElement) 187 this.thisElement)
188 : this.freeVariableMapping = new Map<Element, Element>(), 188 : this.freeVariableMapping = new Map<Element, Element>(),
189 this.capturedFieldMapping = new Map<Element, Element>(), 189 this.capturedFieldMapping = new Map<Element, Element>(),
190 this.capturingScopes = new Map<Node, ClosureScope>(), 190 this.capturingScopes = new Map<Node, ClosureScope>(),
191 this.usedVariablesInTry = new Set<Element>(), 191 this.usedVariablesInTry = new Set<Element>(),
192 this.parametersWithSentinel = new Map<Element, Element>(); 192 this.parametersWithSentinel = new Map<Element, Element>();
193 193
194 bool isClosure() => closureElement != null; 194 bool isClosure() => closureElement != null;
195 195
196 bool captures(Element element) => freeVariableMapping.containsKey(element); 196 bool isVariableCaptured(Element element) {
197 freeVariableMapping.containsKey(element);
198 }
197 199
198 bool mutates(Element element) { 200 bool isVariableBoxed(Element element) {
199 Element copy = freeVariableMapping[element]; 201 Element copy = freeVariableMapping[element];
200 return copy != null && !copy.isMember(); 202 return copy != null && !copy.isMember();
201 } 203 }
202 204
203 void forEachCapturedVariable(void f(Element element)) { 205 void forEachCapturedVariable(void f(Element element)) {
204 freeVariableMapping.forEach((variable, _) { 206 freeVariableMapping.forEach((variable, _) {
205 if (variable is BoxElement) return; 207 if (variable is BoxElement) return;
206 f(variable); 208 f(variable);
207 }); 209 });
208 } 210 }
211
212 void forEachBoxedVariable(void f(Element element)) {
karlklose 2013/03/05 09:57:24 Is this function used?
ngeoffray 2013/03/05 10:18:45 No, but I'd like to come up with some abstractions
213 freeVariableMapping.forEach((variable, copy) {
214 if (!isVariableBoxed(variable)) return;
215 f(variable);
216 });
217 }
218
219 void forEachNonBoxedCapturedVariable(void f(Element element)) {
220 freeVariableMapping.forEach((variable, copy) {
221 if (variable is BoxElement) return;
222 if (isVariableBoxed(variable)) return;
223 f(variable);
224 });
225 }
209 } 226 }
210 227
211 class ClosureTranslator extends Visitor { 228 class ClosureTranslator extends Visitor {
212 final Compiler compiler; 229 final Compiler compiler;
213 final TreeElements elements; 230 final TreeElements elements;
214 int closureFieldCounter = 0; 231 int closureFieldCounter = 0;
215 int boxedFieldCounter = 0; 232 int boxedFieldCounter = 0;
216 bool inTryStatement = false; 233 bool inTryStatement = false;
217 final Map<Node, ClosureClassMap> closureMappingCache; 234 final Map<Node, ClosureClassMap> closureMappingCache;
218 235
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 } 686 }
670 687
671 visitTryStatement(TryStatement node) { 688 visitTryStatement(TryStatement node) {
672 // TODO(ngeoffray): implement finer grain state. 689 // TODO(ngeoffray): implement finer grain state.
673 bool oldInTryStatement = inTryStatement; 690 bool oldInTryStatement = inTryStatement;
674 inTryStatement = true; 691 inTryStatement = true;
675 node.visitChildren(this); 692 node.visitChildren(this);
676 inTryStatement = oldInTryStatement; 693 inTryStatement = oldInTryStatement;
677 } 694 }
678 } 695 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/ssa/builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698