Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(613)

Side by Side Diff: pkg/compiler/lib/src/deferred_load.dart

Issue 2000323006: Make CompilerTask independent of compiler. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 final Map<_DeferredImport, ImportDescription> _deferredImportDescriptions = 145 final Map<_DeferredImport, ImportDescription> _deferredImportDescriptions =
146 <_DeferredImport, ImportDescription>{}; 146 <_DeferredImport, ImportDescription>{};
147 147
148 // For each deferred import we want to know exactly what elements have to 148 // For each deferred import we want to know exactly what elements have to
149 // be loaded. 149 // be loaded.
150 Map<_DeferredImport, Set<Element>> _importedDeferredBy = null; 150 Map<_DeferredImport, Set<Element>> _importedDeferredBy = null;
151 Map<_DeferredImport, Set<ConstantValue>> _constantsDeferredBy = null; 151 Map<_DeferredImport, Set<ConstantValue>> _constantsDeferredBy = null;
152 152
153 Set<Element> _mainElements = new Set<Element>(); 153 Set<Element> _mainElements = new Set<Element>();
154 154
155 DeferredLoadTask(Compiler compiler) : super(compiler) { 155 final Compiler compiler;
156 DeferredLoadTask(Compiler compiler)
157 : compiler = compiler,
158 super(compiler.measurer) {
156 mainOutputUnit.imports.add(_fakeMainImport); 159 mainOutputUnit.imports.add(_fakeMainImport);
157 } 160 }
158 161
159 Backend get backend => compiler.backend; 162 Backend get backend => compiler.backend;
163 DiagnosticReporter get reporter => compiler.reporter;
160 164
161 /// Returns the [OutputUnit] where [element] belongs. 165 /// Returns the [OutputUnit] where [element] belongs.
162 OutputUnit outputUnitForElement(Element element) { 166 OutputUnit outputUnitForElement(Element element) {
163 if (!isProgramSplit) return mainOutputUnit; 167 if (!isProgramSplit) return mainOutputUnit;
164 168
165 element = element.implementation; 169 element = element.implementation;
166 while (!_elementToOutputUnit.containsKey(element)) { 170 while (!_elementToOutputUnit.containsKey(element)) {
167 // TODO(21051): workaround: it looks like we output annotation constants 171 // TODO(21051): workaround: it looks like we output annotation constants
168 // for classes that we don't include in the output. This seems to happen 172 // for classes that we don't include in the output. This seems to happen
169 // when we have reflection but can see that some classes are not needed. 173 // when we have reflection but can see that some classes are not needed.
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 if (!isProgramSplit) { 626 if (!isProgramSplit) {
623 allOutputUnits.add(mainOutputUnit); 627 allOutputUnits.add(mainOutputUnit);
624 return; 628 return;
625 } 629 }
626 if (main == null) return; 630 if (main == null) return;
627 LibraryElement mainLibrary = main.library; 631 LibraryElement mainLibrary = main.library;
628 _importedDeferredBy = new Map<_DeferredImport, Set<Element>>(); 632 _importedDeferredBy = new Map<_DeferredImport, Set<Element>>();
629 _constantsDeferredBy = new Map<_DeferredImport, Set<ConstantValue>>(); 633 _constantsDeferredBy = new Map<_DeferredImport, Set<ConstantValue>>();
630 _importedDeferredBy[_fakeMainImport] = _mainElements; 634 _importedDeferredBy[_fakeMainImport] = _mainElements;
631 635
632 measureElement(mainLibrary, () { 636 reporter.withCurrentElement(mainLibrary, () => measure(() {
633 // Starting from main, traverse the program and find all dependencies. 637 // Starting from main, traverse the program and find all dependencies.
634 _mapDependencies(element: compiler.mainFunction, import: _fakeMainImport); 638 _mapDependencies(element: compiler.mainFunction, import: _fakeMainImport);
635 639
636 // Also add "global" dependencies to the main OutputUnit. These are 640 // Also add "global" dependencies to the main OutputUnit. These are
637 // things that the backend needs but cannot associate with a particular 641 // things that the backend needs but cannot associate with a particular
638 // element, for example, startRootIsolate. This set also contains 642 // element, for example, startRootIsolate. This set also contains
639 // elements for which we lack precise information. 643 // elements for which we lack precise information.
640 for (Element element in compiler.globalDependencies.otherDependencies) { 644 for (Element element in compiler.globalDependencies.otherDependencies) {
641 _mapDependencies(element: element, import: _fakeMainImport); 645 _mapDependencies(element: element, import: _fakeMainImport);
642 } 646 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 OutputUnit representative = allOutputUnits.lookup(outputUnit); 707 OutputUnit representative = allOutputUnits.lookup(outputUnit);
704 if (representative == null) { 708 if (representative == null) {
705 representative = outputUnit; 709 representative = outputUnit;
706 allOutputUnits.add(representative); 710 allOutputUnits.add(representative);
707 } 711 }
708 _constantToOutputUnit[constant] = representative; 712 _constantToOutputUnit[constant] = representative;
709 }); 713 });
710 714
711 // Generate a unique name for each OutputUnit. 715 // Generate a unique name for each OutputUnit.
712 _assignNamesToOutputUnits(allOutputUnits); 716 _assignNamesToOutputUnits(allOutputUnits);
713 }); 717 }));
714 // Notify the impact strategy impacts are no longer needed for deferred 718 // Notify the impact strategy impacts are no longer needed for deferred
715 // load. 719 // load.
716 compiler.impactStrategy.onImpactUsed(IMPACT_USE); 720 compiler.impactStrategy.onImpactUsed(IMPACT_USE);
717 } 721 }
718 722
719 void beforeResolution(Compiler compiler) { 723 void beforeResolution(Compiler compiler) {
720 if (compiler.mainApp == null) return; 724 if (compiler.mainApp == null) return;
721 _allDeferredImports[_fakeMainImport] = compiler.mainApp; 725 _allDeferredImports[_fakeMainImport] = compiler.mainApp;
722 var lastDeferred; 726 var lastDeferred;
723 // When detecting duplicate prefixes of deferred libraries there are 4 727 // When detecting duplicate prefixes of deferred libraries there are 4
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 return result; 1002 return result;
999 } 1003 }
1000 1004
1001 bool operator ==(other) { 1005 bool operator ==(other) {
1002 if (other is! _DeclaredDeferredImport) return false; 1006 if (other is! _DeclaredDeferredImport) return false;
1003 return declaration == other.declaration; 1007 return declaration == other.declaration;
1004 } 1008 }
1005 1009
1006 int get hashCode => declaration.hashCode * 17; 1010 int get hashCode => declaration.hashCode * 17;
1007 } 1011 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698