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

Side by Side Diff: pkg/compiler/lib/src/js_backend/backend.dart

Issue 2370833002: Replace ClosedWorld.backend with ClosedWorld.backendClasses (Closed)
Patch Set: Created 4 years, 2 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) 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 js_backend.backend; 5 library js_backend.backend;
6 6
7 import 'dart:async' show Future; 7 import 'dart:async' show Future;
8 8
9 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames; 9 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames;
10 10
11 import '../closure.dart'; 11 import '../closure.dart';
12 import '../common.dart'; 12 import '../common.dart';
13 import '../common/backend_api.dart' 13 import '../common/backend_api.dart'
14 show Backend, ImpactTransformer, ForeignResolver, NativeRegistry; 14 show
15 Backend,
16 BackendClasses,
17 ImpactTransformer,
18 ForeignResolver,
19 NativeRegistry;
15 import '../common/codegen.dart' show CodegenImpact, CodegenWorkItem; 20 import '../common/codegen.dart' show CodegenImpact, CodegenWorkItem;
16 import '../common/names.dart' show Identifiers, Selectors, Uris; 21 import '../common/names.dart' show Identifiers, Selectors, Uris;
17 import '../common/registry.dart' show Registry; 22 import '../common/registry.dart' show Registry;
18 import '../common/resolution.dart' show Frontend, Resolution, ResolutionImpact; 23 import '../common/resolution.dart' show Frontend, Resolution, ResolutionImpact;
19 import '../common/tasks.dart' show CompilerTask; 24 import '../common/tasks.dart' show CompilerTask;
20 import '../compiler.dart' show Compiler; 25 import '../compiler.dart' show Compiler;
21 import '../constants/constant_system.dart'; 26 import '../constants/constant_system.dart';
22 import '../constants/expressions.dart'; 27 import '../constants/expressions.dart';
23 import '../constants/values.dart'; 28 import '../constants/values.dart';
24 import '../core_types.dart' show CoreClasses, CoreTypes; 29 import '../core_types.dart' show CoreClasses, CoreTypes;
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 StagedWorldImpactBuilder constantImpactsForResolution = 589 StagedWorldImpactBuilder constantImpactsForResolution =
585 new StagedWorldImpactBuilder(); 590 new StagedWorldImpactBuilder();
586 591
587 StagedWorldImpactBuilder constantImpactsForCodegen = 592 StagedWorldImpactBuilder constantImpactsForCodegen =
588 new StagedWorldImpactBuilder(); 593 new StagedWorldImpactBuilder();
589 594
590 final NativeData nativeData = new NativeData(); 595 final NativeData nativeData = new NativeData();
591 596
592 final BackendHelpers helpers; 597 final BackendHelpers helpers;
593 final BackendImpacts impacts; 598 final BackendImpacts impacts;
599 BackendClasses backendClasses;
594 600
595 final JSFrontendAccess frontend; 601 final JSFrontendAccess frontend;
596 602
597 JavaScriptBackend(Compiler compiler, 603 JavaScriptBackend(Compiler compiler,
598 {bool generateSourceMap: true, 604 {bool generateSourceMap: true,
599 bool useStartupEmitter: false, 605 bool useStartupEmitter: false,
600 bool useNewSourceInfo: false, 606 bool useNewSourceInfo: false,
601 bool useKernel: false}) 607 bool useKernel: false})
602 : namer = determineNamer(compiler), 608 : namer = determineNamer(compiler),
603 oneShotInterceptors = new Map<jsAst.Name, Selector>(), 609 oneShotInterceptors = new Map<jsAst.Name, Selector>(),
(...skipping 19 matching lines...) Expand all
623 jsInteropAnalysis = new JsInteropAnalysis(this); 629 jsInteropAnalysis = new JsInteropAnalysis(this);
624 630
625 noSuchMethodRegistry = new NoSuchMethodRegistry(this); 631 noSuchMethodRegistry = new NoSuchMethodRegistry(this);
626 kernelTask = new KernelTask(this); 632 kernelTask = new KernelTask(this);
627 constantCompilerTask = new JavaScriptConstantTask(compiler); 633 constantCompilerTask = new JavaScriptConstantTask(compiler);
628 impactTransformer = new JavaScriptImpactTransformer(this); 634 impactTransformer = new JavaScriptImpactTransformer(this);
629 patchResolverTask = new PatchResolverTask(compiler); 635 patchResolverTask = new PatchResolverTask(compiler);
630 functionCompiler = 636 functionCompiler =
631 new SsaFunctionCompiler(this, sourceInformationStrategy, useKernel); 637 new SsaFunctionCompiler(this, sourceInformationStrategy, useKernel);
632 serialization = new JavaScriptBackendSerialization(this); 638 serialization = new JavaScriptBackendSerialization(this);
639 backendClasses = new JavaScriptBackendClasses(helpers);
633 } 640 }
634 641
635 ConstantSystem get constantSystem => constants.constantSystem; 642 ConstantSystem get constantSystem => constants.constantSystem;
636 643
637 DiagnosticReporter get reporter => compiler.reporter; 644 DiagnosticReporter get reporter => compiler.reporter;
638 645
639 CoreClasses get coreClasses => compiler.coreClasses; 646 CoreClasses get coreClasses => compiler.coreClasses;
640 647
641 CoreTypes get coreTypes => compiler.coreTypes; 648 CoreTypes get coreTypes => compiler.coreTypes;
642 649
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
1114 interceptor.dispatchedType, impactBuilder); 1121 interceptor.dispatchedType, impactBuilder);
1115 } else if (constant.isType) { 1122 } else if (constant.isType) {
1116 if (isForResolution) { 1123 if (isForResolution) {
1117 impactBuilder.registerStaticUse(new StaticUse.staticInvoke( 1124 impactBuilder.registerStaticUse(new StaticUse.staticInvoke(
1118 // TODO(johnniwinther): Find the right [CallStructure]. 1125 // TODO(johnniwinther): Find the right [CallStructure].
1119 helpers.createRuntimeType, 1126 helpers.createRuntimeType,
1120 null)); 1127 null));
1121 registerBackendUse(helpers.createRuntimeType); 1128 registerBackendUse(helpers.createRuntimeType);
1122 } 1129 }
1123 impactBuilder.registerTypeUse( 1130 impactBuilder.registerTypeUse(
1124 new TypeUse.instantiation(typeImplementation.rawType)); 1131 new TypeUse.instantiation(backendClasses.typeImplementation.rawType));
1125 } 1132 }
1126 lookupMapAnalysis.registerConstantKey(constant); 1133 lookupMapAnalysis.registerConstantKey(constant);
1127 } 1134 }
1128 1135
1129 void computeImpactForInstantiatedConstantType( 1136 void computeImpactForInstantiatedConstantType(
1130 DartType type, WorldImpactBuilder impactBuilder) { 1137 DartType type, WorldImpactBuilder impactBuilder) {
1131 DartType instantiatedType = 1138 DartType instantiatedType =
1132 type.isFunctionType ? coreTypes.functionType : type; 1139 type.isFunctionType ? coreTypes.functionType : type;
1133 if (type is InterfaceType) { 1140 if (type is InterfaceType) {
1134 impactBuilder 1141 impactBuilder
1135 .registerTypeUse(new TypeUse.instantiation(instantiatedType)); 1142 .registerTypeUse(new TypeUse.instantiation(instantiatedType));
1136 if (classNeedsRtiField(type.element)) { 1143 if (classNeedsRtiField(type.element)) {
1137 impactBuilder.registerStaticUse(new StaticUse.staticInvoke( 1144 impactBuilder.registerStaticUse(new StaticUse.staticInvoke(
1138 // TODO(johnniwinther): Find the right [CallStructure]. 1145 // TODO(johnniwinther): Find the right [CallStructure].
1139 helpers.setRuntimeTypeInfo, 1146 helpers.setRuntimeTypeInfo,
1140 null)); 1147 null));
1141 } 1148 }
1142 if (type.element == typeImplementation) { 1149 if (type.element == backendClasses.typeImplementation) {
1143 // If we use a type literal in a constant, the compile time 1150 // If we use a type literal in a constant, the compile time
1144 // constant emitter will generate a call to the createRuntimeType 1151 // constant emitter will generate a call to the createRuntimeType
1145 // helper so we register a use of that. 1152 // helper so we register a use of that.
1146 impactBuilder.registerStaticUse(new StaticUse.staticInvoke( 1153 impactBuilder.registerStaticUse(new StaticUse.staticInvoke(
1147 // TODO(johnniwinther): Find the right [CallStructure]. 1154 // TODO(johnniwinther): Find the right [CallStructure].
1148 helpers.createRuntimeType, 1155 helpers.createRuntimeType,
1149 null)); 1156 null));
1150 } 1157 }
1151 } 1158 }
1152 } 1159 }
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after
1890 bool mayGenerateInstanceofCheck(DartType type) { 1897 bool mayGenerateInstanceofCheck(DartType type) {
1891 // We can use an instanceof check for raw types that have no subclass that 1898 // We can use an instanceof check for raw types that have no subclass that
1892 // is mixed-in or in an implements clause. 1899 // is mixed-in or in an implements clause.
1893 1900
1894 if (!type.isRaw) return false; 1901 if (!type.isRaw) return false;
1895 ClassElement classElement = type.element; 1902 ClassElement classElement = type.element;
1896 if (isInterceptorClass(classElement)) return false; 1903 if (isInterceptorClass(classElement)) return false;
1897 return compiler.closedWorld.hasOnlySubclasses(classElement); 1904 return compiler.closedWorld.hasOnlySubclasses(classElement);
1898 } 1905 }
1899 1906
1900 bool isNullImplementation(ClassElement cls) {
1901 return cls == helpers.jsNullClass;
1902 }
1903
1904 ClassElement get intImplementation => helpers.jsIntClass;
1905 ClassElement get uint32Implementation => helpers.jsUInt32Class;
1906 ClassElement get uint31Implementation => helpers.jsUInt31Class;
1907 ClassElement get positiveIntImplementation => helpers.jsPositiveIntClass;
1908 ClassElement get doubleImplementation => helpers.jsDoubleClass;
1909 ClassElement get numImplementation => helpers.jsNumberClass;
1910 ClassElement get stringImplementation => helpers.jsStringClass;
1911 ClassElement get listImplementation => helpers.jsArrayClass;
1912 ClassElement get constListImplementation => helpers.jsUnmodifiableArrayClass;
1913 ClassElement get fixedListImplementation => helpers.jsFixedArrayClass;
1914 ClassElement get growableListImplementation => helpers.jsExtendableArrayClass;
1915 ClassElement get mapImplementation => helpers.mapLiteralClass;
1916 ClassElement get constMapImplementation => helpers.constMapLiteralClass;
1917 ClassElement get typeImplementation => helpers.typeLiteralClass;
1918 ClassElement get boolImplementation => helpers.jsBoolClass;
1919 ClassElement get nullImplementation => helpers.jsNullClass;
1920 ClassElement get syncStarIterableImplementation => helpers.syncStarIterable;
1921 ClassElement get asyncFutureImplementation => helpers.futureImplementation;
1922 ClassElement get asyncStarStreamImplementation => helpers.controllerStream;
1923
1924 void registerStaticUse(Element element, Enqueuer enqueuer) { 1907 void registerStaticUse(Element element, Enqueuer enqueuer) {
1925 if (element == helpers.disableTreeShakingMarker) { 1908 if (element == helpers.disableTreeShakingMarker) {
1926 isTreeShakingDisabled = true; 1909 isTreeShakingDisabled = true;
1927 } else if (element == helpers.preserveNamesMarker) { 1910 } else if (element == helpers.preserveNamesMarker) {
1928 mustPreserveNames = true; 1911 mustPreserveNames = true;
1929 } else if (element == helpers.preserveMetadataMarker) { 1912 } else if (element == helpers.preserveMetadataMarker) {
1930 mustRetainMetadata = true; 1913 mustRetainMetadata = true;
1931 } else if (element == helpers.preserveUrisMarker) { 1914 } else if (element == helpers.preserveUrisMarker) {
1932 if (compiler.options.preserveUris) mustPreserveUris = true; 1915 if (compiler.options.preserveUris) mustPreserveUris = true;
1933 } else if (element == helpers.preserveLibraryNamesMarker) { 1916 } else if (element == helpers.preserveLibraryNamesMarker) {
(...skipping 1316 matching lines...) Expand 10 before | Expand all | Expand 10 after
3250 3233
3251 @override 3234 @override
3252 void onImpactUsed(ImpactUseCase impactUse) { 3235 void onImpactUsed(ImpactUseCase impactUse) {
3253 if (impactUse == DeferredLoadTask.IMPACT_USE && !supportSerialization) { 3236 if (impactUse == DeferredLoadTask.IMPACT_USE && !supportSerialization) {
3254 // TODO(johnniwinther): Allow emptying when serialization has been 3237 // TODO(johnniwinther): Allow emptying when serialization has been
3255 // performed. 3238 // performed.
3256 resolution.emptyCache(); 3239 resolution.emptyCache();
3257 } 3240 }
3258 } 3241 }
3259 } 3242 }
3243
3244 class JavaScriptBackendClasses implements BackendClasses {
3245 final BackendHelpers helpers;
3246
3247 JavaScriptBackendClasses(this.helpers);
3248
3249 ClassElement get intImplementation => helpers.jsIntClass;
3250 ClassElement get uint32Implementation => helpers.jsUInt32Class;
3251 ClassElement get uint31Implementation => helpers.jsUInt31Class;
3252 ClassElement get positiveIntImplementation => helpers.jsPositiveIntClass;
3253 ClassElement get doubleImplementation => helpers.jsDoubleClass;
3254 ClassElement get numImplementation => helpers.jsNumberClass;
3255 ClassElement get stringImplementation => helpers.jsStringClass;
3256 ClassElement get listImplementation => helpers.jsArrayClass;
3257 ClassElement get constListImplementation => helpers.jsUnmodifiableArrayClass;
3258 ClassElement get fixedListImplementation => helpers.jsFixedArrayClass;
3259 ClassElement get growableListImplementation => helpers.jsExtendableArrayClass;
3260 ClassElement get mapImplementation => helpers.mapLiteralClass;
3261 ClassElement get constMapImplementation => helpers.constMapLiteralClass;
3262 ClassElement get typeImplementation => helpers.typeLiteralClass;
3263 ClassElement get boolImplementation => helpers.jsBoolClass;
3264 ClassElement get nullImplementation => helpers.jsNullClass;
3265 ClassElement get syncStarIterableImplementation => helpers.syncStarIterable;
3266 ClassElement get asyncFutureImplementation => helpers.futureImplementation;
3267 ClassElement get asyncStarStreamImplementation => helpers.controllerStream;
3268 ClassElement get functionImplementation => helpers.coreClasses.functionClass;
3269 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698