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

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

Issue 2811593006: Lesser direct Compiler use in SSA (Closed)
Patch Set: Created 3 years, 8 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
« no previous file with comments | « no previous file | pkg/compiler/lib/src/ssa/builder_kernel.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 import 'dart:collection'; 5 import 'dart:collection';
6 6
7 import 'package:js_runtime/shared/embedded_names.dart'; 7 import 'package:js_runtime/shared/embedded_names.dart';
8 8
9 import '../closure.dart'; 9 import '../closure.dart';
10 import '../common.dart'; 10 import '../common.dart';
11 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; 11 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem;
12 import '../common/names.dart' show Identifiers, Selectors; 12 import '../common/names.dart' show Identifiers, Selectors;
13 import '../common/tasks.dart' show CompilerTask; 13 import '../common/tasks.dart' show CompilerTask;
14 import '../compiler.dart';
14 import '../constants/constant_system.dart'; 15 import '../constants/constant_system.dart';
15 import '../constants/expressions.dart'; 16 import '../constants/expressions.dart';
16 import '../constants/values.dart'; 17 import '../constants/values.dart';
17 import '../elements/resolution_types.dart'; 18 import '../elements/resolution_types.dart';
18 import '../elements/types.dart'; 19 import '../elements/types.dart';
19 import '../diagnostics/messages.dart' show Message, MessageTemplate; 20 import '../diagnostics/messages.dart' show Message, MessageTemplate;
20 import '../dump_info.dart' show InfoReporter; 21 import '../dump_info.dart' show InfoReporter;
21 import '../elements/elements.dart'; 22 import '../elements/elements.dart';
22 import '../elements/entities.dart'; 23 import '../elements/entities.dart';
23 import '../elements/modelx.dart' show ConstructorBodyElementX; 24 import '../elements/modelx.dart' show ConstructorBodyElementX;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 // code-analysis too. 144 // code-analysis too.
144 final CodegenRegistry registry; 145 final CodegenRegistry registry;
145 146
146 /// Results from the global type-inference analysis corresponding to the 147 /// Results from the global type-inference analysis corresponding to the
147 /// current element being visited. 148 /// current element being visited.
148 /// 149 ///
149 /// Invariant: this property is updated together with [resolvedAst]. 150 /// Invariant: this property is updated together with [resolvedAst].
150 GlobalTypeInferenceElementResult elementInferenceResults; 151 GlobalTypeInferenceElementResult elementInferenceResults;
151 152
152 final JavaScriptBackend backend; 153 final JavaScriptBackend backend;
154
155 Compiler get compiler => backend.compiler;
156
153 final ConstantSystem constantSystem; 157 final ConstantSystem constantSystem;
154 final RuntimeTypesSubstitutions rtiSubstitutions; 158 final RuntimeTypesSubstitutions rtiSubstitutions;
155 159
156 SourceInformationBuilder sourceInformationBuilder; 160 SourceInformationBuilder sourceInformationBuilder;
157 161
158 bool inLazyInitializerExpression = false; 162 bool inLazyInitializerExpression = false;
159 163
160 // TODO(sigmund): make all comments /// instead of /* */ 164 // TODO(sigmund): make all comments /// instead of /* */
161 /* This field is used by the native handler. */ 165 /* This field is used by the native handler. */
162 final NativeEmitter nativeEmitter; 166 final NativeEmitter nativeEmitter;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 this.registry, 199 this.registry,
196 JavaScriptBackend backend, 200 JavaScriptBackend backend,
197 this.closedWorld, 201 this.closedWorld,
198 this.nativeEmitter, 202 this.nativeEmitter,
199 SourceInformationStrategy sourceInformationFactory) 203 SourceInformationStrategy sourceInformationFactory)
200 : this.infoReporter = backend.compiler.dumpInfoTask, 204 : this.infoReporter = backend.compiler.dumpInfoTask,
201 this.backend = backend, 205 this.backend = backend,
202 this.constantSystem = backend.constantSystem, 206 this.constantSystem = backend.constantSystem,
203 this.rtiSubstitutions = backend.rtiSubstitutions { 207 this.rtiSubstitutions = backend.rtiSubstitutions {
204 assert(target.isImplementation); 208 assert(target.isImplementation);
205 compiler = backend.compiler;
206 elementInferenceResults = _resultOf(target); 209 elementInferenceResults = _resultOf(target);
207 assert(elementInferenceResults != null); 210 assert(elementInferenceResults != null);
208 graph.element = target; 211 graph.element = target;
209 sourceElementStack.add(target); 212 sourceElementStack.add(target);
210 sourceInformationBuilder = 213 sourceInformationBuilder =
211 sourceInformationFactory.createBuilderForContext(resolvedAst); 214 sourceInformationFactory.createBuilderForContext(resolvedAst);
212 graph.sourceInformation = 215 graph.sourceInformation =
213 sourceInformationBuilder.buildVariableDeclaration(); 216 sourceInformationBuilder.buildVariableDeclaration();
214 localsHandler = new LocalsHandler( 217 localsHandler = new LocalsHandler(
215 this, target, null, backend.nativeData, backend.interceptorData); 218 this, target, null, backend.nativeData, backend.interceptorData);
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 bool heuristicSayGoodToGo() { 486 bool heuristicSayGoodToGo() {
484 // Don't inline recursively 487 // Don't inline recursively
485 if (inliningStack.any((entry) => entry.function == function)) { 488 if (inliningStack.any((entry) => entry.function == function)) {
486 return false; 489 return false;
487 } 490 }
488 491
489 if (function.isSynthesized) return true; 492 if (function.isSynthesized) return true;
490 493
491 // Don't inline across deferred import to prevent leaking code. The only 494 // Don't inline across deferred import to prevent leaking code. The only
492 // exception is an empty function (which does not contain code). 495 // exception is an empty function (which does not contain code).
493 bool hasOnlyNonDeferredImportPaths = compiler.deferredLoadTask 496 bool hasOnlyNonDeferredImportPaths = deferredLoadTask
494 .hasOnlyNonDeferredImportPaths(compiler.currentElement, function); 497 .hasOnlyNonDeferredImportPaths(compiler.currentElement, function);
495 498
496 if (!hasOnlyNonDeferredImportPaths) { 499 if (!hasOnlyNonDeferredImportPaths) {
497 return doesNotContainCode(); 500 return doesNotContainCode();
498 } 501 }
499 502
500 // Do not inline code that is rarely executed unless it reduces size. 503 // Do not inline code that is rarely executed unless it reduces size.
501 if (inExpressionOfThrow || inLazyInitializerExpression) { 504 if (inExpressionOfThrow || inLazyInitializerExpression) {
502 return reductiveHeuristic(); 505 return reductiveHeuristic();
503 } 506 }
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 List<HInstruction> constructorArguments = <HInstruction>[]; 1207 List<HInstruction> constructorArguments = <HInstruction>[];
1205 List<FieldEntity> fields = <FieldEntity>[]; 1208 List<FieldEntity> fields = <FieldEntity>[];
1206 1209
1207 classElement.forEachInstanceField( 1210 classElement.forEachInstanceField(
1208 (ClassElement enclosingClass, FieldElement member) { 1211 (ClassElement enclosingClass, FieldElement member) {
1209 HInstruction value = fieldValues[member]; 1212 HInstruction value = fieldValues[member];
1210 if (value == null) { 1213 if (value == null) {
1211 // Uninitialized native fields are pre-initialized by the native 1214 // Uninitialized native fields are pre-initialized by the native
1212 // implementation. 1215 // implementation.
1213 assert(invariant( 1216 assert(invariant(
1214 member, isNativeUpgradeFactory || compiler.compilationFailed)); 1217 member, isNativeUpgradeFactory || reporter.hasReportedError));
1215 } else { 1218 } else {
1216 fields.add(member); 1219 fields.add(member);
1217 ResolutionDartType type = localsHandler.substInContext(member.type); 1220 ResolutionDartType type = localsHandler.substInContext(member.type);
1218 constructorArguments 1221 constructorArguments
1219 .add(typeBuilder.potentiallyCheckOrTrustType(value, type)); 1222 .add(typeBuilder.potentiallyCheckOrTrustType(value, type));
1220 } 1223 }
1221 }, includeSuperAndInjectedMembers: true); 1224 }, includeSuperAndInjectedMembers: true);
1222 1225
1223 ResolutionInterfaceType type = classElement.thisType; 1226 ResolutionInterfaceType type = classElement.thisType;
1224 TypeMask ssaType = 1227 TypeMask ssaType =
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
1784 block.remove(breakInstruction); 1787 block.remove(breakInstruction);
1785 }); 1788 });
1786 } 1789 }
1787 } 1790 }
1788 jumpHandler.close(); 1791 jumpHandler.close();
1789 loopDepth--; 1792 loopDepth--;
1790 } 1793 }
1791 1794
1792 visitFunctionExpression(ast.FunctionExpression node) { 1795 visitFunctionExpression(ast.FunctionExpression node) {
1793 LocalFunctionElement methodElement = elements[node]; 1796 LocalFunctionElement methodElement = elements[node];
1794 ClosureClassMap nestedClosureData = compiler.closureToClassMapper 1797 ClosureClassMap nestedClosureData = closureToClassMapper
1795 .getClosureToClassMapping(methodElement.resolvedAst); 1798 .getClosureToClassMapping(methodElement.resolvedAst);
1796 assert(nestedClosureData != null); 1799 assert(nestedClosureData != null);
1797 assert(nestedClosureData.closureClassElement != null); 1800 assert(nestedClosureData.closureClassElement != null);
1798 ClosureClassElement closureClassElement = 1801 ClosureClassElement closureClassElement =
1799 nestedClosureData.closureClassElement; 1802 nestedClosureData.closureClassElement;
1800 MethodElement callElement = nestedClosureData.callElement; 1803 MethodElement callElement = nestedClosureData.callElement;
1801 1804
1802 List<HInstruction> capturedVariables = <HInstruction>[]; 1805 List<HInstruction> capturedVariables = <HInstruction>[];
1803 closureClassElement.closureFields.forEach((ClosureFieldElement field) { 1806 closureClassElement.closureFields.forEach((ClosureFieldElement field) {
1804 Local capturedLocal = 1807 Local capturedLocal =
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
2016 pushInvokeDynamic(send, selector, mask, [receiver], 2019 pushInvokeDynamic(send, selector, mask, [receiver],
2017 sourceInformation: sourceInformationBuilder.buildGet(send)); 2020 sourceInformation: sourceInformationBuilder.buildGet(send));
2018 } 2021 }
2019 2022
2020 /// Inserts a call to checkDeferredIsLoaded for [prefixElement]. 2023 /// Inserts a call to checkDeferredIsLoaded for [prefixElement].
2021 /// If [prefixElement] is [null] ndo nothing. 2024 /// If [prefixElement] is [null] ndo nothing.
2022 void generateIsDeferredLoadedCheckIfNeeded( 2025 void generateIsDeferredLoadedCheckIfNeeded(
2023 PrefixElement prefixElement, ast.Node location) { 2026 PrefixElement prefixElement, ast.Node location) {
2024 if (prefixElement == null) return; 2027 if (prefixElement == null) return;
2025 String loadId = 2028 String loadId =
2026 compiler.deferredLoadTask.getImportDeferName(location, prefixElement); 2029 deferredLoadTask.getImportDeferName(location, prefixElement);
2027 HInstruction loadIdConstant = addConstantString(loadId); 2030 HInstruction loadIdConstant = addConstantString(loadId);
2028 String uri = prefixElement.deferredImport.uri.toString(); 2031 String uri = prefixElement.deferredImport.uri.toString();
2029 HInstruction uriConstant = addConstantString(uri); 2032 HInstruction uriConstant = addConstantString(uri);
2030 MethodElement helper = helpers.checkDeferredIsLoaded; 2033 MethodElement helper = helpers.checkDeferredIsLoaded;
2031 pushInvokeStatic(location, helper, [loadIdConstant, uriConstant]); 2034 pushInvokeStatic(location, helper, [loadIdConstant, uriConstant]);
2032 pop(); 2035 pop();
2033 } 2036 }
2034 2037
2035 /// Inserts a call to checkDeferredIsLoaded if the send has a prefix that 2038 /// Inserts a call to checkDeferredIsLoaded if the send has a prefix that
2036 /// resolves to a deferred library. 2039 /// resolves to a deferred library.
2037 void generateIsDeferredLoadedCheckOfSend(ast.Send node) { 2040 void generateIsDeferredLoadedCheckOfSend(ast.Send node) {
2038 generateIsDeferredLoadedCheckIfNeeded( 2041 generateIsDeferredLoadedCheckIfNeeded(
2039 compiler.deferredLoadTask.deferredPrefixElement(node, elements), node); 2042 deferredLoadTask.deferredPrefixElement(node, elements), node);
2040 } 2043 }
2041 2044
2042 void handleInvalidStaticGet(ast.Send node, Element element) { 2045 void handleInvalidStaticGet(ast.Send node, Element element) {
2043 SourceInformation sourceInformation = 2046 SourceInformation sourceInformation =
2044 sourceInformationBuilder.buildGet(node); 2047 sourceInformationBuilder.buildGet(node);
2045 generateThrowNoSuchMethod( 2048 generateThrowNoSuchMethod(
2046 node, noSuchMethodTargetSymbolString(element, 'get'), 2049 node, noSuchMethodTargetSymbolString(element, 'get'),
2047 argumentNodes: const Link<ast.Node>(), 2050 argumentNodes: const Link<ast.Node>(),
2048 sourceInformation: sourceInformation); 2051 sourceInformation: sourceInformation);
2049 } 2052 }
(...skipping 13 matching lines...) Expand all
2063 } 2066 }
2064 2067
2065 /// Read a static or top level [field] of constant value. 2068 /// Read a static or top level [field] of constant value.
2066 void generateStaticConstGet(ast.Send node, FieldElement field, 2069 void generateStaticConstGet(ast.Send node, FieldElement field,
2067 ConstantExpression constant, SourceInformation sourceInformation) { 2070 ConstantExpression constant, SourceInformation sourceInformation) {
2068 ConstantValue value = constants.getConstantValue(constant); 2071 ConstantValue value = constants.getConstantValue(constant);
2069 HConstant instruction; 2072 HConstant instruction;
2070 // Constants that are referred via a deferred prefix should be referred 2073 // Constants that are referred via a deferred prefix should be referred
2071 // by reference. 2074 // by reference.
2072 PrefixElement prefix = 2075 PrefixElement prefix =
2073 compiler.deferredLoadTask.deferredPrefixElement(node, elements); 2076 deferredLoadTask.deferredPrefixElement(node, elements);
2074 if (prefix != null) { 2077 if (prefix != null) {
2075 instruction = graph.addDeferredConstant( 2078 instruction = graph.addDeferredConstant(
2076 value, prefix, sourceInformation, compiler, closedWorld); 2079 value, prefix, sourceInformation, compiler, closedWorld);
2077 } else { 2080 } else {
2078 instruction = graph.addConstant(value, closedWorld, 2081 instruction = graph.addConstant(value, closedWorld,
2079 sourceInformation: sourceInformation); 2082 sourceInformation: sourceInformation);
2080 } 2083 }
2081 stack.add(instruction); 2084 stack.add(instruction);
2082 // The inferrer may have found a better type than the constant 2085 // The inferrer may have found a better type than the constant
2083 // handler in the case of lists, because the constant handler 2086 // handler in the case of lists, because the constant handler
(...skipping 888 matching lines...) Expand 10 before | Expand all | Expand 10 after
2972 reporter.internalError(node, "Unknown foreign: ${element}"); 2975 reporter.internalError(node, "Unknown foreign: ${element}");
2973 } 2976 }
2974 } 2977 }
2975 2978
2976 generateDeferredLoaderGet(ast.Send node, FunctionElement deferredLoader, 2979 generateDeferredLoaderGet(ast.Send node, FunctionElement deferredLoader,
2977 SourceInformation sourceInformation) { 2980 SourceInformation sourceInformation) {
2978 // Until now we only handle these as getters. 2981 // Until now we only handle these as getters.
2979 invariant(node, deferredLoader.isDeferredLoaderGetter); 2982 invariant(node, deferredLoader.isDeferredLoaderGetter);
2980 FunctionEntity loadFunction = helpers.loadLibraryWrapper; 2983 FunctionEntity loadFunction = helpers.loadLibraryWrapper;
2981 PrefixElement prefixElement = deferredLoader.enclosingElement; 2984 PrefixElement prefixElement = deferredLoader.enclosingElement;
2982 String loadId = 2985 String loadId = deferredLoadTask.getImportDeferName(node, prefixElement);
2983 compiler.deferredLoadTask.getImportDeferName(node, prefixElement);
2984 var inputs = [ 2986 var inputs = [
2985 graph.addConstantString(new ast.DartString.literal(loadId), closedWorld) 2987 graph.addConstantString(new ast.DartString.literal(loadId), closedWorld)
2986 ]; 2988 ];
2987 push(new HInvokeStatic(loadFunction, inputs, commonMasks.nonNullType, 2989 push(new HInvokeStatic(loadFunction, inputs, commonMasks.nonNullType,
2988 targetCanThrow: false) 2990 targetCanThrow: false)
2989 ..sourceInformation = sourceInformation); 2991 ..sourceInformation = sourceInformation);
2990 } 2992 }
2991 2993
2992 generateSuperNoSuchMethodSend( 2994 generateSuperNoSuchMethodSend(
2993 ast.Send node, Selector selector, List<HInstruction> arguments) { 2995 ast.Send node, Selector selector, List<HInstruction> arguments) {
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
3495 new Map<ResolutionDartType, Set<ResolutionDartType>>(); 3497 new Map<ResolutionDartType, Set<ResolutionDartType>>();
3496 bool definitelyFails = false; 3498 bool definitelyFails = false;
3497 3499
3498 void addTypeVariableBoundCheck( 3500 void addTypeVariableBoundCheck(
3499 GenericType instance, 3501 GenericType instance,
3500 ResolutionDartType typeArgument, 3502 ResolutionDartType typeArgument,
3501 ResolutionTypeVariableType typeVariable, 3503 ResolutionTypeVariableType typeVariable,
3502 ResolutionDartType bound) { 3504 ResolutionDartType bound) {
3503 if (definitelyFails) return; 3505 if (definitelyFails) return;
3504 3506
3505 int subtypeRelation = 3507 int subtypeRelation = types.computeSubtypeRelation(typeArgument, bound);
3506 compiler.types.computeSubtypeRelation(typeArgument, bound);
3507 if (subtypeRelation == Types.IS_SUBTYPE) return; 3508 if (subtypeRelation == Types.IS_SUBTYPE) return;
3508 3509
3509 String message = "Can't create an instance of malbounded type '$type': " 3510 String message = "Can't create an instance of malbounded type '$type': "
3510 "'${typeArgument}' is not a subtype of bound '${bound}' for " 3511 "'${typeArgument}' is not a subtype of bound '${bound}' for "
3511 "type variable '${typeVariable}' of type " 3512 "type variable '${typeVariable}' of type "
3512 "${type == instance 3513 "${type == instance
3513 ? "'${type.element.thisType}'" 3514 ? "'${type.element.thisType}'"
3514 : "'${instance.element.thisType}' on the supertype " 3515 : "'${instance.element.thisType}' on the supertype "
3515 "'${instance}' of '${type}'" 3516 "'${instance}' of '${type}'"
3516 }."; 3517 }.";
3517 if (subtypeRelation == Types.NOT_SUBTYPE) { 3518 if (subtypeRelation == Types.NOT_SUBTYPE) {
3518 generateTypeError(node, message); 3519 generateTypeError(node, message);
3519 definitelyFails = true; 3520 definitelyFails = true;
3520 return; 3521 return;
3521 } else if (subtypeRelation == Types.MAYBE_SUBTYPE) { 3522 } else if (subtypeRelation == Types.MAYBE_SUBTYPE) {
3522 Set<ResolutionDartType> seenChecks = seenChecksMap.putIfAbsent( 3523 Set<ResolutionDartType> seenChecks = seenChecksMap.putIfAbsent(
3523 typeArgument, () => new Set<ResolutionDartType>()); 3524 typeArgument, () => new Set<ResolutionDartType>());
3524 if (!seenChecks.contains(bound)) { 3525 if (!seenChecks.contains(bound)) {
3525 seenChecks.add(bound); 3526 seenChecks.add(bound);
3526 assertIsSubtype(node, typeArgument, bound, message); 3527 assertIsSubtype(node, typeArgument, bound, message);
3527 } 3528 }
3528 } 3529 }
3529 } 3530 }
3530 3531
3531 compiler.types.checkTypeVariableBounds(type, addTypeVariableBoundCheck); 3532 types.checkTypeVariableBounds(type, addTypeVariableBoundCheck);
3532 if (definitelyFails) { 3533 if (definitelyFails) {
3533 return true; 3534 return true;
3534 } 3535 }
3535 for (ResolutionInterfaceType supertype in type.element.allSupertypes) { 3536 for (ResolutionInterfaceType supertype in type.element.allSupertypes) {
3536 ResolutionDartType instance = type.asInstanceOf(supertype.element); 3537 ResolutionDartType instance = type.asInstanceOf(supertype.element);
3537 compiler.types 3538 types.checkTypeVariableBounds(instance, addTypeVariableBoundCheck);
3538 .checkTypeVariableBounds(instance, addTypeVariableBoundCheck);
3539 if (definitelyFails) { 3539 if (definitelyFails) {
3540 return true; 3540 return true;
3541 } 3541 }
3542 } 3542 }
3543 return false; 3543 return false;
3544 } 3544 }
3545 3545
3546 visitStaticSend(ast.Send node) { 3546 visitStaticSend(ast.Send node) {
3547 internalError(node, "Unexpected visitStaticSend"); 3547 internalError(node, "Unexpected visitStaticSend");
3548 } 3548 }
(...skipping 3192 matching lines...) Expand 10 before | Expand all | Expand 10 after
6741 this.oldReturnLocal, 6741 this.oldReturnLocal,
6742 this.oldReturnType, 6742 this.oldReturnType,
6743 this.oldResolvedAst, 6743 this.oldResolvedAst,
6744 this.oldStack, 6744 this.oldStack,
6745 this.oldLocalsHandler, 6745 this.oldLocalsHandler,
6746 this.inTryStatement, 6746 this.inTryStatement,
6747 this.allFunctionsCalledOnce, 6747 this.allFunctionsCalledOnce,
6748 this.oldElementInferenceResults) 6748 this.oldElementInferenceResults)
6749 : super(function); 6749 : super(function);
6750 } 6750 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/ssa/builder_kernel.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698