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

Unified Diff: pkg/compiler/lib/src/js_backend/backend.dart

Issue 1320503003: dart2js: add initial support for lookup-maps (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 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 side-by-side diff with in-line comments
Download patch
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();
}

Powered by Google App Engine
This is Rietveld 408576698