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

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

Issue 2575083002: Pass ClosedWorld directly to codegen tasks (Closed)
Patch Set: Updated cf. comment. Created 4 years 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 'package:js_runtime/shared/embedded_names.dart'; 5 import 'package:js_runtime/shared/embedded_names.dart';
6 import 'package:kernel/ast.dart' as ir; 6 import 'package:kernel/ast.dart' as ir;
7 7
8 import '../constants/expressions.dart'; 8 import '../constants/expressions.dart';
9 import '../common.dart'; 9 import '../common.dart';
10 import '../common/names.dart'; 10 import '../common/names.dart';
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 for (LocalFunctionElement localFunction in kernel.localFunctions.keys) { 60 for (LocalFunctionElement localFunction in kernel.localFunctions.keys) {
61 _nodeToElement[kernel.localFunctions[localFunction]] = localFunction; 61 _nodeToElement[kernel.localFunctions[localFunction]] = localFunction;
62 } 62 }
63 _typeConverter = new DartTypeConverter(this); 63 _typeConverter = new DartTypeConverter(this);
64 } 64 }
65 65
66 Compiler get _compiler => _backend.compiler; 66 Compiler get _compiler => _backend.compiler;
67 TreeElements get elements => _resolvedAst.elements; 67 TreeElements get elements => _resolvedAst.elements;
68 DiagnosticReporter get reporter => _compiler.reporter; 68 DiagnosticReporter get reporter => _compiler.reporter;
69 Element get _target => _resolvedAst.element; 69 Element get _target => _resolvedAst.element;
70 ClosedWorld get _closedWorld => _compiler.closedWorld;
71 70
72 GlobalTypeInferenceResults get _globalInferenceResults => 71 GlobalTypeInferenceResults get _globalInferenceResults =>
73 _compiler.globalInference.results; 72 _compiler.globalInference.results;
74 73
75 GlobalTypeInferenceElementResult _resultOf(Element e) => 74 GlobalTypeInferenceElementResult _resultOf(Element e) =>
76 _globalInferenceResults.resultOf(e); 75 _globalInferenceResults.resultOf(e);
77 76
78 ConstantValue getConstantForSymbol(ir.SymbolLiteral node) { 77 ConstantValue getConstantForSymbol(ir.SymbolLiteral node) {
79 if (kernel.syntheticNodes.contains(node)) { 78 if (kernel.syntheticNodes.contains(node)) {
80 return _backend.constantSystem.createSymbol(_compiler, node.value); 79 return _backend.constantSystem.createSymbol(_compiler, node.value);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 121
123 Local getLocal(ir.VariableDeclaration variable) { 122 Local getLocal(ir.VariableDeclaration variable) {
124 // If this is a synthetic local, return the synthetic local 123 // If this is a synthetic local, return the synthetic local
125 if (variable.name == null) { 124 if (variable.name == null) {
126 return _syntheticLocals.putIfAbsent( 125 return _syntheticLocals.putIfAbsent(
127 variable, () => new SyntheticLocal("x", null)); 126 variable, () => new SyntheticLocal("x", null));
128 } 127 }
129 return getElement(variable) as LocalElement; 128 return getElement(variable) as LocalElement;
130 } 129 }
131 130
132 bool getCanThrow(ir.Node procedure) { 131 bool getCanThrow(ir.Node procedure, ClosedWorld closedWorld) {
133 FunctionElement function = getElement(procedure); 132 FunctionElement function = getElement(procedure);
134 return !_closedWorld.getCannotThrow(function); 133 return !closedWorld.getCannotThrow(function);
135 } 134 }
136 135
137 TypeMask returnTypeOf(ir.Member node) { 136 TypeMask returnTypeOf(ir.Member node) {
138 return TypeMaskFactory.inferredReturnTypeForElement( 137 return TypeMaskFactory.inferredReturnTypeForElement(
139 getElement(node), _globalInferenceResults); 138 getElement(node), _globalInferenceResults);
140 } 139 }
141 140
142 SideEffects getSideEffects(ir.Node node) { 141 SideEffects getSideEffects(ir.Node node, ClosedWorld closedWorld) {
143 return _closedWorld.getSideEffectsOfElement(getElement(node)); 142 return closedWorld.getSideEffectsOfElement(getElement(node));
144 } 143 }
145 144
146 CallStructure getCallStructure(ir.Arguments arguments) { 145 CallStructure getCallStructure(ir.Arguments arguments) {
147 int argumentCount = arguments.positional.length + arguments.named.length; 146 int argumentCount = arguments.positional.length + arguments.named.length;
148 List<String> namedArguments = arguments.named.map((e) => e.name).toList(); 147 List<String> namedArguments = arguments.named.map((e) => e.name).toList();
149 return new CallStructure(argumentCount, namedArguments); 148 return new CallStructure(argumentCount, namedArguments);
150 } 149 }
151 150
152 FunctionSignature getFunctionSignature(ir.FunctionNode function) { 151 FunctionSignature getFunctionSignature(ir.FunctionNode function) {
153 return getElement(function).asFunctionElement().functionSignature; 152 return getElement(function).asFunctionElement().functionSignature;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 return new Selector.getter(name); 194 return new Selector.getter(name);
196 } 195 }
197 196
198 Selector getSetterSelector(ir.PropertySet setter) { 197 Selector getSetterSelector(ir.PropertySet setter) {
199 ir.Name irName = setter.name; 198 ir.Name irName = setter.name;
200 Name name = new Name( 199 Name name = new Name(
201 irName.name, irName.isPrivate ? getElement(irName.library) : null); 200 irName.name, irName.isPrivate ? getElement(irName.library) : null);
202 return new Selector.setter(name); 201 return new Selector.setter(name);
203 } 202 }
204 203
205 TypeMask typeOfInvocation(ir.MethodInvocation send) { 204 TypeMask typeOfInvocation(ir.MethodInvocation send, ClosedWorld closedWorld) {
206 ast.Node operatorNode = kernel.nodeToAstOperator[send]; 205 ast.Node operatorNode = kernel.nodeToAstOperator[send];
207 if (operatorNode != null) { 206 if (operatorNode != null) {
208 return _resultOf(_target).typeOfOperator(operatorNode); 207 return _resultOf(_target).typeOfOperator(operatorNode);
209 } 208 }
210 if (send.name.name == '[]=') { 209 if (send.name.name == '[]=') {
211 return _compiler.closedWorld.commonMasks.dynamicType; 210 return closedWorld.commonMasks.dynamicType;
212 } 211 }
213 return _resultOf(_target).typeOfSend(getNode(send)); 212 return _resultOf(_target).typeOfSend(getNode(send));
214 } 213 }
215 214
216 TypeMask typeOfGet(ir.PropertyGet getter) { 215 TypeMask typeOfGet(ir.PropertyGet getter) {
217 return _resultOf(_target).typeOfSend(getNode(getter)); 216 return _resultOf(_target).typeOfSend(getNode(getter));
218 } 217 }
219 218
220 TypeMask typeOfSet(ir.PropertySet setter) { 219 TypeMask typeOfSet(ir.PropertySet setter, ClosedWorld closedWorld) {
221 return _closedWorld.commonMasks.dynamicType; 220 return closedWorld.commonMasks.dynamicType;
222 } 221 }
223 222
224 TypeMask typeOfSend(ir.Expression send) { 223 TypeMask typeOfSend(ir.Expression send) {
225 assert(send is ir.InvocationExpression || send is ir.PropertyGet); 224 assert(send is ir.InvocationExpression || send is ir.PropertyGet);
226 return _resultOf(_target).typeOfSend(getNode(send)); 225 return _resultOf(_target).typeOfSend(getNode(send));
227 } 226 }
228 227
229 TypeMask typeOfListLiteral(Element owner, ir.ListLiteral listLiteral) { 228 TypeMask typeOfListLiteral(
229 Element owner, ir.ListLiteral listLiteral, ClosedWorld closedWorld) {
230 ast.Node node = getNodeOrNull(listLiteral); 230 ast.Node node = getNodeOrNull(listLiteral);
231 if (node == null) { 231 if (node == null) {
232 assertNodeIsSynthetic(listLiteral); 232 assertNodeIsSynthetic(listLiteral);
233 return _closedWorld.commonMasks.growableListType; 233 return closedWorld.commonMasks.growableListType;
234 } 234 }
235 return _resultOf(owner).typeOfNewList(getNode(listLiteral)) ?? 235 return _resultOf(owner).typeOfNewList(getNode(listLiteral)) ??
236 _closedWorld.commonMasks.dynamicType; 236 closedWorld.commonMasks.dynamicType;
237 } 237 }
238 238
239 TypeMask typeOfIterator(ir.ForInStatement forInStatement) { 239 TypeMask typeOfIterator(ir.ForInStatement forInStatement) {
240 return _resultOf(_target).typeOfIterator(getNode(forInStatement)); 240 return _resultOf(_target).typeOfIterator(getNode(forInStatement));
241 } 241 }
242 242
243 TypeMask typeOfIteratorCurrent(ir.ForInStatement forInStatement) { 243 TypeMask typeOfIteratorCurrent(ir.ForInStatement forInStatement) {
244 return _resultOf(_target).typeOfIteratorCurrent(getNode(forInStatement)); 244 return _resultOf(_target).typeOfIteratorCurrent(getNode(forInStatement));
245 } 245 }
246 246
247 TypeMask typeOfIteratorMoveNext(ir.ForInStatement forInStatement) { 247 TypeMask typeOfIteratorMoveNext(ir.ForInStatement forInStatement) {
248 return _resultOf(_target).typeOfIteratorMoveNext(getNode(forInStatement)); 248 return _resultOf(_target).typeOfIteratorMoveNext(getNode(forInStatement));
249 } 249 }
250 250
251 bool isJsIndexableIterator(ir.ForInStatement forInStatement) { 251 bool isJsIndexableIterator(
252 ir.ForInStatement forInStatement, ClosedWorld closedWorld) {
252 TypeMask mask = typeOfIterator(forInStatement); 253 TypeMask mask = typeOfIterator(forInStatement);
253 return mask != null && 254 return mask != null &&
254 mask.satisfies(_backend.helpers.jsIndexableClass, _closedWorld) && 255 mask.satisfies(_backend.helpers.jsIndexableClass, closedWorld) &&
255 // String is indexable but not iterable. 256 // String is indexable but not iterable.
256 !mask.satisfies(_backend.helpers.jsStringClass, _closedWorld); 257 !mask.satisfies(_backend.helpers.jsStringClass, closedWorld);
257 } 258 }
258 259
259 bool isFixedLength(TypeMask mask) { 260 bool isFixedLength(TypeMask mask, ClosedWorld closedWorld) {
260 JavaScriptBackend backend = _compiler.backend;
261 if (mask.isContainer && (mask as ContainerTypeMask).length != null) { 261 if (mask.isContainer && (mask as ContainerTypeMask).length != null) {
262 // A container on which we have inferred the length. 262 // A container on which we have inferred the length.
263 return true; 263 return true;
264 } 264 }
265 // TODO(sra): Recognize any combination of fixed length indexables. 265 // TODO(sra): Recognize any combination of fixed length indexables.
266 if (mask.containsOnly( 266 if (mask.containsOnly(closedWorld.backendClasses.fixedListImplementation) ||
267 _closedWorld.backendClasses.fixedListImplementation) || 267 mask.containsOnly(closedWorld.backendClasses.constListImplementation) ||
268 mask.containsOnly( 268 mask.containsOnlyString(closedWorld) ||
269 _closedWorld.backendClasses.constListImplementation) || 269 closedWorld.commonMasks.isTypedArray(mask)) {
270 mask.containsOnlyString(_closedWorld) ||
271 _closedWorld.commonMasks.isTypedArray(mask)) {
272 return true; 270 return true;
273 } 271 }
274 return false; 272 return false;
275 } 273 }
276 274
277 TypeMask inferredIndexType(ir.ForInStatement forInStatement) { 275 TypeMask inferredIndexType(ir.ForInStatement forInStatement) {
278 return TypeMaskFactory.inferredTypeForSelector(new Selector.index(), 276 return TypeMaskFactory.inferredTypeForSelector(new Selector.index(),
279 typeOfIterator(forInStatement), _globalInferenceResults); 277 typeOfIterator(forInStatement), _globalInferenceResults);
280 } 278 }
281 279
282 TypeMask inferredTypeOf(ir.Member node) { 280 TypeMask inferredTypeOf(ir.Member node) {
283 return TypeMaskFactory.inferredTypeForElement( 281 return TypeMaskFactory.inferredTypeForElement(
284 getElement(node), _globalInferenceResults); 282 getElement(node), _globalInferenceResults);
285 } 283 }
286 284
287 TypeMask selectorTypeOf(Selector selector, TypeMask mask) { 285 TypeMask selectorTypeOf(Selector selector, TypeMask mask) {
288 return TypeMaskFactory.inferredTypeForSelector( 286 return TypeMaskFactory.inferredTypeForSelector(
289 selector, mask, _globalInferenceResults); 287 selector, mask, _globalInferenceResults);
290 } 288 }
291 289
292 TypeMask typeFromNativeBehavior(native.NativeBehavior nativeBehavior) { 290 TypeMask typeFromNativeBehavior(
293 return TypeMaskFactory.fromNativeBehavior(nativeBehavior, _closedWorld); 291 native.NativeBehavior nativeBehavior, ClosedWorld closedWorld) {
292 return TypeMaskFactory.fromNativeBehavior(nativeBehavior, closedWorld);
294 } 293 }
295 294
296 ConstantValue getConstantFor(ir.Node node) { 295 ConstantValue getConstantFor(ir.Node node) {
297 ConstantValue constantValue = 296 ConstantValue constantValue =
298 _backend.constants.getConstantValueForNode(getNode(node), elements); 297 _backend.constants.getConstantValueForNode(getNode(node), elements);
299 assert(invariant(getNode(node), constantValue != null, 298 assert(invariant(getNode(node), constantValue != null,
300 message: 'No constant computed for $node')); 299 message: 'No constant computed for $node'));
301 return constantValue; 300 return constantValue;
302 } 301 }
303 302
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 astAdapter.reporter.internalError( 853 astAdapter.reporter.internalError(
855 CURRENT_ELEMENT_SPANNABLE, "Unexpected constant target: $element."); 854 CURRENT_ELEMENT_SPANNABLE, "Unexpected constant target: $element.");
856 return null; 855 return null;
857 } 856 }
858 857
859 @override 858 @override
860 ConstantExpression visitStringLiteral(ir.StringLiteral node) { 859 ConstantExpression visitStringLiteral(ir.StringLiteral node) {
861 return new StringConstantExpression(node.value); 860 return new StringConstantExpression(node.value);
862 } 861 }
863 } 862 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/ssa/interceptor_simplifier.dart ('k') | pkg/compiler/lib/src/ssa/optimize.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698