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

Unified Diff: dart/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart

Issue 12033003: Deferred (aka lazy) loading of static functions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased Created 7 years, 10 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: dart/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart
diff --git a/dart/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart b/dart/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart
index c25a335ce8c54ed34d04910912117b1dc10d6ff3..f44f0b40fd44799f1edc2032652e1676e5ce3939 100644
--- a/dart/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart
+++ b/dart/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart
@@ -59,6 +59,7 @@ class CodeEmitterTask extends CompilerTask {
NativeEmitter nativeEmitter;
CodeBuffer boundClosureBuffer;
CodeBuffer mainBuffer;
+ final CodeBuffer deferredBuffer = new CodeBuffer();
/** Shorter access to [isolatePropertiesName]. Both here in the code, as
well as in the generated code. */
String isolateProperties;
@@ -1368,6 +1369,7 @@ $lazyInitializerLogic
}
for (ClassElement element in sortedClasses) {
+ if (isDeferred(element)) continue;
generateClass(element, buffer);
}
@@ -1396,7 +1398,7 @@ $lazyInitializerLogic
buffer.add('$N$n');
}
- void emitStaticFunctions(CodeBuffer buffer) {
+ void emitStaticFunctions(CodeBuffer eagerBuffer) {
bool isStaticFunction(Element element) =>
!element.isInstanceMember() && !element.isField();
@@ -1408,6 +1410,7 @@ $lazyInitializerLogic
.toSet();
for (Element element in Elements.sortedByPosition(elements)) {
+ CodeBuffer buffer = isDeferred(element) ? deferredBuffer : eagerBuffer;
js.Expression code = compiler.codegenWorld.generatedCode[element];
emitStaticFunction(buffer, namer.getName(element), code);
js.Expression bailoutCode =
@@ -1421,6 +1424,7 @@ $lazyInitializerLogic
// Is it possible the primary function was inlined but the bailout was not?
for (Element element in
Elements.sortedByPosition(pendingElementsWithBailouts)) {
+ CodeBuffer buffer = isDeferred(element) ? deferredBuffer : eagerBuffer;
js.Expression bailoutCode =
compiler.codegenWorld.generatedBailoutCode[element];
emitStaticFunction(buffer, namer.getBailoutName(element), bailoutCode);
@@ -1432,6 +1436,7 @@ $lazyInitializerLogic
compiler.codegenWorld.staticFunctionsNeedingGetter;
for (FunctionElement element in
Elements.sortedByPosition(functionsNeedingGetter)) {
+ if (isDeferred(element)) continue;
// The static function does not have the correct name. Since
// [addParameterStubs] use the name to create its stubs we simply
// create a fake element with the correct name.
@@ -2322,13 +2327,15 @@ if (typeof document !== 'undefined' && document.readyState !== 'complete') {
mainBuffer.add('}\n');
compiler.assembledCode = mainBuffer.getText();
- if (generateSourceMap) {
- SourceFile compiledFile = new SourceFile(null, compiler.assembledCode);
- String sourceMap = buildSourceMap(mainBuffer, compiledFile);
- compiler.outputProvider('', 'js.map')
- ..add(sourceMap)
+ if (!deferredBuffer.isEmpty) {
+ String code = deferredBuffer.getText();
+ compiler.outputProvider('part', 'js')
+ ..add(code)
..close();
+ outputSourceMap(deferredBuffer, compiler.assembledCode, 'part');
}
+
+ outputSourceMap(mainBuffer, compiler.assembledCode, '');
});
return compiler.assembledCode;
}
@@ -2338,6 +2345,19 @@ if (typeof document !== 'undefined' && document.readyState !== 'complete') {
buffer.forEachSourceLocation(sourceMapBuilder.addMapping);
return sourceMapBuilder.build(compiledFile);
}
+
+ void outputSourceMap(CodeBuffer buffer, String code, String name) {
+ if (!generateSourceMap) return;
+ SourceFile compiledFile = new SourceFile(null, compiler.assembledCode);
+ String sourceMap = buildSourceMap(mainBuffer, compiledFile);
+ compiler.outputProvider(name, 'js.map')
+ ..add(sourceMap)
+ ..close();
+ }
+
+ bool isDeferred(Element element) {
+ return compiler.deferredLoadTask.isDeferred(element);
+ }
}
const String GENERATED_BY = """

Powered by Google App Engine
This is Rietveld 408576698