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

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

Issue 2563443007: Reduce use of Compiler.closedWorld (Closed)
Patch Set: 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;
70 71
71 GlobalTypeInferenceElementResult _resultOf(Element e) => 72 GlobalTypeInferenceElementResult _resultOf(Element e) =>
72 _compiler.globalInference.results.resultOf(e); 73 _compiler.globalInference.results.resultOf(e);
73 74
74 ConstantValue getConstantForSymbol(ir.SymbolLiteral node) { 75 ConstantValue getConstantForSymbol(ir.SymbolLiteral node) {
75 if (kernel.syntheticNodes.contains(node)) { 76 if (kernel.syntheticNodes.contains(node)) {
76 return _backend.constantSystem.createSymbol(_compiler, node.value); 77 return _backend.constantSystem.createSymbol(_compiler, node.value);
77 } 78 }
78 ast.Node astNode = getNode(node); 79 ast.Node astNode = getNode(node);
79 ConstantValue constantValue = _backend.constants 80 ConstantValue constantValue = _backend.constants
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 // If this is a synthetic local, return the synthetic local 121 // If this is a synthetic local, return the synthetic local
121 if (variable.name == null) { 122 if (variable.name == null) {
122 return _syntheticLocals.putIfAbsent( 123 return _syntheticLocals.putIfAbsent(
123 variable, () => new SyntheticLocal("x", null)); 124 variable, () => new SyntheticLocal("x", null));
124 } 125 }
125 return getElement(variable) as LocalElement; 126 return getElement(variable) as LocalElement;
126 } 127 }
127 128
128 bool getCanThrow(ir.Node procedure) { 129 bool getCanThrow(ir.Node procedure) {
129 FunctionElement function = getElement(procedure); 130 FunctionElement function = getElement(procedure);
130 return !_compiler.closedWorld.getCannotThrow(function); 131 return !_closedWorld.getCannotThrow(function);
131 } 132 }
132 133
133 TypeMask returnTypeOf(ir.Member node) { 134 TypeMask returnTypeOf(ir.Member node) {
134 return TypeMaskFactory.inferredReturnTypeForElement( 135 return TypeMaskFactory.inferredReturnTypeForElement(
135 getElement(node), _compiler); 136 getElement(node), _compiler);
136 } 137 }
137 138
138 SideEffects getSideEffects(ir.Node node) { 139 SideEffects getSideEffects(ir.Node node) {
139 return _compiler.closedWorld.getSideEffectsOfElement(getElement(node)); 140 return _closedWorld.getSideEffectsOfElement(getElement(node));
140 } 141 }
141 142
142 CallStructure getCallStructure(ir.Arguments arguments) { 143 CallStructure getCallStructure(ir.Arguments arguments) {
143 int argumentCount = arguments.positional.length + arguments.named.length; 144 int argumentCount = arguments.positional.length + arguments.named.length;
144 List<String> namedArguments = arguments.named.map((e) => e.name).toList(); 145 List<String> namedArguments = arguments.named.map((e) => e.name).toList();
145 return new CallStructure(argumentCount, namedArguments); 146 return new CallStructure(argumentCount, namedArguments);
146 } 147 }
147 148
148 FunctionSignature getFunctionSignature(ir.FunctionNode function) { 149 FunctionSignature getFunctionSignature(ir.FunctionNode function) {
149 return getElement(function).asFunctionElement().functionSignature; 150 return getElement(function).asFunctionElement().functionSignature;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 return _compiler.closedWorld.commonMasks.dynamicType; 208 return _compiler.closedWorld.commonMasks.dynamicType;
208 } 209 }
209 return _resultOf(_target).typeOfSend(getNode(send)); 210 return _resultOf(_target).typeOfSend(getNode(send));
210 } 211 }
211 212
212 TypeMask typeOfGet(ir.PropertyGet getter) { 213 TypeMask typeOfGet(ir.PropertyGet getter) {
213 return _resultOf(_target).typeOfSend(getNode(getter)); 214 return _resultOf(_target).typeOfSend(getNode(getter));
214 } 215 }
215 216
216 TypeMask typeOfSet(ir.PropertySet setter) { 217 TypeMask typeOfSet(ir.PropertySet setter) {
217 return _compiler.closedWorld.commonMasks.dynamicType; 218 return _closedWorld.commonMasks.dynamicType;
218 } 219 }
219 220
220 TypeMask typeOfSend(ir.Expression send) { 221 TypeMask typeOfSend(ir.Expression send) {
221 assert(send is ir.InvocationExpression || send is ir.PropertyGet); 222 assert(send is ir.InvocationExpression || send is ir.PropertyGet);
222 return _resultOf(_target).typeOfSend(getNode(send)); 223 return _resultOf(_target).typeOfSend(getNode(send));
223 } 224 }
224 225
225 TypeMask typeOfListLiteral(Element owner, ir.ListLiteral listLiteral) { 226 TypeMask typeOfListLiteral(Element owner, ir.ListLiteral listLiteral) {
226 ast.Node node = getNodeOrNull(listLiteral); 227 ast.Node node = getNodeOrNull(listLiteral);
227 if (node == null) { 228 if (node == null) {
228 assertNodeIsSynthetic(listLiteral); 229 assertNodeIsSynthetic(listLiteral);
229 return _compiler.closedWorld.commonMasks.growableListType; 230 return _closedWorld.commonMasks.growableListType;
230 } 231 }
231 return _resultOf(owner).typeOfNewList(getNode(listLiteral)) ?? 232 return _resultOf(owner).typeOfNewList(getNode(listLiteral)) ??
232 _compiler.closedWorld.commonMasks.dynamicType; 233 _closedWorld.commonMasks.dynamicType;
233 } 234 }
234 235
235 TypeMask typeOfIterator(ir.ForInStatement forInStatement) { 236 TypeMask typeOfIterator(ir.ForInStatement forInStatement) {
236 return _resultOf(_target).typeOfIterator(getNode(forInStatement)); 237 return _resultOf(_target).typeOfIterator(getNode(forInStatement));
237 } 238 }
238 239
239 TypeMask typeOfIteratorCurrent(ir.ForInStatement forInStatement) { 240 TypeMask typeOfIteratorCurrent(ir.ForInStatement forInStatement) {
240 return _resultOf(_target).typeOfIteratorCurrent(getNode(forInStatement)); 241 return _resultOf(_target).typeOfIteratorCurrent(getNode(forInStatement));
241 } 242 }
242 243
243 TypeMask typeOfIteratorMoveNext(ir.ForInStatement forInStatement) { 244 TypeMask typeOfIteratorMoveNext(ir.ForInStatement forInStatement) {
244 return _resultOf(_target).typeOfIteratorMoveNext(getNode(forInStatement)); 245 return _resultOf(_target).typeOfIteratorMoveNext(getNode(forInStatement));
245 } 246 }
246 247
247 bool isJsIndexableIterator(ir.ForInStatement forInStatement) { 248 bool isJsIndexableIterator(ir.ForInStatement forInStatement) {
248 TypeMask mask = typeOfIterator(forInStatement); 249 TypeMask mask = typeOfIterator(forInStatement);
249 ClosedWorld closedWorld = _compiler.closedWorld;
250 return mask != null && 250 return mask != null &&
251 mask.satisfies(_backend.helpers.jsIndexableClass, closedWorld) && 251 mask.satisfies(_backend.helpers.jsIndexableClass, _closedWorld) &&
252 // String is indexable but not iterable. 252 // String is indexable but not iterable.
253 !mask.satisfies(_backend.helpers.jsStringClass, closedWorld); 253 !mask.satisfies(_backend.helpers.jsStringClass, _closedWorld);
254 } 254 }
255 255
256 bool isFixedLength(TypeMask mask) { 256 bool isFixedLength(TypeMask mask) {
257 ClosedWorld closedWorld = _compiler.closedWorld;
258 JavaScriptBackend backend = _compiler.backend; 257 JavaScriptBackend backend = _compiler.backend;
259 if (mask.isContainer && (mask as ContainerTypeMask).length != null) { 258 if (mask.isContainer && (mask as ContainerTypeMask).length != null) {
260 // A container on which we have inferred the length. 259 // A container on which we have inferred the length.
261 return true; 260 return true;
262 } 261 }
263 // TODO(sra): Recognize any combination of fixed length indexables. 262 // TODO(sra): Recognize any combination of fixed length indexables.
264 if (mask.containsOnly(backend.helpers.jsFixedArrayClass) || 263 if (mask.containsOnly(
265 mask.containsOnly(backend.helpers.jsUnmodifiableArrayClass) || 264 _closedWorld.backendClasses.fixedListImplementation) ||
266 mask.containsOnlyString(closedWorld) || 265 mask.containsOnly(
266 _closedWorld.backendClasses.constListImplementation) ||
267 mask.containsOnlyString(_closedWorld) ||
267 backend.isTypedArray(mask)) { 268 backend.isTypedArray(mask)) {
268 return true; 269 return true;
269 } 270 }
270 return false; 271 return false;
271 } 272 }
272 273
273 TypeMask inferredIndexType(ir.ForInStatement forInStatement) { 274 TypeMask inferredIndexType(ir.ForInStatement forInStatement) {
274 return TypeMaskFactory.inferredTypeForSelector( 275 return TypeMaskFactory.inferredTypeForSelector(
275 new Selector.index(), typeOfIterator(forInStatement), _compiler); 276 new Selector.index(), typeOfIterator(forInStatement), _compiler);
276 } 277 }
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 astAdapter.reporter.internalError( 844 astAdapter.reporter.internalError(
844 CURRENT_ELEMENT_SPANNABLE, "Unexpected constant target: $element."); 845 CURRENT_ELEMENT_SPANNABLE, "Unexpected constant target: $element.");
845 return null; 846 return null;
846 } 847 }
847 848
848 @override 849 @override
849 ConstantExpression visitStringLiteral(ir.StringLiteral node) { 850 ConstantExpression visitStringLiteral(ir.StringLiteral node) {
850 return new StringConstantExpression(node.value); 851 return new StringConstantExpression(node.value);
851 } 852 }
852 } 853 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/ssa/invoke_dynamic_specializers.dart ('k') | pkg/compiler/lib/src/ssa/kernel_string_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698