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 'dart2jslib.dart' show | 7 import 'dart2jslib.dart' show |
| 8 Compiler, | 8 Compiler, |
| 9 CompilerTask, | 9 CompilerTask, |
| 10 Constant, | 10 Constant, |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 /// The OutputUnit that will be loaded when the program starts. | 112 /// The OutputUnit that will be loaded when the program starts. |
| 113 final OutputUnit mainOutputUnit = new OutputUnit(); | 113 final OutputUnit mainOutputUnit = new OutputUnit(); |
| 114 | 114 |
| 115 /// A set containing (eventually) all output units that will result from the | 115 /// A set containing (eventually) all output units that will result from the |
| 116 /// program. | 116 /// program. |
| 117 final Set<OutputUnit> allOutputUnits = new Set<OutputUnit>(); | 117 final Set<OutputUnit> allOutputUnits = new Set<OutputUnit>(); |
| 118 | 118 |
| 119 /// Will be `true` if the program contains deferred libraries. | 119 /// Will be `true` if the program contains deferred libraries. |
| 120 bool splitProgram = false; | 120 bool splitProgram = false; |
| 121 | 121 |
| 122 /// A mapping from the name of a [DeferredLibrary] annotation to all dependent | 122 /// A mapping from the name of a defer import to all the output units it |
| 123 /// output units. | 123 /// depends on in a list of lists to be loaded in the order they appear. |
| 124 final Map<String, Set<OutputUnit>> hunksToLoad = | 124 /// |
| 125 new Map<String, Set<OutputUnit>>(); | 125 /// For example {"lib1": [[lib1_lib2_lib3], [lib1_lib2, lib1_lib3], |
| 126 /// [lib1]]} would mean that in order to load "lib1" first the hunk | |
| 127 /// lib1_lib2_lib2 should be loaded, then the hunks lib1_lib2 and lib1_lib3 | |
| 128 /// can be loaded in parallel. And finally lib1 can be loaded. | |
| 129 final Map<String, List<List<OutputUnit>>> hunksToLoad = | |
| 130 new Map<String, List<List<OutputUnit>>>(); | |
| 126 final Map<Import, String> importDeferName = new Map<Import, String>(); | 131 final Map<Import, String> importDeferName = new Map<Import, String>(); |
| 127 | 132 |
| 128 /// A mapping from elements and constants to their output unit. Query this via | 133 /// A mapping from elements and constants to their output unit. Query this via |
| 129 /// [outputUnitForElement] | 134 /// [outputUnitForElement] |
| 130 final Map<Element, OutputUnit> _elementToOutputUnit = | 135 final Map<Element, OutputUnit> _elementToOutputUnit = |
| 131 new Map<Element, OutputUnit>(); | 136 new Map<Element, OutputUnit>(); |
| 132 | 137 |
| 133 /// A mapping from constants to their output unit. Query this via | 138 /// A mapping from constants to their output unit. Query this via |
| 134 /// [outputUnitForConstant] | 139 /// [outputUnitForConstant] |
| 135 final Map<Constant, OutputUnit> _constantToOutputUnit = | 140 final Map<Constant, OutputUnit> _constantToOutputUnit = |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 601 generatedNames[outputUnit] = outputUnit.name; | 606 generatedNames[outputUnit] = outputUnit.name; |
| 602 } | 607 } |
| 603 | 608 |
| 604 for (Import import in _allDeferredImports.keys) { | 609 for (Import import in _allDeferredImports.keys) { |
| 605 computeImportDeferName(import); | 610 computeImportDeferName(import); |
| 606 } | 611 } |
| 607 | 612 |
| 608 for (OutputUnit outputUnit in allOutputUnits) { | 613 for (OutputUnit outputUnit in allOutputUnits) { |
| 609 computeOutputUnitName(outputUnit); | 614 computeOutputUnitName(outputUnit); |
| 610 } | 615 } |
| 616 List sortedOutputUnits = new List.from(allOutputUnits); | |
| 617 // Sort the outputunits in descending order of the number of imports they | |
|
floitsch
2014/04/02 09:32:48
output units
sigurdm
2014/04/02 11:25:30
Done.
| |
| 618 // include. | |
|
floitsch
2014/04/02 09:32:48
Explain why this is necessary and enough.
sigurdm
2014/04/02 11:25:30
I tried to explain it - hope it is not too verbose
| |
| 619 sortedOutputUnits.sort((a, b) => b.imports.length - a.imports.length); | |
| 611 | 620 |
| 612 // For each deferred import we find out which outputUnits to load. | 621 // For each deferred import we find out which outputUnits to load. |
| 613 for (Import import in _allDeferredImports.keys) { | 622 for (Import import in _allDeferredImports.keys) { |
| 614 if (import == _fakeMainImport) continue; | 623 if (import == _fakeMainImport) continue; |
| 615 hunksToLoad[importDeferName[import]] = new Set<OutputUnit>(); | 624 hunksToLoad[importDeferName[import]] = new List<List<OutputUnit>>(); |
| 616 for (OutputUnit outputUnit in allOutputUnits) { | 625 int lastNumberOfImports = 0; |
| 626 List<OutputUnit> currentLastList; | |
| 627 for (OutputUnit outputUnit in sortedOutputUnits) { | |
| 617 if (outputUnit == mainOutputUnit) continue; | 628 if (outputUnit == mainOutputUnit) continue; |
| 618 if (outputUnit.imports.contains(import)) { | 629 if (outputUnit.imports.contains(import)) { |
| 619 hunksToLoad[importDeferName[import]].add(outputUnit); | 630 if (outputUnit.imports.length != lastNumberOfImports) { |
| 631 lastNumberOfImports = outputUnit.imports.length; | |
| 632 currentLastList = new List<OutputUnit>(); | |
| 633 hunksToLoad[importDeferName[import]].add(currentLastList); | |
| 634 } | |
| 635 currentLastList.add(outputUnit); | |
| 620 } | 636 } |
| 621 } | 637 } |
| 622 } | 638 } |
| 623 } | 639 } |
| 624 | 640 |
| 625 void onResolutionComplete(FunctionElement main) { | 641 void onResolutionComplete(FunctionElement main) { |
| 626 if (!splitProgram) { | 642 if (!splitProgram) { |
| 627 allOutputUnits.add(mainOutputUnit); | 643 allOutputUnits.add(mainOutputUnit); |
| 628 return; | 644 return; |
| 629 } | 645 } |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 748 } | 764 } |
| 749 if (splitProgram && compiler.backend is DartBackend) { | 765 if (splitProgram && compiler.backend is DartBackend) { |
| 750 // TODO(sigurdm): Implement deferred loading for dart2dart. | 766 // TODO(sigurdm): Implement deferred loading for dart2dart. |
| 751 splitProgram = false; | 767 splitProgram = false; |
| 752 compiler.reportInfo( | 768 compiler.reportInfo( |
| 753 lastDeferred, | 769 lastDeferred, |
| 754 MessageKind.DEFERRED_LIBRARY_DART_2_DART); | 770 MessageKind.DEFERRED_LIBRARY_DART_2_DART); |
| 755 } | 771 } |
| 756 } | 772 } |
| 757 } | 773 } |
| OLD | NEW |