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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 dart2js.js_emitter.full_emitter; 5 library dart2js.js_emitter.full_emitter;
6 6
7 import 'dart:convert'; 7 import 'dart:convert';
8 import 'dart:collection' show HashMap; 8 import 'dart:collection' show HashMap;
9 9
10 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames; 10 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames;
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 reporter.withCurrentElement(element, () { 667 reporter.withCurrentElement(element, () {
668 parts.add(buildInitialization(element, jsAst.number(0))); 668 parts.add(buildInitialization(element, jsAst.number(0)));
669 }); 669 });
670 } 670 }
671 }); 671 });
672 } 672 }
673 673
674 return new jsAst.Block(parts); 674 return new jsAst.Block(parts);
675 } 675 }
676 676
677 jsAst.Statement buildLazilyInitializedStaticFields() { 677 jsAst.Statement buildLazilyInitializedStaticFields(
678 JavaScriptConstantCompiler handler = backend.constants; 678 Iterable<StaticField> lazyFields, {bool isMainFragment: true}) {
679 List<VariableElement> lazyFields =
680 handler.getLazilyInitializedFieldsForEmission();
681 if (lazyFields.isNotEmpty) { 679 if (lazyFields.isNotEmpty) {
682 needsLazyInitializer = true; 680 needsLazyInitializer = true;
683 List<jsAst.Expression> laziesInfo = buildLaziesInfo(lazyFields); 681 List<jsAst.Expression> laziesInfo =
682 buildLaziesInfo(lazyFields, isMainFragment);
684 return js.statement(''' 683 return js.statement('''
685 (function(lazies) { 684 (function(lazies) {
686 for (var i = 0; i < lazies.length; ) { 685 for (var i = 0; i < lazies.length; ) {
687 var fieldName = lazies[i++]; 686 var fieldName = lazies[i++];
688 var getterName = lazies[i++]; 687 var getterName = lazies[i++];
688 var lazyValue = lazies[i++];
689 if (#notMinified) { 689 if (#notMinified) {
690 var staticName = lazies[i++]; 690 var staticName = lazies[i++];
691 } 691 }
692 var lazyValue = lazies[i++]; 692 if (#isDeferredFragment) {
693 693 var fieldHolder = lazies[i++];
694 }
694 // We build the lazy-check here: 695 // We build the lazy-check here:
695 // lazyInitializer(fieldName, getterName, lazyValue, staticName); 696 // lazyInitializer(fieldName, getterName, lazyValue, staticName);
696 // 'staticName' is used for error reporting in non-minified mode. 697 // 'staticName' is used for error reporting in non-minified mode.
697 // 'lazyValue' must be a closure that constructs the initial value. 698 // 'lazyValue' must be a closure that constructs the initial value.
698 if (#notMinified) { 699 if (#isMainFragment) {
699 #lazy(fieldName, getterName, lazyValue, staticName); 700 if (#notMinified) {
701 #lazy(fieldName, getterName, lazyValue, staticName);
702 } else {
703 #lazy(fieldName, getterName, lazyValue);
704 }
700 } else { 705 } else {
701 #lazy(fieldName, getterName, lazyValue); 706 if (#notMinified) {
707 #lazy(fieldName, getterName, lazyValue, staticName, fieldHolder);
708 } else {
709 #lazy(fieldName, getterName, lazyValue, null, fieldHolder);
710 }
702 } 711 }
703 } 712 }
704 })(#laziesInfo) 713 })(#laziesInfo)
705 ''', {'notMinified': !compiler.enableMinification, 714 ''', {'notMinified': !compiler.enableMinification,
706 'laziesInfo': new jsAst.ArrayInitializer(laziesInfo), 715 'laziesInfo': new jsAst.ArrayInitializer(laziesInfo),
707 'lazy': js(lazyInitializerName)}); 716 'lazy': js(lazyInitializerName),
717 'isMainFragment': isMainFragment,
718 'isDeferredFragment': !isMainFragment});
708 } else { 719 } else {
709 return js.comment("No lazy statics."); 720 return js.comment("No lazy statics.");
710 } 721 }
711 } 722 }
712 723
713 List<jsAst.Expression> buildLaziesInfo(List<VariableElement> lazies) { 724 List<jsAst.Expression> buildLaziesInfo(
725 Iterable<StaticField> lazies, bool isMainFragment) {
714 List<jsAst.Expression> laziesInfo = <jsAst.Expression>[]; 726 List<jsAst.Expression> laziesInfo = <jsAst.Expression>[];
715 for (VariableElement element in Elements.sortedByPosition(lazies)) { 727 for (StaticField field in lazies) {
716 jsAst.Expression code = backend.generatedCode[element]; 728 laziesInfo.add(js.quoteName(field.name));
717 // The code is null if we ended up not needing the lazily 729 laziesInfo.add(js.quoteName(namer.deriveLazyInitializerName(field.name)));
718 // initialized field after all because of constant folding 730 laziesInfo.add(field.code);
719 // before code generation.
720 if (code == null) continue;
721 laziesInfo.add(js.quoteName(namer.globalPropertyName(element)));
722 laziesInfo.add(js.quoteName(namer.lazyInitializerName(element)));
723 if (!compiler.enableMinification) { 731 if (!compiler.enableMinification) {
724 laziesInfo.add(js.string(element.name)); 732 laziesInfo.add(js.quoteName(field.name));
725 } 733 }
726 laziesInfo.add(code); 734 if (!isMainFragment) {
735 laziesInfo.add(js('#', field.holder.name));
736 }
727 } 737 }
728 return laziesInfo; 738 return laziesInfo;
729 } 739 }
730 740
731 // TODO(sra): Remove this unused function. 741 // TODO(sra): Remove this unused function.
732 jsAst.Expression buildLazilyInitializedStaticField( 742 jsAst.Expression buildLazilyInitializedStaticField(
733 VariableElement element, {String isolateProperties}) { 743 VariableElement element, {String isolateProperties}) {
734 jsAst.Expression code = backend.generatedCode[element]; 744 jsAst.Expression code = backend.generatedCode[element];
735 // The code is null if we ended up not needing the lazily 745 // The code is null if we ended up not needing the lazily
736 // initialized field after all because of constant folding 746 // initialized field after all because of constant folding
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after
1563 "oneShotInterceptors": interceptorEmitter.buildOneShotInterceptors(), 1573 "oneShotInterceptors": interceptorEmitter.buildOneShotInterceptors(),
1564 "makeConstantList": 1574 "makeConstantList":
1565 buildMakeConstantList(program.outputContainsConstantList), 1575 buildMakeConstantList(program.outputContainsConstantList),
1566 "compileTimeConstants": buildCompileTimeConstants(mainFragment.constants, 1576 "compileTimeConstants": buildCompileTimeConstants(mainFragment.constants,
1567 isMainFragment: true), 1577 isMainFragment: true),
1568 "deferredBoilerPlate": buildDeferredBoilerPlate(deferredLoadHashes), 1578 "deferredBoilerPlate": buildDeferredBoilerPlate(deferredLoadHashes),
1569 "staticNonFinalInitializers": buildStaticNonFinalFieldInitializations( 1579 "staticNonFinalInitializers": buildStaticNonFinalFieldInitializations(
1570 mainOutputUnit), 1580 mainOutputUnit),
1571 "typeToInterceptorMap": 1581 "typeToInterceptorMap":
1572 interceptorEmitter.buildTypeToInterceptorMap(program), 1582 interceptorEmitter.buildTypeToInterceptorMap(program),
1573 "lazyStaticFields": buildLazilyInitializedStaticFields(), 1583 "lazyStaticFields": buildLazilyInitializedStaticFields(
1584 mainFragment.staticLazilyInitializedFields),
1574 "metadata": buildMetadata(program, mainOutputUnit), 1585 "metadata": buildMetadata(program, mainOutputUnit),
1575 "convertToFastObject": buildConvertToFastObjectFunction(), 1586 "convertToFastObject": buildConvertToFastObjectFunction(),
1576 "convertToSlowObject": buildConvertToSlowObjectFunction(), 1587 "convertToSlowObject": buildConvertToSlowObjectFunction(),
1577 "convertGlobalObjectsToFastObjects": 1588 "convertGlobalObjectsToFastObjects":
1578 buildConvertGlobalObjectToFastObjects(), 1589 buildConvertGlobalObjectToFastObjects(),
1579 "debugFastObjects": buildDebugFastObjectCode(), 1590 "debugFastObjects": buildDebugFastObjectCode(),
1580 "init": buildInitFunction(program.outputContainsConstantList), 1591 "init": buildInitFunction(program.outputContainsConstantList),
1581 "main": buildMain(mainFragment.invokeMain) 1592 "main": buildMain(mainFragment.invokeMain)
1582 })); 1593 }));
1583 1594
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
1989 js.statement('$setupProgramName(dart, ${typesAccess}.length);')); 2000 js.statement('$setupProgramName(dart, ${typesAccess}.length);'));
1990 } 2001 }
1991 2002
1992 body..add(buildMetadata(program, outputUnit)) 2003 body..add(buildMetadata(program, outputUnit))
1993 ..add(js.statement('${typesAccess}.push.apply(${typesAccess}, ' 2004 ..add(js.statement('${typesAccess}.push.apply(${typesAccess}, '
1994 '${namer.deferredTypesName});')); 2005 '${namer.deferredTypesName});'));
1995 2006
1996 body.add(buildCompileTimeConstants(fragment.constants, 2007 body.add(buildCompileTimeConstants(fragment.constants,
1997 isMainFragment: false)); 2008 isMainFragment: false));
1998 body.add(buildStaticNonFinalFieldInitializations(outputUnit)); 2009 body.add(buildStaticNonFinalFieldInitializations(outputUnit));
2010 body.add(buildLazilyInitializedStaticFields(
2011 fragment.staticLazilyInitializedFields, isMainFragment: false));
1999 2012
2000 List<jsAst.Statement> statements = <jsAst.Statement>[]; 2013 List<jsAst.Statement> statements = <jsAst.Statement>[];
2001 2014
2002 statements 2015 statements
2003 ..add(buildGeneratedBy()) 2016 ..add(buildGeneratedBy())
2004 ..add(buildDeferredHeader()) 2017 ..add(buildDeferredHeader())
2005 ..add(js.statement('${deferredInitializers}.current = ' 2018 ..add(js.statement('${deferredInitializers}.current = '
2006 """function (#, ${namer.staticStateHolder}) { 2019 """function (#, ${namer.staticStateHolder}) {
2007 # 2020 #
2008 } 2021 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
2130 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { 2143 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) {
2131 if (element.isInstanceMember) { 2144 if (element.isInstanceMember) {
2132 cachedClassBuilders.remove(element.enclosingClass); 2145 cachedClassBuilders.remove(element.enclosingClass);
2133 2146
2134 nativeEmitter.cachedBuilders.remove(element.enclosingClass); 2147 nativeEmitter.cachedBuilders.remove(element.enclosingClass);
2135 2148
2136 } 2149 }
2137 } 2150 }
2138 } 2151 }
2139 } 2152 }
OLDNEW
« 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