Chromium Code Reviews| Index: pkg/compiler/lib/src/js_backend/backend.dart |
| diff --git a/pkg/compiler/lib/src/js_backend/backend.dart b/pkg/compiler/lib/src/js_backend/backend.dart |
| index b0f9a82df29609e06f49cf76954fd248cbdd26b8..ae8ee2e192f77166411c9af0d2e1dc3cd55fd785 100644 |
| --- a/pkg/compiler/lib/src/js_backend/backend.dart |
| +++ b/pkg/compiler/lib/src/js_backend/backend.dart |
| @@ -235,6 +235,8 @@ class JavaScriptBackend extends Backend { |
| new Uri(scheme: 'dart', path: '_js_embedded_names'); |
| static final Uri DART_ISOLATE_HELPER = |
| new Uri(scheme: 'dart', path: '_isolate_helper'); |
| + static final Uri PACKAGE_LOOKUP_MAP = |
| + new Uri(scheme: 'package', path: 'lookup_map/lookup_map.dart'); |
| static final Uri DART_ASYNC = new Uri(scheme: 'dart', path: 'async'); |
| static final Uri DART_HTML = new Uri(scheme: 'dart', path: 'html'); |
| @@ -612,6 +614,9 @@ class JavaScriptBackend extends Backend { |
| /// constructors for custom elements. |
| CustomElementsAnalysis customElementsAnalysis; |
| + /// Codegen support for tree-shaking entries of `LookupMap`. |
| + LookupMapAnalysis lookupMapAnalysis; |
| + |
| /// Support for classifying `noSuchMethod` implementations. |
| NoSuchMethodRegistry noSuchMethodRegistry; |
| @@ -645,6 +650,7 @@ class JavaScriptBackend extends Backend { |
| compiler, namer, generateSourceMap, useStartupEmitter); |
| typeVariableHandler = new TypeVariableHandler(compiler); |
| customElementsAnalysis = new CustomElementsAnalysis(this); |
| + lookupMapAnalysis = new LookupMapAnalysis(this); |
| noSuchMethodRegistry = new NoSuchMethodRegistry(this); |
| constantCompilerTask = new JavaScriptConstantTask(compiler); |
| resolutionCallbacks = new JavaScriptResolutionCallbacks(this); |
| @@ -953,11 +959,23 @@ class JavaScriptBackend extends Backend { |
| } |
| } |
| - void registerCompileTimeConstant(ConstantValue constant, Registry registry) { |
| + void registerCompileTimeConstant(ConstantValue constant, Registry registry, |
| + {bool addForEmission: true}) { |
| registerCompileTimeConstantInternal(constant, registry); |
| + |
| + if (!registry.isForResolution && |
| + lookupMapAnalysis.isLookupMap(constant)) { |
| + // Note: internally, this registration will temporarily remove the |
| + // constant dependencies and add them later on-demand. |
| + lookupMapAnalysis.registerLookupMapReference(constant); |
| + } |
| + |
| for (ConstantValue dependency in constant.getDependencies()) { |
| - registerCompileTimeConstant(dependency, registry); |
| + registerCompileTimeConstant(dependency, registry, |
| + addForEmission: false); |
| } |
| + |
| + if (addForEmission) constants.addCompileTimeConstantForEmission(constant); |
| } |
| void registerCompileTimeConstantInternal(ConstantValue constant, |
| @@ -975,6 +993,11 @@ class JavaScriptBackend extends Backend { |
| } else if (constant.isType) { |
| enqueueInResolution(getCreateRuntimeType(), registry); |
| registry.registerInstantiation(typeImplementation.rawType); |
| + DartType representedType = |
| + (constant as TypeConstantValue).representedType; |
|
herhut
2015/09/02 12:59:57
Why use as here? I think the usual style is to cas
Siggi Cherem (dart-lang)
2015/09/03 00:44:28
Done.
|
| + if (representedType != const DynamicType()) { |
| + lookupMapAnalysis.registerTypeConstant(representedType.element); |
| + } |
| } |
| } |
| @@ -1000,7 +1023,7 @@ class JavaScriptBackend extends Backend { |
| Registry registry) { |
| assert(registry.isForResolution); |
| ConstantValue constant = constants.getConstantValueForMetadata(metadata); |
| - registerCompileTimeConstant(constant, registry); |
| + registerCompileTimeConstant(constant, registry, addForEmission: false); |
| metadataConstants.add(new Dependency(constant, annotatedElement)); |
| } |
| @@ -1133,6 +1156,13 @@ class JavaScriptBackend extends Backend { |
| } |
| customElementsAnalysis.registerInstantiatedClass(cls, enqueuer); |
| + if (!enqueuer.isResolutionQueue) { |
| + lookupMapAnalysis.registerInstantiatedClass(cls); |
| + } |
| + } |
| + |
| + void registerInstantiatedType(InterfaceType type, Registry registry) { |
| + lookupMapAnalysis.registerInstantiatedType(type, registry); |
| } |
| void registerUseInterceptor(Enqueuer enqueuer) { |
| @@ -1442,7 +1472,6 @@ class JavaScriptBackend extends Backend { |
| constants.getConstantValueForVariable(element); |
| if (initialValue != null) { |
| registerCompileTimeConstant(initialValue, work.registry); |
| - constants.addCompileTimeConstantForEmission(initialValue); |
| // We don't need to generate code for static or top-level |
| // variables. For instance variables, we may need to generate |
| // the checked setter. |
| @@ -2137,6 +2166,8 @@ class JavaScriptBackend extends Backend { |
| jsBuiltinEnum = find(library, 'JsBuiltin'); |
| } else if (uri == DART_HTML) { |
| htmlLibraryIsLoaded = true; |
| + } else if (uri == PACKAGE_LOOKUP_MAP) { |
| + lookupMapAnalysis.initRuntimeClass(find(library, 'LookupMap')); |
| } |
| annotations.onLibraryScanned(library); |
| }); |
| @@ -2530,6 +2561,7 @@ class JavaScriptBackend extends Backend { |
| // Add elements referenced only via custom elements. Return early if any |
| // elements are added to avoid counting the elements as due to mirrors. |
| customElementsAnalysis.onQueueEmpty(enqueuer); |
| + lookupMapAnalysis.onQueueEmpty(enqueuer); |
| if (!enqueuer.queueIsEmpty) return false; |
| noSuchMethodRegistry.onQueueEmpty(); |
| @@ -2573,7 +2605,8 @@ class JavaScriptBackend extends Backend { |
| registerCompileTimeConstant( |
| dependency.constant, |
| new CodegenRegistry(compiler, |
| - dependency.annotatedElement.analyzableElement.treeElements)); |
| + dependency.annotatedElement.analyzableElement.treeElements), |
| + addForEmission: false); |
| } |
| metadataConstants.clear(); |
| } |