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 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 626 if (!isProgramSplit) { | 626 if (!isProgramSplit) { |
| 627 allOutputUnits.add(mainOutputUnit); | 627 allOutputUnits.add(mainOutputUnit); |
| 628 return; | 628 return; |
| 629 } | 629 } |
| 630 if (main == null) return; | 630 if (main == null) return; |
| 631 LibraryElement mainLibrary = main.library; | 631 LibraryElement mainLibrary = main.library; |
| 632 _importedDeferredBy = new Map<_DeferredImport, Set<Element>>(); | 632 _importedDeferredBy = new Map<_DeferredImport, Set<Element>>(); |
| 633 _constantsDeferredBy = new Map<_DeferredImport, Set<ConstantValue>>(); | 633 _constantsDeferredBy = new Map<_DeferredImport, Set<ConstantValue>>(); |
| 634 _importedDeferredBy[_fakeMainImport] = _mainElements; | 634 _importedDeferredBy[_fakeMainImport] = _mainElements; |
| 635 | 635 |
| 636 reporter.withCurrentElement(mainLibrary, () => measure(() { | 636 reporter.withCurrentElement( |
| 637 // Starting from main, traverse the program and find all dependencies. | 637 mainLibrary, |
|
Siggi Cherem (dart-lang)
2016/05/25 17:04:16
thanks!
| |
| 638 _mapDependencies(element: compiler.mainFunction, import: _fakeMainImport); | 638 () => measure(() { |
| 639 // Starting from main, traverse the program and find all | |
| 640 // dependencies. | |
| 641 _mapDependencies( | |
| 642 element: compiler.mainFunction, import: _fakeMainImport); | |
| 639 | 643 |
| 640 // Also add "global" dependencies to the main OutputUnit. These are | 644 // Also add "global" dependencies to the main OutputUnit. These |
| 641 // things that the backend needs but cannot associate with a particular | 645 // are things that the backend needs but cannot associate with a |
| 642 // element, for example, startRootIsolate. This set also contains | 646 // particular element, for example, startRootIsolate. This set |
| 643 // elements for which we lack precise information. | 647 // also contains elements for which we lack precise information. |
| 644 for (Element element in compiler.globalDependencies.otherDependencies) { | 648 for (Element element |
| 645 _mapDependencies(element: element, import: _fakeMainImport); | 649 in compiler.globalDependencies.otherDependencies) { |
| 646 } | 650 _mapDependencies(element: element, import: _fakeMainImport); |
| 651 } | |
| 647 | 652 |
| 648 // Now check to see if we have to add more elements due to mirrors. | 653 // Now check to see if we have to add more elements due to |
| 649 if (compiler.mirrorsLibrary != null) { | 654 // mirrors. |
| 650 _addMirrorElements(); | 655 if (compiler.mirrorsLibrary != null) { |
| 651 } | 656 _addMirrorElements(); |
| 657 } | |
| 652 | 658 |
| 653 // Build the OutputUnits using these two maps. | 659 // Build the OutputUnits using these two maps. |
| 654 Map<Element, OutputUnit> elementToOutputUnitBuilder = | 660 Map<Element, OutputUnit> elementToOutputUnitBuilder = |
| 655 new Map<Element, OutputUnit>(); | 661 new Map<Element, OutputUnit>(); |
| 656 Map<ConstantValue, OutputUnit> constantToOutputUnitBuilder = | 662 Map<ConstantValue, OutputUnit> constantToOutputUnitBuilder = |
| 657 new Map<ConstantValue, OutputUnit>(); | 663 new Map<ConstantValue, OutputUnit>(); |
| 658 | 664 |
| 659 // Reverse the mappings. For each element record an OutputUnit collecting | 665 // Reverse the mappings. For each element record an OutputUnit |
| 660 // all deferred imports mapped to this element. Same for constants. | 666 // collecting all deferred imports mapped to this element. Same |
| 661 for (_DeferredImport import in _importedDeferredBy.keys) { | 667 // for constants. |
| 662 for (Element element in _importedDeferredBy[import]) { | 668 for (_DeferredImport import in _importedDeferredBy.keys) { |
| 663 // Only one file should be loaded when the program starts, so make | 669 for (Element element in _importedDeferredBy[import]) { |
| 664 // sure that only one OutputUnit is created for [fakeMainImport]. | 670 // Only one file should be loaded when the program starts, so |
| 665 if (import == _fakeMainImport) { | 671 // make sure that only one OutputUnit is created for |
| 666 elementToOutputUnitBuilder[element] = mainOutputUnit; | 672 // [fakeMainImport]. |
| 667 } else { | 673 if (import == _fakeMainImport) { |
| 668 elementToOutputUnitBuilder | 674 elementToOutputUnitBuilder[element] = mainOutputUnit; |
| 669 .putIfAbsent(element, () => new OutputUnit()) | 675 } else { |
| 670 .imports | 676 elementToOutputUnitBuilder |
| 671 .add(import); | 677 .putIfAbsent(element, () => new OutputUnit()) |
| 672 } | 678 .imports |
| 673 } | 679 .add(import); |
| 674 } | 680 } |
| 675 for (_DeferredImport import in _constantsDeferredBy.keys) { | 681 } |
| 676 for (ConstantValue constant in _constantsDeferredBy[import]) { | 682 } |
| 677 // Only one file should be loaded when the program starts, so make | 683 for (_DeferredImport import in _constantsDeferredBy.keys) { |
| 678 // sure that only one OutputUnit is created for [fakeMainImport]. | 684 for (ConstantValue constant in _constantsDeferredBy[import]) { |
| 679 if (import == _fakeMainImport) { | 685 // Only one file should be loaded when the program starts, so |
| 680 constantToOutputUnitBuilder[constant] = mainOutputUnit; | 686 // make sure that only one OutputUnit is created for |
| 681 } else { | 687 // [fakeMainImport]. |
| 682 constantToOutputUnitBuilder | 688 if (import == _fakeMainImport) { |
| 683 .putIfAbsent(constant, () => new OutputUnit()) | 689 constantToOutputUnitBuilder[constant] = mainOutputUnit; |
| 684 .imports | 690 } else { |
| 685 .add(import); | 691 constantToOutputUnitBuilder |
| 686 } | 692 .putIfAbsent(constant, () => new OutputUnit()) |
| 687 } | 693 .imports |
| 688 } | 694 .add(import); |
| 695 } | |
| 696 } | |
| 697 } | |
| 689 | 698 |
| 690 // Release maps; | 699 // Release maps; |
| 691 _importedDeferredBy = null; | 700 _importedDeferredBy = null; |
| 692 _constantsDeferredBy = null; | 701 _constantsDeferredBy = null; |
| 693 | 702 |
| 694 // Find all the output units elements/constants have been mapped to, and | 703 // Find all the output units elements/constants have been mapped |
| 695 // canonicalize them. | 704 // to, and canonicalize them. |
| 696 elementToOutputUnitBuilder | 705 elementToOutputUnitBuilder |
| 697 .forEach((Element element, OutputUnit outputUnit) { | 706 .forEach((Element element, OutputUnit outputUnit) { |
| 698 OutputUnit representative = allOutputUnits.lookup(outputUnit); | 707 OutputUnit representative = allOutputUnits.lookup(outputUnit); |
| 699 if (representative == null) { | 708 if (representative == null) { |
| 700 representative = outputUnit; | 709 representative = outputUnit; |
| 701 allOutputUnits.add(representative); | 710 allOutputUnits.add(representative); |
| 702 } | 711 } |
| 703 _elementToOutputUnit[element] = representative; | 712 _elementToOutputUnit[element] = representative; |
| 704 }); | 713 }); |
| 705 constantToOutputUnitBuilder | 714 constantToOutputUnitBuilder |
| 706 .forEach((ConstantValue constant, OutputUnit outputUnit) { | 715 .forEach((ConstantValue constant, OutputUnit outputUnit) { |
| 707 OutputUnit representative = allOutputUnits.lookup(outputUnit); | 716 OutputUnit representative = allOutputUnits.lookup(outputUnit); |
| 708 if (representative == null) { | 717 if (representative == null) { |
| 709 representative = outputUnit; | 718 representative = outputUnit; |
| 710 allOutputUnits.add(representative); | 719 allOutputUnits.add(representative); |
| 711 } | 720 } |
| 712 _constantToOutputUnit[constant] = representative; | 721 _constantToOutputUnit[constant] = representative; |
| 713 }); | 722 }); |
| 714 | 723 |
| 715 // Generate a unique name for each OutputUnit. | 724 // Generate a unique name for each OutputUnit. |
| 716 _assignNamesToOutputUnits(allOutputUnits); | 725 _assignNamesToOutputUnits(allOutputUnits); |
| 717 })); | 726 })); |
| 718 // Notify the impact strategy impacts are no longer needed for deferred | 727 // Notify the impact strategy impacts are no longer needed for deferred |
| 719 // load. | 728 // load. |
| 720 compiler.impactStrategy.onImpactUsed(IMPACT_USE); | 729 compiler.impactStrategy.onImpactUsed(IMPACT_USE); |
| 721 } | 730 } |
| 722 | 731 |
| 723 void beforeResolution(Compiler compiler) { | 732 void beforeResolution(Compiler compiler) { |
| 724 if (compiler.mainApp == null) return; | 733 if (compiler.mainApp == null) return; |
| 725 _allDeferredImports[_fakeMainImport] = compiler.mainApp; | 734 _allDeferredImports[_fakeMainImport] = compiler.mainApp; |
| 726 var lastDeferred; | 735 var lastDeferred; |
| 727 // When detecting duplicate prefixes of deferred libraries there are 4 | 736 // When detecting duplicate prefixes of deferred libraries there are 4 |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1002 return result; | 1011 return result; |
| 1003 } | 1012 } |
| 1004 | 1013 |
| 1005 bool operator ==(other) { | 1014 bool operator ==(other) { |
| 1006 if (other is! _DeclaredDeferredImport) return false; | 1015 if (other is! _DeclaredDeferredImport) return false; |
| 1007 return declaration == other.declaration; | 1016 return declaration == other.declaration; |
| 1008 } | 1017 } |
| 1009 | 1018 |
| 1010 int get hashCode => declaration.hashCode * 17; | 1019 int get hashCode => declaration.hashCode * 17; |
| 1011 } | 1020 } |
| OLD | NEW |