| 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/tasks.dart' show CompilerTask; | 7 import 'common/tasks.dart' show CompilerTask; |
| 8 import 'common.dart'; | 8 import 'common.dart'; |
| 9 import 'compiler.dart' show Compiler; | 9 import 'compiler.dart' show Compiler; |
| 10 import 'constants/expressions.dart' show ConstantExpression; | 10 import 'constants/expressions.dart' show ConstantExpression; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 ImportElement, | 27 ImportElement, |
| 28 LibraryElement, | 28 LibraryElement, |
| 29 MemberElement, | 29 MemberElement, |
| 30 MethodElement, | 30 MethodElement, |
| 31 MetadataAnnotation, | 31 MetadataAnnotation, |
| 32 PrefixElement, | 32 PrefixElement, |
| 33 ResolvedAstKind, | 33 ResolvedAstKind, |
| 34 TypedefElement; | 34 TypedefElement; |
| 35 import 'elements/entities.dart'; | 35 import 'elements/entities.dart'; |
| 36 import 'js_backend/js_backend.dart' show JavaScriptBackend; | 36 import 'js_backend/js_backend.dart' show JavaScriptBackend; |
| 37 import 'js_backend/backend_usage.dart' show BackendUsage; | |
| 38 import 'resolution/resolution.dart' show AnalyzableElementX; | 37 import 'resolution/resolution.dart' show AnalyzableElementX; |
| 39 import 'resolution/tree_elements.dart' show TreeElements; | 38 import 'resolution/tree_elements.dart' show TreeElements; |
| 40 import 'tree/tree.dart' as ast; | 39 import 'tree/tree.dart' as ast; |
| 41 import 'universe/use.dart' show StaticUse, StaticUseKind, TypeUse, TypeUseKind; | 40 import 'universe/use.dart' show StaticUse, StaticUseKind, TypeUse, TypeUseKind; |
| 42 import 'universe/world_impact.dart' | 41 import 'universe/world_impact.dart' |
| 43 show ImpactUseCase, WorldImpact, WorldImpactVisitorImpl; | 42 show ImpactUseCase, WorldImpact, WorldImpactVisitorImpl; |
| 44 import 'util/setlet.dart' show Setlet; | 43 import 'util/setlet.dart' show Setlet; |
| 45 import 'util/uri_extras.dart' as uri_extras; | 44 import 'util/uri_extras.dart' as uri_extras; |
| 46 import 'util/util.dart' show makeUnique; | 45 import 'util/util.dart' show makeUnique; |
| 46 import 'world.dart' show ClosedWorld; |
| 47 | 47 |
| 48 /// A "hunk" of the program that will be loaded whenever one of its [imports] | 48 /// A "hunk" of the program that will be loaded whenever one of its [imports] |
| 49 /// are loaded. | 49 /// are loaded. |
| 50 /// | 50 /// |
| 51 /// Elements that are only used in one deferred import, is in an OutputUnit with | 51 /// Elements that are only used in one deferred import, is in an OutputUnit with |
| 52 /// the deferred import as single element in the [imports] set. | 52 /// the deferred import as single element in the [imports] set. |
| 53 /// | 53 /// |
| 54 /// Whenever a deferred Element is shared between several deferred imports it is | 54 /// Whenever a deferred Element is shared between several deferred imports it is |
| 55 /// in an output unit with those imports in the [imports] Set. | 55 /// in an output unit with those imports in the [imports] Set. |
| 56 /// | 56 /// |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 | 155 |
| 156 final Compiler compiler; | 156 final Compiler compiler; |
| 157 DeferredLoadTask(Compiler compiler) | 157 DeferredLoadTask(Compiler compiler) |
| 158 : compiler = compiler, | 158 : compiler = compiler, |
| 159 super(compiler.measurer) { | 159 super(compiler.measurer) { |
| 160 mainOutputUnit.imports.add(_fakeMainImport); | 160 mainOutputUnit.imports.add(_fakeMainImport); |
| 161 } | 161 } |
| 162 | 162 |
| 163 JavaScriptBackend get backend => compiler.backend; | 163 JavaScriptBackend get backend => compiler.backend; |
| 164 DiagnosticReporter get reporter => compiler.reporter; | 164 DiagnosticReporter get reporter => compiler.reporter; |
| 165 BackendUsage get _backendUsage => backend.backendUsage; | |
| 166 | 165 |
| 167 /// Returns the [OutputUnit] where [element] belongs. | 166 /// Returns the [OutputUnit] where [element] belongs. |
| 168 OutputUnit outputUnitForElement(Element element) { | 167 OutputUnit outputUnitForElement(Element element) { |
| 169 if (!isProgramSplit) return mainOutputUnit; | 168 if (!isProgramSplit) return mainOutputUnit; |
| 170 | 169 |
| 171 element = element.implementation; | 170 element = element.implementation; |
| 172 while (!_elementToOutputUnit.containsKey(element)) { | 171 while (!_elementToOutputUnit.containsKey(element)) { |
| 173 // TODO(21051): workaround: it looks like we output annotation constants | 172 // TODO(21051): workaround: it looks like we output annotation constants |
| 174 // for classes that we don't include in the output. This seems to happen | 173 // for classes that we don't include in the output. This seems to happen |
| 175 // when we have reflection but can see that some classes are not needed. | 174 // when we have reflection but can see that some classes are not needed. |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 hunksToLoad[importDeferName[import]] = new List<OutputUnit>(); | 668 hunksToLoad[importDeferName[import]] = new List<OutputUnit>(); |
| 670 for (OutputUnit outputUnit in sortedOutputUnits) { | 669 for (OutputUnit outputUnit in sortedOutputUnits) { |
| 671 if (outputUnit == mainOutputUnit) continue; | 670 if (outputUnit == mainOutputUnit) continue; |
| 672 if (outputUnit.imports.contains(import)) { | 671 if (outputUnit.imports.contains(import)) { |
| 673 hunksToLoad[importDeferName[import]].add(outputUnit); | 672 hunksToLoad[importDeferName[import]].add(outputUnit); |
| 674 } | 673 } |
| 675 } | 674 } |
| 676 } | 675 } |
| 677 } | 676 } |
| 678 | 677 |
| 679 void onResolutionComplete(FunctionEntity main) { | 678 void onResolutionComplete(FunctionEntity main, ClosedWorld closedWorld) { |
| 680 if (!isProgramSplit) { | 679 if (!isProgramSplit) { |
| 681 allOutputUnits.add(mainOutputUnit); | 680 allOutputUnits.add(mainOutputUnit); |
| 682 return; | 681 return; |
| 683 } | 682 } |
| 684 if (main == null) return; | 683 if (main == null) return; |
| 685 MethodElement mainMethod = main; | 684 MethodElement mainMethod = main; |
| 686 LibraryElement mainLibrary = mainMethod.library; | 685 LibraryElement mainLibrary = mainMethod.library; |
| 687 _importedDeferredBy = new Map<_DeferredImport, Set<Element>>(); | 686 _importedDeferredBy = new Map<_DeferredImport, Set<Element>>(); |
| 688 _constantsDeferredBy = new Map<_DeferredImport, Set<ConstantValue>>(); | 687 _constantsDeferredBy = new Map<_DeferredImport, Set<ConstantValue>>(); |
| 689 _importedDeferredBy[_fakeMainImport] = _mainElements; | 688 _importedDeferredBy[_fakeMainImport] = _mainElements; |
| 690 | 689 |
| 691 reporter.withCurrentElement( | 690 reporter.withCurrentElement( |
| 692 mainLibrary, | 691 mainLibrary, |
| 693 () => measure(() { | 692 () => measure(() { |
| 694 // Starting from main, traverse the program and find all | 693 // Starting from main, traverse the program and find all |
| 695 // dependencies. | 694 // dependencies. |
| 696 _mapDependencies(element: mainMethod, import: _fakeMainImport); | 695 _mapDependencies(element: mainMethod, import: _fakeMainImport); |
| 697 | 696 |
| 698 // Also add "global" dependencies to the main OutputUnit. These | 697 // Also add "global" dependencies to the main OutputUnit. These |
| 699 // are things that the backend needs but cannot associate with a | 698 // are things that the backend needs but cannot associate with a |
| 700 // particular element, for example, startRootIsolate. This set | 699 // particular element, for example, startRootIsolate. This set |
| 701 // also contains elements for which we lack precise information. | 700 // also contains elements for which we lack precise information. |
| 702 for (MethodElement element | 701 for (MethodElement element |
| 703 in _backendUsage.globalFunctionDependencies) { | 702 in closedWorld.backendUsage.globalFunctionDependencies) { |
| 704 _mapDependencies( | 703 _mapDependencies( |
| 705 element: element.implementation, import: _fakeMainImport); | 704 element: element.implementation, import: _fakeMainImport); |
| 706 } | 705 } |
| 707 for (ClassElement element | 706 for (ClassElement element |
| 708 in _backendUsage.globalClassDependencies) { | 707 in closedWorld.backendUsage.globalClassDependencies) { |
| 709 _mapDependencies( | 708 _mapDependencies( |
| 710 element: element.implementation, import: _fakeMainImport); | 709 element: element.implementation, import: _fakeMainImport); |
| 711 } | 710 } |
| 712 | 711 |
| 713 // Now check to see if we have to add more elements due to | 712 // Now check to see if we have to add more elements due to |
| 714 // mirrors. | 713 // mirrors. |
| 715 if (compiler.commonElements.mirrorsLibrary != null) { | 714 if (compiler.commonElements.mirrorsLibrary != null) { |
| 716 _addMirrorElements(); | 715 _addMirrorElements(); |
| 717 } | 716 } |
| 718 | 717 |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1091 | 1090 |
| 1092 bool operator ==(other) { | 1091 bool operator ==(other) { |
| 1093 if (other is! _DeclaredDeferredImport) return false; | 1092 if (other is! _DeclaredDeferredImport) return false; |
| 1094 return declaration == other.declaration; | 1093 return declaration == other.declaration; |
| 1095 } | 1094 } |
| 1096 | 1095 |
| 1097 int get hashCode => declaration.hashCode * 17; | 1096 int get hashCode => declaration.hashCode * 17; |
| 1098 | 1097 |
| 1099 String toString() => '$declaration'; | 1098 String toString() => '$declaration'; |
| 1100 } | 1099 } |
| OLD | NEW |