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

Unified Diff: pkg/compiler/lib/src/js_emitter/full_emitter/emitter.dart

Issue 1575603002: dart2js: lazily load fields in their own deferred parts (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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
« no previous file with comments | « no previous file | pkg/compiler/lib/src/js_emitter/program_builder/program_builder.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/js_emitter/full_emitter/emitter.dart
diff --git a/pkg/compiler/lib/src/js_emitter/full_emitter/emitter.dart b/pkg/compiler/lib/src/js_emitter/full_emitter/emitter.dart
index b16379f5465ca7a8aa2e072146d7a0ab08a2734e..00e187dcc5bd94db0a6b65fa85cca21c6ebd691f 100644
--- a/pkg/compiler/lib/src/js_emitter/full_emitter/emitter.dart
+++ b/pkg/compiler/lib/src/js_emitter/full_emitter/emitter.dart
@@ -674,13 +674,12 @@ class Emitter implements js_emitter.Emitter {
return new jsAst.Block(parts);
}
- jsAst.Statement buildLazilyInitializedStaticFields() {
- JavaScriptConstantCompiler handler = backend.constants;
- List<VariableElement> lazyFields =
- handler.getLazilyInitializedFieldsForEmission();
+ jsAst.Statement buildLazilyInitializedStaticFields(Fragment fragment) {
+ List<StaticField> lazyFields = fragment.staticLazilyInitializedFields;
if (lazyFields.isNotEmpty) {
needsLazyInitializer = true;
- List<jsAst.Expression> laziesInfo = buildLaziesInfo(lazyFields);
+ List<jsAst.Expression> laziesInfo =
+ buildLaziesInfo(lazyFields, fragment.isMainFragment);
return js.statement('''
(function(lazies) {
for (var i = 0; i < lazies.length; ) {
@@ -690,40 +689,51 @@ class Emitter implements js_emitter.Emitter {
var staticName = lazies[i++];
}
var lazyValue = lazies[i++];
-
+ if (#isDeferredFragment) {
+ var fieldHolder = lazies[i++];
+ }
// We build the lazy-check here:
// lazyInitializer(fieldName, getterName, lazyValue, staticName);
// 'staticName' is used for error reporting in non-minified mode.
// 'lazyValue' must be a closure that constructs the initial value.
- if (#notMinified) {
- #lazy(fieldName, getterName, lazyValue, staticName);
+ if (#isMainFragment) {
+ if (#notMinified) {
+ #lazy(fieldName, getterName, lazyValue, staticName);
+ } else {
+ #lazy(fieldName, getterName, lazyValue);
+ }
} else {
- #lazy(fieldName, getterName, lazyValue);
+ if (#notMinified) {
+ #lazy(fieldName, getterName, lazyValue, staticName, fieldHolder);
+ } else {
+ #lazy(fieldName, getterName, lazyValue, null, fieldHolder);
+ }
}
}
})(#laziesInfo)
''', {'notMinified': !compiler.enableMinification,
'laziesInfo': new jsAst.ArrayInitializer(laziesInfo),
- 'lazy': js(lazyInitializerName)});
+ 'lazy': js(lazyInitializerName),
+ 'isMainFragment': fragment.isMainFragment,
+ 'isDeferredFragment': !fragment.isMainFragment});
} else {
return js.comment("No lazy statics.");
}
}
- List<jsAst.Expression> buildLaziesInfo(List<VariableElement> lazies) {
+ List<jsAst.Expression> buildLaziesInfo(
+ List<StaticField> lazies, bool isMainFragment) {
List<jsAst.Expression> laziesInfo = <jsAst.Expression>[];
- for (VariableElement element in Elements.sortedByPosition(lazies)) {
- jsAst.Expression code = backend.generatedCode[element];
- // The code is null if we ended up not needing the lazily
Siggi Cherem (dart-lang) 2016/01/08 22:50:37 just to make sure I follow - we now emit null code
Harry Terkelsen 2016/01/11 18:01:21 We don't emit null code. The code here that filter
- // initialized field after all because of constant folding
- // before code generation.
- if (code == null) continue;
- laziesInfo.add(js.quoteName(namer.globalPropertyName(element)));
- laziesInfo.add(js.quoteName(namer.lazyInitializerName(element)));
+ for (StaticField field in lazies) {
+ laziesInfo.add(js.quoteName(field.name));
+ laziesInfo.add(js.quoteName(namer.deriveLazyInitializerName(field.name)));
Siggi Cherem (dart-lang) 2016/01/08 22:50:37 so this no longer makes the name globally unique,
Harry Terkelsen 2016/01/11 18:01:21 It seems to be working properly in my simple test
if (!compiler.enableMinification) {
- laziesInfo.add(js.string(element.name));
+ laziesInfo.add(js.quoteName(field.name));
+ }
+ laziesInfo.add(field.code);
+ if (!isMainFragment) {
+ laziesInfo.add(js('#', field.holder.name));
}
- laziesInfo.add(code);
}
return laziesInfo;
}
@@ -1570,7 +1580,7 @@ class Emitter implements js_emitter.Emitter {
mainOutputUnit),
"typeToInterceptorMap":
interceptorEmitter.buildTypeToInterceptorMap(program),
- "lazyStaticFields": buildLazilyInitializedStaticFields(),
+ "lazyStaticFields": buildLazilyInitializedStaticFields(mainFragment),
"metadata": buildMetadata(program, mainOutputUnit),
"convertToFastObject": buildConvertToFastObjectFunction(),
"convertToSlowObject": buildConvertToSlowObjectFunction(),
@@ -1996,6 +2006,7 @@ function(originalDescriptor, name, holder, isStatic, globalFunctionsAccess) {
body.add(buildCompileTimeConstants(fragment.constants,
isMainFragment: false));
body.add(buildStaticNonFinalFieldInitializations(outputUnit));
+ body.add(buildLazilyInitializedStaticFields(fragment));
List<jsAst.Statement> statements = <jsAst.Statement>[];
« no previous file with comments | « no previous file | pkg/compiler/lib/src/js_emitter/program_builder/program_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698