| Index: pkg/compiler/lib/src/deferred_load.dart
|
| diff --git a/pkg/compiler/lib/src/deferred_load.dart b/pkg/compiler/lib/src/deferred_load.dart
|
| index 114bdcaaf8886442f87a8fc3b0fd7dbe63de1948..b4e586a8de10b3b67f5837caee73943ee882e17b 100644
|
| --- a/pkg/compiler/lib/src/deferred_load.dart
|
| +++ b/pkg/compiler/lib/src/deferred_load.dart
|
| @@ -222,11 +222,23 @@ class DeferredLoadTask extends CompilerTask {
|
| return outputUnitTo.imports.containsAll(outputUnitFrom.imports);
|
| }
|
|
|
| + // TODO(het): use a union-find to canonicalize output units
|
| + OutputUnit _getCanonicalUnit(OutputUnit outputUnit) {
|
| + OutputUnit representative = allOutputUnits.lookup(outputUnit);
|
| + if (representative == null) {
|
| + representative = outputUnit;
|
| + allOutputUnits.add(representative);
|
| + }
|
| + return representative;
|
| + }
|
| +
|
| void registerConstantDeferredUse(
|
| DeferredConstantValue constant, PrefixElement prefix) {
|
| OutputUnit outputUnit = new OutputUnit();
|
| outputUnit.imports.add(new _DeclaredDeferredImport(prefix.deferredImport));
|
| - _constantToOutputUnit[constant] = outputUnit;
|
| +
|
| + // Check to see if there is already a canonical output unit registered.
|
| + _constantToOutputUnit[constant] = _getCanonicalUnit(outputUnit);
|
| }
|
|
|
| /// Answers whether [element] is explicitly deferred when referred to from
|
| @@ -679,6 +691,11 @@ class DeferredLoadTask extends CompilerTask {
|
| Map<ConstantValue, OutputUnit> constantToOutputUnitBuilder =
|
| new Map<ConstantValue, OutputUnit>();
|
|
|
| + // Add all constants that may have been registered during
|
| + // resolution with [registerConstantDeferredUse].
|
| + constantToOutputUnitBuilder.addAll(_constantToOutputUnit);
|
| + _constantToOutputUnit.clear();
|
| +
|
| // Reverse the mappings. For each element record an OutputUnit
|
| // collecting all deferred imports mapped to this element. Same
|
| // for constants.
|
| @@ -721,21 +738,11 @@ class DeferredLoadTask extends CompilerTask {
|
| // to, and canonicalize them.
|
| elementToOutputUnitBuilder
|
| .forEach((Element element, OutputUnit outputUnit) {
|
| - OutputUnit representative = allOutputUnits.lookup(outputUnit);
|
| - if (representative == null) {
|
| - representative = outputUnit;
|
| - allOutputUnits.add(representative);
|
| - }
|
| - _elementToOutputUnit[element] = representative;
|
| + _elementToOutputUnit[element] = _getCanonicalUnit(outputUnit);
|
| });
|
| constantToOutputUnitBuilder
|
| .forEach((ConstantValue constant, OutputUnit outputUnit) {
|
| - OutputUnit representative = allOutputUnits.lookup(outputUnit);
|
| - if (representative == null) {
|
| - representative = outputUnit;
|
| - allOutputUnits.add(representative);
|
| - }
|
| - _constantToOutputUnit[constant] = representative;
|
| + _constantToOutputUnit[constant] = _getCanonicalUnit(outputUnit);
|
| });
|
|
|
| // Generate a unique name for each OutputUnit.
|
|
|