Chromium Code Reviews| 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..ac9cf9fe6a86361fba6470e82e0431fa7c97a984 100644 |
| --- a/pkg/compiler/lib/src/universe/codegen_world_builder.dart |
| +++ b/pkg/compiler/lib/src/universe/codegen_world_builder.dart |
| @@ -48,6 +48,16 @@ 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 |
|
Siggi Cherem (dart-lang)
2017/06/01 22:28:43
nit: remove extra whitespace at the beginning of t
Johnni Winther
2017/06/02 11:17:24
Done.
|
| + /// 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([preSortCompare]); |
| } |
| abstract class CodegenWorldBuilderImpl implements CodegenWorldBuilder { |
| @@ -487,17 +497,57 @@ abstract class CodegenWorldBuilderImpl implements CodegenWorldBuilder { |
| } |
| } |
| - bool registerConstantUse(ConstantUse use); |
| + /** Set of all registered compiled constants. */ |
|
Siggi Cherem (dart-lang)
2017/06/01 22:28:43
nit: switch to ///
Johnni Winther
2017/06/02 11:17:24
Done.
|
| + final Set<ConstantValue> compiledConstants = new Set<ConstantValue>(); |
| + |
| + void addCompileTimeConstantForEmission(ConstantValue constant) { |
| + compiledConstants.add(constant); |
| + } |
| + |
| + /** |
| + * Returns a list of constants topologically sorted so that dependencies |
|
Siggi Cherem (dart-lang)
2017/06/01 22:28:43
delete comment? (use @override)
Johnni Winther
2017/06/02 11:17:24
Done.
|
| + * 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([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 +591,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 +610,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'); |