| Index: pkg/compiler/lib/src/universe/codegen_world_builder.dart
|
| diff --git a/pkg/compiler/lib/src/universe/codegen_world_builder.dart b/pkg/compiler/lib/src/universe/codegen_world_builder.dart
|
| index 0d17a9ef32835279f5b72348c83ae7ca2e782b78..6a7f84abd8b027687b6f27f74c0db22bc4557609 100644
|
| --- a/pkg/compiler/lib/src/universe/codegen_world_builder.dart
|
| +++ b/pkg/compiler/lib/src/universe/codegen_world_builder.dart
|
| @@ -48,6 +48,18 @@ abstract class CodegenWorldBuilder implements WorldBuilder {
|
|
|
| /// Set of methods in instantiated classes that are potentially closurized.
|
| Iterable<FunctionEntity> get closurizedMembers;
|
| +
|
| + /// Register [constant] as needed for emission.
|
| + void addCompileTimeConstantForEmission(ConstantValue constant);
|
| +
|
| + /// Returns a list of constants topologically sorted so that dependencies
|
| + /// appear before the dependent constant.
|
| + ///
|
| + /// [preSortCompare] is a comparator function that gives the constants a
|
| + /// consistent order prior to the topological sort which gives the constants
|
| + /// an ordering that is less sensitive to perturbations in the source code.
|
| + List<ConstantValue> getConstantsForEmission(
|
| + [Comparator<ConstantValue> preSortCompare]);
|
| }
|
|
|
| abstract class CodegenWorldBuilderImpl implements CodegenWorldBuilder {
|
| @@ -487,17 +499,53 @@ abstract class CodegenWorldBuilderImpl implements CodegenWorldBuilder {
|
| }
|
| }
|
|
|
| - bool registerConstantUse(ConstantUse use);
|
| + /// Set of all registered compiled constants.
|
| + final Set<ConstantValue> compiledConstants = new Set<ConstantValue>();
|
| +
|
| + @override
|
| + void addCompileTimeConstantForEmission(ConstantValue constant) {
|
| + compiledConstants.add(constant);
|
| + }
|
| +
|
| + @override
|
| + List<ConstantValue> getConstantsForEmission(
|
| + [Comparator<ConstantValue> preSortCompare]) {
|
| + // We must emit dependencies before their uses.
|
| + Set<ConstantValue> seenConstants = new Set<ConstantValue>();
|
| + List<ConstantValue> result = new List<ConstantValue>();
|
| +
|
| + void addConstant(ConstantValue constant) {
|
| + if (!seenConstants.contains(constant)) {
|
| + constant.getDependencies().forEach(addConstant);
|
| + assert(!seenConstants.contains(constant));
|
| + result.add(constant);
|
| + seenConstants.add(constant);
|
| + }
|
| + }
|
| +
|
| + List<ConstantValue> sorted = compiledConstants.toList();
|
| + if (preSortCompare != null) {
|
| + sorted.sort(preSortCompare);
|
| + }
|
| + sorted.forEach(addConstant);
|
| + return result;
|
| + }
|
| +
|
| + /// Register the constant [use] with this world builder. Returns `true` if
|
| + /// the constant use was new to the world.
|
| + bool registerConstantUse(ConstantUse use) {
|
| + if (use.kind == ConstantUseKind.DIRECT) {
|
| + addCompileTimeConstantForEmission(use.value);
|
| + }
|
| + return _constantValues.add(use.value);
|
| + }
|
| }
|
|
|
| class ElementCodegenWorldBuilderImpl extends CodegenWorldBuilderImpl {
|
| - final JavaScriptConstantCompiler _constants;
|
| -
|
| ElementCodegenWorldBuilderImpl(
|
| ElementEnvironment elementEnvironment,
|
| NativeBasicData nativeBasicData,
|
| ClosedWorld world,
|
| - this._constants,
|
| SelectorConstraintsStrategy selectorConstraintsStrategy)
|
| : super(elementEnvironment, nativeBasicData, world,
|
| selectorConstraintsStrategy);
|
| @@ -541,16 +589,6 @@ class ElementCodegenWorldBuilderImpl extends CodegenWorldBuilderImpl {
|
| super.registerStaticUse(staticUse, memberUsed);
|
| }
|
|
|
| - /// Register the constant [use] with this world builder. Returns `true` if
|
| - /// the constant use was new to the world.
|
| - @override
|
| - bool registerConstantUse(ConstantUse use) {
|
| - if (use.kind == ConstantUseKind.DIRECT) {
|
| - _constants.addCompileTimeConstantForEmission(use.value);
|
| - }
|
| - return _constantValues.add(use.value);
|
| - }
|
| -
|
| void registerIsCheck(ResolutionDartType type) {
|
| // Even in checked mode, type annotations for return type and argument
|
| // types do not imply type checks, so there should never be a check
|
| @@ -570,12 +608,6 @@ class KernelCodegenWorldBuilder extends CodegenWorldBuilderImpl {
|
| selectorConstraintsStrategy);
|
|
|
| @override
|
| - bool registerConstantUse(ConstantUse use) {
|
| - throw new UnimplementedError(
|
| - 'KernelCodegenWorldBuilder.registerConstantUse');
|
| - }
|
| -
|
| - @override
|
| void forEachParameter(
|
| FunctionEntity function, void f(DartType type, String name)) {
|
| throw new UnimplementedError('KernelCodegenWorldBuilder.forEachParameter');
|
|
|