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

Side by Side Diff: pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart

Issue 830463003: dart2js: collect static-non-final fields in the task. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 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 | Annotate | Revision Log
« no previous file with comments | « pkg/compiler/lib/src/js_emitter/code_emitter_task.dart ('k') | no next file » | 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 part of dart2js.js_emitter; 5 part of dart2js.js_emitter;
6 6
7 7
8 class OldEmitter implements Emitter { 8 class OldEmitter implements Emitter {
9 final Compiler compiler; 9 final Compiler compiler;
10 final CodeEmitterTask task; 10 final CodeEmitterTask task;
(...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 void emitStaticFunctions(List<Element> staticFunctions) { 760 void emitStaticFunctions(List<Element> staticFunctions) {
761 for (Element element in staticFunctions) { 761 for (Element element in staticFunctions) {
762 ClassBuilder builder = new ClassBuilder(element, namer); 762 ClassBuilder builder = new ClassBuilder(element, namer);
763 containerBuilder.addMember(element, builder); 763 containerBuilder.addMember(element, builder);
764 getElementDescriptor(element).properties.addAll(builder.properties); 764 getElementDescriptor(element).properties.addAll(builder.properties);
765 } 765 }
766 } 766 }
767 767
768 void emitStaticNonFinalFieldInitializations(CodeBuffer buffer, 768 void emitStaticNonFinalFieldInitializations(CodeBuffer buffer,
769 OutputUnit outputUnit) { 769 OutputUnit outputUnit) {
770 void emitInitialization(Element element, jsAst.Expression initialValue) {
771 jsAst.Expression init =
772 js('$isolateProperties.# = #',
773 [namer.getNameOfGlobalField(element), initialValue]);
774 buffer.write(jsAst.prettyPrint(init, compiler,
775 monitor: compiler.dumpInfoTask));
776 buffer.write('$N');
777 }
778
779 bool inMainUnit = (outputUnit == compiler.deferredLoadTask.mainOutputUnit);
770 JavaScriptConstantCompiler handler = backend.constants; 780 JavaScriptConstantCompiler handler = backend.constants;
771 Iterable<VariableElement> staticNonFinalFields =
772 handler.getStaticNonFinalFieldsForEmission();
773 for (Element element in Elements.sortedByPosition(staticNonFinalFields)) {
774 compiler.withCurrentElement(element, () {
775 jsAst.Expression initialValue;
776 if (outputUnit !=
777 compiler.deferredLoadTask.outputUnitForElement(element)) {
778 if (outputUnit == compiler.deferredLoadTask.mainOutputUnit) {
779 // In the main output-unit we output a stub initializer for deferred
780 // variables, such that `isolateProperties` stays a fast object.
781 initialValue = jsAst.number(0);
782 } else {
783 // Don't output stubs outside the main output file.
784 return;
785 }
786 } else {
787 initialValue = constantEmitter.referenceInInitializationContext(
788 handler.getInitialValueFor(element).value);
789 781
782 Iterable<Element> fields = task.outputStaticNonFinalFieldLists[outputUnit];
783 // If the outputUnit does not contain any static non-final fields, then
784 // [fields] is `null`.
785 if (fields != null) {
786 for (Element element in fields) {
787 compiler.withCurrentElement(element, () {
788 ConstantValue constant = handler.getInitialValueFor(element).value;
789 emitInitialization(
790 element,
791 constantEmitter.referenceInInitializationContext(constant));
792 });
793 }
794 }
795
796 if (inMainUnit && task.outputStaticNonFinalFieldLists.length > 1) {
797 // In the main output-unit we output a stub initializer for deferred
798 // variables, so that `isolateProperties` stays a fast object.
799 task.outputStaticNonFinalFieldLists.forEach(
800 (OutputUnit fieldsOutputUnit, Iterable<VariableElement> fields) {
801 if (fieldsOutputUnit == outputUnit) return; // Skip the main unit.
802 for (Element element in fields) {
803 compiler.withCurrentElement(element, () {
804 emitInitialization(element, jsAst.number(0));
805 });
790 } 806 }
791 jsAst.Expression init =
792 js('$isolateProperties.# = #',
793 [namer.getNameOfGlobalField(element), initialValue]);
794 buffer.write(jsAst.prettyPrint(init, compiler,
795 monitor: compiler.dumpInfoTask));
796 buffer.write('$N');
797 }); 807 });
798 } 808 }
799 } 809 }
800 810
801 void emitLazilyInitializedStaticFields(CodeBuffer buffer) { 811 void emitLazilyInitializedStaticFields(CodeBuffer buffer) {
802 JavaScriptConstantCompiler handler = backend.constants; 812 JavaScriptConstantCompiler handler = backend.constants;
803 List<VariableElement> lazyFields = 813 List<VariableElement> lazyFields =
804 handler.getLazilyInitializedFieldsForEmission(); 814 handler.getLazilyInitializedFieldsForEmission();
805 if (!lazyFields.isEmpty) { 815 if (!lazyFields.isEmpty) {
806 needsLazyInitializer = true; 816 needsLazyInitializer = true;
(...skipping 1252 matching lines...) Expand 10 before | Expand all | Expand 10 after
2059 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { 2069 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) {
2060 if (element.isInstanceMember) { 2070 if (element.isInstanceMember) {
2061 cachedClassBuilders.remove(element.enclosingClass); 2071 cachedClassBuilders.remove(element.enclosingClass);
2062 2072
2063 nativeEmitter.cachedBuilders.remove(element.enclosingClass); 2073 nativeEmitter.cachedBuilders.remove(element.enclosingClass);
2064 2074
2065 } 2075 }
2066 } 2076 }
2067 } 2077 }
2068 } 2078 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_emitter/code_emitter_task.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698