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

Side by Side Diff: pkg/compiler/lib/src/ssa/locals_handler.dart

Issue 2931463002: Revert "Entity-ify some portions of LocalsHandler and Closure." (Closed)
Patch Set: Created 3 years, 6 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
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 import '../closure.dart'; 5 import '../closure.dart';
6 import '../common.dart'; 6 import '../common.dart';
7 import '../elements/elements.dart'; 7 import '../elements/elements.dart';
8 import '../elements/entities.dart'; 8 import '../elements/entities.dart';
9 import '../elements/types.dart'; 9 import '../elements/types.dart';
10 import '../io/source_information.dart'; 10 import '../io/source_information.dart';
(...skipping 12 matching lines...) Expand all
23 /// too. 23 /// too.
24 class LocalsHandler { 24 class LocalsHandler {
25 /// The values of locals that can be directly accessed (without redirections 25 /// The values of locals that can be directly accessed (without redirections
26 /// to boxes or closure-fields). 26 /// to boxes or closure-fields).
27 /// 27 ///
28 /// [directLocals] is iterated, so it is "insertion ordered" to make the 28 /// [directLocals] is iterated, so it is "insertion ordered" to make the
29 /// iteration order a function only of insertions and not a function of 29 /// iteration order a function only of insertions and not a function of
30 /// e.g. Element hash codes. I'd prefer to use a SortedMap but some elements 30 /// e.g. Element hash codes. I'd prefer to use a SortedMap but some elements
31 /// don't have source locations for [Elements.compareByPosition]. 31 /// don't have source locations for [Elements.compareByPosition].
32 Map<Local, HInstruction> directLocals = new Map<Local, HInstruction>(); 32 Map<Local, HInstruction> directLocals = new Map<Local, HInstruction>();
33 Map<Local, FieldEntity> redirectionMapping = new Map<Local, FieldEntity>(); 33 Map<Local, CapturedVariable> redirectionMapping =
34 new Map<Local, CapturedVariable>();
34 final GraphBuilder builder; 35 final GraphBuilder builder;
35 ClosureClassMap closureData; 36 ClosureClassMap closureData;
36 Map<TypeVariableType, TypeVariableLocal> typeVariableLocals = 37 Map<TypeVariableType, TypeVariableLocal> typeVariableLocals =
37 new Map<TypeVariableType, TypeVariableLocal>(); 38 new Map<TypeVariableType, TypeVariableLocal>();
38 final Entity executableContext; 39 final Entity executableContext;
39 final MemberEntity memberContext; 40 final MemberEntity memberContext;
40 41
41 /// The class that defines the current type environment or null if no type 42 /// The class that defines the current type environment or null if no type
42 /// variables are in scope. 43 /// variables are in scope.
43 final ClassEntity contextClass; 44 final ClassEntity contextClass;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 builder = other.builder, 118 builder = other.builder,
118 closureData = other.closureData, 119 closureData = other.closureData,
119 _nativeData = other._nativeData, 120 _nativeData = other._nativeData,
120 _interceptorData = other._interceptorData, 121 _interceptorData = other._interceptorData,
121 activationVariables = other.activationVariables, 122 activationVariables = other.activationVariables,
122 cachedTypeOfThis = other.cachedTypeOfThis, 123 cachedTypeOfThis = other.cachedTypeOfThis,
123 cachedTypesOfCapturedVariables = other.cachedTypesOfCapturedVariables; 124 cachedTypesOfCapturedVariables = other.cachedTypesOfCapturedVariables;
124 125
125 /// Redirects accesses from element [from] to element [to]. The [to] element 126 /// Redirects accesses from element [from] to element [to]. The [to] element
126 /// must be a boxed variable or a variable that is stored in a closure-field. 127 /// must be a boxed variable or a variable that is stored in a closure-field.
127 void redirectElement(Local from, FieldEntity to) { 128 void redirectElement(Local from, CapturedVariable to) {
128 assert(redirectionMapping[from] == null); 129 assert(redirectionMapping[from] == null);
129 redirectionMapping[from] = to; 130 redirectionMapping[from] = to;
130 assert(isStoredInClosureField(from) || isBoxed(from)); 131 assert(isStoredInClosureField(from) || isBoxed(from));
131 } 132 }
132 133
133 HInstruction createBox() { 134 HInstruction createBox() {
134 HInstruction box = new HCreateBox(commonMasks.nonNullType); 135 HInstruction box = new HCreateBox(commonMasks.nonNullType);
135 builder.add(box); 136 builder.add(box);
136 return box; 137 return box;
137 } 138 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 redirectElement(from, to); 173 redirectElement(from, to);
173 updateLocal(from, instruction); 174 updateLocal(from, instruction);
174 } else { 175 } else {
175 redirectElement(from, to); 176 redirectElement(from, to);
176 } 177 }
177 }); 178 });
178 } 179 }
179 180
180 /// Replaces the current box with a new box and copies over the given list 181 /// Replaces the current box with a new box and copies over the given list
181 /// of elements from the old box into the new box. 182 /// of elements from the old box into the new box.
182 void updateCaptureBox(Local boxElement, List<Local> toBeCopiedElements) { 183 void updateCaptureBox(
184 BoxLocal boxElement, List<LocalVariableElement> toBeCopiedElements) {
183 // Create a new box and copy over the values from the old box into the 185 // Create a new box and copy over the values from the old box into the
184 // new one. 186 // new one.
185 HInstruction oldBox = readLocal(boxElement); 187 HInstruction oldBox = readLocal(boxElement);
186 HInstruction newBox = createBox(); 188 HInstruction newBox = createBox();
187 for (Local boxedVariable in toBeCopiedElements) { 189 for (LocalVariableElement boxedVariable in toBeCopiedElements) {
188 // [readLocal] uses the [boxElement] to find its box. By replacing it 190 // [readLocal] uses the [boxElement] to find its box. By replacing it
189 // behind its back we can still get to the old values. 191 // behind its back we can still get to the old values.
190 updateLocal(boxElement, oldBox); 192 updateLocal(boxElement, oldBox);
191 HInstruction oldValue = readLocal(boxedVariable); 193 HInstruction oldValue = readLocal(boxedVariable);
192 updateLocal(boxElement, newBox); 194 updateLocal(boxElement, newBox);
193 updateLocal(boxedVariable, oldValue); 195 updateLocal(boxedVariable, oldValue);
194 } 196 }
195 updateLocal(boxElement, newBox); 197 updateLocal(boxElement, newBox);
196 } 198 }
197 199
(...skipping 26 matching lines...) Expand all
224 builder.parameters[parameterElement] = parameter; 226 builder.parameters[parameterElement] = parameter;
225 directLocals[parameterElement] = parameter; 227 directLocals[parameterElement] = parameter;
226 }); 228 });
227 } 229 }
228 230
229 enterScope(node, forGenerativeConstructorBody: isGenerativeConstructorBody); 231 enterScope(node, forGenerativeConstructorBody: isGenerativeConstructorBody);
230 232
231 // If the freeVariableMapping is not empty, then this function was a 233 // If the freeVariableMapping is not empty, then this function was a
232 // nested closure that captures variables. Redirect the captured 234 // nested closure that captures variables. Redirect the captured
233 // variables to fields in the closure. 235 // variables to fields in the closure.
234 closureData.forEachFreeVariable((Local from, FieldEntity to) { 236 closureData.forEachFreeVariable((Local from, CapturedVariable to) {
235 redirectElement(from, to); 237 redirectElement(from, to);
236 }); 238 });
237 if (closureData.isClosure) { 239 if (closureData.isClosure) {
238 // Inside closure redirect references to itself to [:this:]. 240 // Inside closure redirect references to itself to [:this:].
239 HThis thisInstruction = 241 HThis thisInstruction =
240 new HThis(closureData.thisLocal, commonMasks.nonNullType); 242 new HThis(closureData.thisLocal, commonMasks.nonNullType);
241 builder.graph.thisInstruction = thisInstruction; 243 builder.graph.thisInstruction = thisInstruction;
242 builder.graph.entry.addAtEntry(thisInstruction); 244 builder.graph.entry.addAtEntry(thisInstruction);
243 updateLocal(closureData.closureElement, thisInstruction); 245 updateLocal(closureData.closureElement, thisInstruction);
244 } else if (element.isInstanceMember) { 246 } else if (element.isInstanceMember) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 /// captured variables that are stored in the closure-field return [:false:]. 299 /// captured variables that are stored in the closure-field return [:false:].
298 bool isAccessedDirectly(Local local) { 300 bool isAccessedDirectly(Local local) {
299 assert(local != null); 301 assert(local != null);
300 return !redirectionMapping.containsKey(local) && 302 return !redirectionMapping.containsKey(local) &&
301 !closureData.variablesUsedInTryOrGenerator.contains(local); 303 !closureData.variablesUsedInTryOrGenerator.contains(local);
302 } 304 }
303 305
304 bool isStoredInClosureField(Local local) { 306 bool isStoredInClosureField(Local local) {
305 assert(local != null); 307 assert(local != null);
306 if (isAccessedDirectly(local)) return false; 308 if (isAccessedDirectly(local)) return false;
307 FieldEntity redirectTarget = redirectionMapping[local]; 309 CapturedVariable redirectTarget = redirectionMapping[local];
308 if (redirectTarget == null) return false; 310 if (redirectTarget == null) return false;
309 return redirectTarget is ClosureFieldElement; 311 return redirectTarget is ClosureFieldElement;
310 } 312 }
311 313
312 bool isBoxed(Local local) { 314 bool isBoxed(Local local) {
313 if (isAccessedDirectly(local)) return false; 315 if (isAccessedDirectly(local)) return false;
314 if (isStoredInClosureField(local)) return false; 316 if (isStoredInClosureField(local)) return false;
315 return redirectionMapping.containsKey(local); 317 return redirectionMapping.containsKey(local);
316 } 318 }
317 319
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 final MemberEntity memberContext; 683 final MemberEntity memberContext;
682 684
683 // Avoid slow Object.hashCode. 685 // Avoid slow Object.hashCode.
684 final int hashCode = _nextHashCode = (_nextHashCode + 1).toUnsigned(30); 686 final int hashCode = _nextHashCode = (_nextHashCode + 1).toUnsigned(30);
685 static int _nextHashCode = 0; 687 static int _nextHashCode = 0;
686 688
687 SyntheticLocal(this.name, this.executableContext, this.memberContext); 689 SyntheticLocal(this.name, this.executableContext, this.memberContext);
688 690
689 toString() => 'SyntheticLocal($name)'; 691 toString() => 'SyntheticLocal($name)';
690 } 692 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/closure.dart ('k') | tests/compiler/dart2js/serialization/model_test_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698