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

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

Issue 795923003: Dart2js, move deferred global vars to the right output unit. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments Created 6 years 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 | « no previous file | sdk/lib/_internal/compiler/js_lib/js_helper.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 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 976 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 } 987 }
988 988
989 void emitStaticFunctions(List<Element> staticFunctions) { 989 void emitStaticFunctions(List<Element> staticFunctions) {
990 for (Element element in staticFunctions) { 990 for (Element element in staticFunctions) {
991 ClassBuilder builder = new ClassBuilder(element, namer); 991 ClassBuilder builder = new ClassBuilder(element, namer);
992 containerBuilder.addMember(element, builder); 992 containerBuilder.addMember(element, builder);
993 getElementDescriptor(element).properties.addAll(builder.properties); 993 getElementDescriptor(element).properties.addAll(builder.properties);
994 } 994 }
995 } 995 }
996 996
997 void emitStaticNonFinalFieldInitializations(CodeBuffer buffer) { 997 void emitStaticNonFinalFieldInitializations(CodeBuffer buffer,
998 OutputUnit outputUnit) {
998 JavaScriptConstantCompiler handler = backend.constants; 999 JavaScriptConstantCompiler handler = backend.constants;
999 Iterable<VariableElement> staticNonFinalFields = 1000 Iterable<VariableElement> staticNonFinalFields =
1000 handler.getStaticNonFinalFieldsForEmission(); 1001 handler.getStaticNonFinalFieldsForEmission();
1001 for (Element element in Elements.sortedByPosition(staticNonFinalFields)) { 1002 for (Element element in Elements.sortedByPosition(staticNonFinalFields)) {
1002 // [:interceptedNames:] is handled in [emitInterceptedNames]. 1003 // [:interceptedNames:] is handled in [emitInterceptedNames].
1003 if (element == backend.interceptedNames) continue; 1004 if (element == backend.interceptedNames) continue;
1004 // `mapTypeToInterceptor` is handled in [emitMapTypeToInterceptor]. 1005 // `mapTypeToInterceptor` is handled in [emitMapTypeToInterceptor].
1005 if (element == backend.mapTypeToInterceptor) continue; 1006 if (element == backend.mapTypeToInterceptor) continue;
1006 compiler.withCurrentElement(element, () { 1007 compiler.withCurrentElement(element, () {
1007 ConstantValue initialValue = handler.getInitialValueFor(element).value; 1008 jsAst.Expression initialValue;
1009 if (outputUnit !=
1010 compiler.deferredLoadTask.outputUnitForElement(element)) {
1011 if (outputUnit == compiler.deferredLoadTask.mainOutputUnit) {
1012 // In the main output-unit we output a stub initializer for deferred
1013 // variables, such that `isolateProperties` stays a fast object.
1014 initialValue = jsAst.number(0);
1015 } else {
1016 // Don't output stubs outside the main output file.
1017 return;
1018 }
1019 } else {
1020 initialValue = constantEmitter.referenceInInitializationContext(
1021 handler.getInitialValueFor(element).value);
1022
1023 }
1008 jsAst.Expression init = 1024 jsAst.Expression init =
1009 js('$isolateProperties.# = #', 1025 js('$isolateProperties.# = #',
1010 [namer.getNameOfGlobalField(element), 1026 [namer.getNameOfGlobalField(element), initialValue]);
1011 constantEmitter.referenceInInitializationContext(initialValue)]);
1012 buffer.write(jsAst.prettyPrint(init, compiler, 1027 buffer.write(jsAst.prettyPrint(init, compiler,
1013 monitor: compiler.dumpInfoTask)); 1028 monitor: compiler.dumpInfoTask));
1014 buffer.write('$N'); 1029 buffer.write('$N');
1015 }); 1030 });
1016 } 1031 }
1017 } 1032 }
1018 1033
1019 void emitLazilyInitializedStaticFields(CodeBuffer buffer) { 1034 void emitLazilyInitializedStaticFields(CodeBuffer buffer) {
1020 JavaScriptConstantCompiler handler = backend.constants; 1035 JavaScriptConstantCompiler handler = backend.constants;
1021 List<VariableElement> lazyFields = 1036 List<VariableElement> lazyFields =
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after
1663 // Constants in checked mode call into RTI code to set type information 1678 // Constants in checked mode call into RTI code to set type information
1664 // which may need getInterceptor (and one-shot interceptor) methods, so 1679 // which may need getInterceptor (and one-shot interceptor) methods, so
1665 // we have to make sure that [emitGetInterceptorMethods] and 1680 // we have to make sure that [emitGetInterceptorMethods] and
1666 // [emitOneShotInterceptors] have been called. 1681 // [emitOneShotInterceptors] have been called.
1667 emitCompileTimeConstants(mainBuffer, mainOutputUnit); 1682 emitCompileTimeConstants(mainBuffer, mainOutputUnit);
1668 1683
1669 emitDeferredBoilerPlate(mainBuffer, deferredLoadHashes); 1684 emitDeferredBoilerPlate(mainBuffer, deferredLoadHashes);
1670 1685
1671 // Static field initializations require the classes and compile-time 1686 // Static field initializations require the classes and compile-time
1672 // constants to be set up. 1687 // constants to be set up.
1673 emitStaticNonFinalFieldInitializations(mainBuffer); 1688 emitStaticNonFinalFieldInitializations(mainBuffer, mainOutputUnit);
1674 interceptorEmitter.emitInterceptedNames(mainBuffer); 1689 interceptorEmitter.emitInterceptedNames(mainBuffer);
1675 interceptorEmitter.emitMapTypeToInterceptor(mainBuffer); 1690 interceptorEmitter.emitMapTypeToInterceptor(mainBuffer);
1676 emitLazilyInitializedStaticFields(mainBuffer); 1691 emitLazilyInitializedStaticFields(mainBuffer);
1677 1692
1678 mainBuffer.writeln(); 1693 mainBuffer.writeln();
1679 mainBuffer.add(nativeBuffer); 1694 mainBuffer.add(nativeBuffer);
1680 1695
1681 metadataEmitter.emitMetadata(mainBuffer); 1696 metadataEmitter.emitMetadata(mainBuffer);
1682 1697
1683 isolateProperties = isolatePropertiesName; 1698 isolateProperties = isolatePropertiesName;
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
2105 // the isolate-properties and for storing the current isolate. During 2120 // the isolate-properties and for storing the current isolate. During
2106 // the setup (the code above this lines) we must set the variable to 2121 // the setup (the code above this lines) we must set the variable to
2107 // the isolate-properties. 2122 // the isolate-properties.
2108 // After we have done the setup (finishing with `finishClasses`) it must 2123 // After we have done the setup (finishing with `finishClasses`) it must
2109 // point to the current Isolate. Otherwise all methods/functions 2124 // point to the current Isolate. Otherwise all methods/functions
2110 // accessing isolate variables will access the wrong object. 2125 // accessing isolate variables will access the wrong object.
2111 outputBuffer.write("${namer.currentIsolate}$_=${_}arguments[1]$N"); 2126 outputBuffer.write("${namer.currentIsolate}$_=${_}arguments[1]$N");
2112 typeTestEmitter.emitRuntimeTypeSupport(outputBuffer, outputUnit); 2127 typeTestEmitter.emitRuntimeTypeSupport(outputBuffer, outputUnit);
2113 2128
2114 emitCompileTimeConstants(outputBuffer, outputUnit); 2129 emitCompileTimeConstants(outputBuffer, outputUnit);
2130 emitStaticNonFinalFieldInitializations(outputBuffer, outputUnit);
2115 outputBuffer.write('}$N'); 2131 outputBuffer.write('}$N');
2116 2132
2117 if (compiler.useContentSecurityPolicy) { 2133 if (compiler.useContentSecurityPolicy) {
2118 jsAst.FunctionDeclaration precompiledFunctionAst = 2134 jsAst.FunctionDeclaration precompiledFunctionAst =
2119 buildCspPrecompiledFunctionFor(outputUnit); 2135 buildCspPrecompiledFunctionFor(outputUnit);
2120 2136
2121 outputBuffer.write( 2137 outputBuffer.write(
2122 jsAst.prettyPrint( 2138 jsAst.prettyPrint(
2123 precompiledFunctionAst, compiler, 2139 precompiledFunctionAst, compiler,
2124 monitor: compiler.dumpInfoTask, 2140 monitor: compiler.dumpInfoTask,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
2197 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { 2213 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) {
2198 if (element.isInstanceMember) { 2214 if (element.isInstanceMember) {
2199 cachedClassBuilders.remove(element.enclosingClass); 2215 cachedClassBuilders.remove(element.enclosingClass);
2200 2216
2201 nativeEmitter.cachedBuilders.remove(element.enclosingClass); 2217 nativeEmitter.cachedBuilders.remove(element.enclosingClass);
2202 2218
2203 } 2219 }
2204 } 2220 }
2205 } 2221 }
2206 } 2222 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/js_lib/js_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698