Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 library deferred_load; | 5 library deferred_load; |
| 6 | 6 |
| 7 import 'common/backend_api.dart' show Backend; | 7 import 'common/backend_api.dart' show Backend; |
| 8 import 'common/tasks.dart' show CompilerTask; | 8 import 'common/tasks.dart' show CompilerTask; |
| 9 import 'common.dart'; | 9 import 'common.dart'; |
| 10 import 'compiler.dart' show Compiler; | 10 import 'compiler.dart' show Compiler; |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 219 bool hasOnlyNonDeferredImportPaths(Element from, Element to) { | 219 bool hasOnlyNonDeferredImportPaths(Element from, Element to) { |
| 220 OutputUnit outputUnitFrom = outputUnitForElement(from); | 220 OutputUnit outputUnitFrom = outputUnitForElement(from); |
| 221 OutputUnit outputUnitTo = outputUnitForElement(to); | 221 OutputUnit outputUnitTo = outputUnitForElement(to); |
| 222 return outputUnitTo.imports.containsAll(outputUnitFrom.imports); | 222 return outputUnitTo.imports.containsAll(outputUnitFrom.imports); |
| 223 } | 223 } |
| 224 | 224 |
| 225 void registerConstantDeferredUse( | 225 void registerConstantDeferredUse( |
| 226 DeferredConstantValue constant, PrefixElement prefix) { | 226 DeferredConstantValue constant, PrefixElement prefix) { |
| 227 OutputUnit outputUnit = new OutputUnit(); | 227 OutputUnit outputUnit = new OutputUnit(); |
| 228 outputUnit.imports.add(new _DeclaredDeferredImport(prefix.deferredImport)); | 228 outputUnit.imports.add(new _DeclaredDeferredImport(prefix.deferredImport)); |
| 229 _constantToOutputUnit[constant] = outputUnit; | 229 |
| 230 // Check to see if there is already a canonical output unit registered. | |
| 231 OutputUnit representative = allOutputUnits.lookup(outputUnit); | |
|
Siggi Cherem (dart-lang)
2016/09/07 18:10:44
I see this logic replicated in a few places, maybe
Siggi Cherem (dart-lang)
2016/09/07 18:14:09
reading more into this, it feels like we are doing
Harry Terkelsen
2016/09/07 23:53:50
Done.
Harry Terkelsen
2016/09/07 23:53:50
added a todo
| |
| 232 if (representative == null) { | |
| 233 representative = outputUnit; | |
| 234 allOutputUnits.add(representative); | |
| 235 } | |
| 236 _constantToOutputUnit[constant] = representative; | |
| 230 } | 237 } |
| 231 | 238 |
| 232 /// Answers whether [element] is explicitly deferred when referred to from | 239 /// Answers whether [element] is explicitly deferred when referred to from |
| 233 /// [library]. | 240 /// [library]. |
| 234 bool _isExplicitlyDeferred(Element element, LibraryElement library) { | 241 bool _isExplicitlyDeferred(Element element, LibraryElement library) { |
| 235 Iterable<ImportElement> imports = _getImports(element, library); | 242 Iterable<ImportElement> imports = _getImports(element, library); |
| 236 // If the element is not imported explicitly, it is implicitly imported | 243 // If the element is not imported explicitly, it is implicitly imported |
| 237 // not deferred. | 244 // not deferred. |
| 238 if (imports.isEmpty) return false; | 245 if (imports.isEmpty) return false; |
| 239 // An element could potentially be loaded by several imports. If all of them | 246 // An element could potentially be loaded by several imports. If all of them |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 672 if (compiler.commonElements.mirrorsLibrary != null) { | 679 if (compiler.commonElements.mirrorsLibrary != null) { |
| 673 _addMirrorElements(); | 680 _addMirrorElements(); |
| 674 } | 681 } |
| 675 | 682 |
| 676 // Build the OutputUnits using these two maps. | 683 // Build the OutputUnits using these two maps. |
| 677 Map<Element, OutputUnit> elementToOutputUnitBuilder = | 684 Map<Element, OutputUnit> elementToOutputUnitBuilder = |
| 678 new Map<Element, OutputUnit>(); | 685 new Map<Element, OutputUnit>(); |
| 679 Map<ConstantValue, OutputUnit> constantToOutputUnitBuilder = | 686 Map<ConstantValue, OutputUnit> constantToOutputUnitBuilder = |
| 680 new Map<ConstantValue, OutputUnit>(); | 687 new Map<ConstantValue, OutputUnit>(); |
| 681 | 688 |
| 689 // Add all constants that may have been registered during | |
| 690 // resolution with [registerConstantDeferredUse]. | |
|
Siggi Cherem (dart-lang)
2016/09/07 18:10:44
would it make sense to store those somewhere else
Harry Terkelsen
2016/09/07 23:53:50
I wanted to do that at first, but it would mean ha
| |
| 691 constantToOutputUnitBuilder.addAll(_constantToOutputUnit); | |
| 692 _constantToOutputUnit.clear(); | |
| 693 | |
| 682 // Reverse the mappings. For each element record an OutputUnit | 694 // Reverse the mappings. For each element record an OutputUnit |
| 683 // collecting all deferred imports mapped to this element. Same | 695 // collecting all deferred imports mapped to this element. Same |
| 684 // for constants. | 696 // for constants. |
| 685 for (_DeferredImport import in _importedDeferredBy.keys) { | 697 for (_DeferredImport import in _importedDeferredBy.keys) { |
| 686 for (Element element in _importedDeferredBy[import]) { | 698 for (Element element in _importedDeferredBy[import]) { |
| 687 // Only one file should be loaded when the program starts, so | 699 // Only one file should be loaded when the program starts, so |
| 688 // make sure that only one OutputUnit is created for | 700 // make sure that only one OutputUnit is created for |
| 689 // [fakeMainImport]. | 701 // [fakeMainImport]. |
| 690 if (import == _fakeMainImport) { | 702 if (import == _fakeMainImport) { |
| 691 elementToOutputUnitBuilder[element] = mainOutputUnit; | 703 elementToOutputUnitBuilder[element] = mainOutputUnit; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 728 } | 740 } |
| 729 _elementToOutputUnit[element] = representative; | 741 _elementToOutputUnit[element] = representative; |
| 730 }); | 742 }); |
| 731 constantToOutputUnitBuilder | 743 constantToOutputUnitBuilder |
| 732 .forEach((ConstantValue constant, OutputUnit outputUnit) { | 744 .forEach((ConstantValue constant, OutputUnit outputUnit) { |
| 733 OutputUnit representative = allOutputUnits.lookup(outputUnit); | 745 OutputUnit representative = allOutputUnits.lookup(outputUnit); |
| 734 if (representative == null) { | 746 if (representative == null) { |
| 735 representative = outputUnit; | 747 representative = outputUnit; |
| 736 allOutputUnits.add(representative); | 748 allOutputUnits.add(representative); |
| 737 } | 749 } |
| 738 _constantToOutputUnit[constant] = representative; | 750 _constantToOutputUnit[constant] = representative; |
|
Siggi Cherem (dart-lang)
2016/09/07 18:10:44
not sure if this would work, but another option wo
Harry Terkelsen
2016/09/07 23:53:50
the problem is that the 'registerConstantDeferredU
| |
| 739 }); | 751 }); |
| 740 | 752 |
| 741 // Generate a unique name for each OutputUnit. | 753 // Generate a unique name for each OutputUnit. |
| 742 _assignNamesToOutputUnits(allOutputUnits); | 754 _assignNamesToOutputUnits(allOutputUnits); |
| 743 })); | 755 })); |
| 744 // Notify the impact strategy impacts are no longer needed for deferred | 756 // Notify the impact strategy impacts are no longer needed for deferred |
| 745 // load. | 757 // load. |
| 746 compiler.impactStrategy.onImpactUsed(IMPACT_USE); | 758 compiler.impactStrategy.onImpactUsed(IMPACT_USE); |
| 747 } | 759 } |
| 748 | 760 |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1036 | 1048 |
| 1037 bool operator ==(other) { | 1049 bool operator ==(other) { |
| 1038 if (other is! _DeclaredDeferredImport) return false; | 1050 if (other is! _DeclaredDeferredImport) return false; |
| 1039 return declaration == other.declaration; | 1051 return declaration == other.declaration; |
| 1040 } | 1052 } |
| 1041 | 1053 |
| 1042 int get hashCode => declaration.hashCode * 17; | 1054 int get hashCode => declaration.hashCode * 17; |
| 1043 | 1055 |
| 1044 String toString() => '$declaration'; | 1056 String toString() => '$declaration'; |
| 1045 } | 1057 } |
| OLD | NEW |