| Index: sdk/lib/_internal/compiler/implementation/js_emitter/code_emitter_task.dart
|
| diff --git a/sdk/lib/_internal/compiler/implementation/js_emitter/code_emitter_task.dart b/sdk/lib/_internal/compiler/implementation/js_emitter/code_emitter_task.dart
|
| index 41c78cd73255abd7f36481bddab5b857adaebfd9..907f99eaa468da7c37c625af053cb5fc3156b520 100644
|
| --- a/sdk/lib/_internal/compiler/implementation/js_emitter/code_emitter_task.dart
|
| +++ b/sdk/lib/_internal/compiler/implementation/js_emitter/code_emitter_task.dart
|
| @@ -33,6 +33,8 @@ class CodeEmitterTask extends CompilerTask {
|
| final Set<ClassElement> neededClasses = new Set<ClassElement>();
|
| final Map<OutputUnit, List<ClassElement>> outputClassLists =
|
| new Map<OutputUnit, List<ClassElement>>();
|
| + final Map<OutputUnit, List<Constant>> outputConstantLists =
|
| + new Map<OutputUnit, List<Constant>>();
|
| final List<ClassElement> nativeClasses = <ClassElement>[];
|
| final Map<String, String> mangledFieldNames = <String, String>{};
|
| final Map<String, String> mangledGlobalFieldNames = <String, String>{};
|
| @@ -416,13 +418,13 @@ class CodeEmitterTask extends CompilerTask {
|
|
|
| for (var cls in pendingClasses) finishClass(cls);
|
| }''', [
|
| - DEBUG_FAST_OBJECTS,
|
| + DEBUG_FAST_OBJECTS,
|
| backend.hasRetainedMetadata,
|
| needsMixinSupport,
|
| backend.isTreeShakingDisabled,
|
| buildFinishClass(),
|
| nsmEmitter.buildTrivialNsmHandlers()]);
|
| -
|
| +
|
| }
|
|
|
| jsAst.Node optional(bool condition, jsAst.Node node) {
|
| @@ -877,26 +879,9 @@ class CodeEmitterTask extends CompilerTask {
|
| }
|
|
|
| void emitCompileTimeConstants(CodeBuffer buffer, OutputUnit outputUnit) {
|
| - JavaScriptConstantCompiler handler = backend.constants;
|
| - List<Constant> constants = handler.getConstantsForEmission(
|
| - compareConstants);
|
| - Set<Constant> outputUnitConstants = null;
|
| - // TODO(sigurdm): We shouldn't run through all constants for every
|
| - // outputUnit.
|
| + List<Constant> constants = outputConstantLists[outputUnit];
|
| + if (constants == null) return;
|
| for (Constant constant in constants) {
|
| - if (isConstantInlinedOrAlreadyEmitted(constant)) continue;
|
| - OutputUnit constantUnit =
|
| - compiler.deferredLoadTask.outputUnitForConstant(constant);
|
| - if (constantUnit != outputUnit && constantUnit != null) continue;
|
| - if (outputUnit != compiler.deferredLoadTask.mainOutputUnit
|
| - && constantUnit == null) {
|
| - // The back-end introduces some constants, like "InterceptorConstant" or
|
| - // some list constants. They are emitted in the main output-unit, and
|
| - // ignored otherwise.
|
| - // TODO(sigurdm): We should track those constants.
|
| - continue;
|
| - }
|
| -
|
| String name = namer.constantName(constant);
|
| if (constant.isList) emitMakeConstantListIfNotEmitted(buffer);
|
| jsAst.Expression init = js('#.# = #',
|
| @@ -1077,6 +1062,28 @@ class CodeEmitterTask extends CompilerTask {
|
| }
|
|
|
| /**
|
| + * Compute all the constants that must be emitted.
|
| + */
|
| + void computeNeededConstants() {
|
| + JavaScriptConstantCompiler handler = backend.constants;
|
| + List<Constant> constants = handler.getConstantsForEmission(
|
| + compareConstants);
|
| + for (Constant constant in constants) {
|
| + if (isConstantInlinedOrAlreadyEmitted(constant)) continue;
|
| + OutputUnit constantUnit =
|
| + compiler.deferredLoadTask.outputUnitForConstant(constant);
|
| + if (constantUnit == null) {
|
| + // The back-end introduces some constants, like "InterceptorConstant" or
|
| + // some list constants. They are emitted in the main output-unit.
|
| + // TODO(sigurdm): We should track those constants.
|
| + constantUnit = compiler.deferredLoadTask.mainOutputUnit;
|
| + }
|
| + outputConstantLists.putIfAbsent(constantUnit, () => new List<Constant>())
|
| + .add(constant);
|
| + }
|
| + }
|
| +
|
| + /**
|
| * Compute all the classes that must be emitted.
|
| */
|
| void computeNeededClasses() {
|
| @@ -1426,6 +1433,7 @@ mainBuffer.add(r'''
|
| // which may need getInterceptor (and one-shot interceptor) methods, so
|
| // we have to make sure that [emitGetInterceptorMethods] and
|
| // [emitOneShotInterceptors] have been called.
|
| + computeNeededConstants();
|
| emitCompileTimeConstants(mainBuffer, mainOutputUnit);
|
|
|
| // Write a javascript mapping from Deferred import load ids (derrived from
|
|
|