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

Unified Diff: pkg/compiler/lib/src/library_loader.dart

Issue 2990233003: Filter unreachable libraries in kernel loader (Closed)
Patch Set: include core, format update script Created 3 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/compiler/tool/status_files/update_all.sh » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/library_loader.dart
diff --git a/pkg/compiler/lib/src/library_loader.dart b/pkg/compiler/lib/src/library_loader.dart
index a76dcc0710045899b312a8296dff740b8c810794..38c768c3eaca0df8b027fd52678124d26709c84d 100644
--- a/pkg/compiler/lib/src/library_loader.dart
+++ b/pkg/compiler/lib/src/library_loader.dart
@@ -873,13 +873,36 @@ class KernelLibraryLoaderTask extends CompilerTask
// Only visible for unit testing.
LoadedLibraries createLoadedLibraries(ir.Program program) {
_elementMap.addProgram(program);
- program.libraries.forEach((ir.Library library) =>
- _allLoadedLibraries.add(_elementMap.lookupLibrary(library.importUri)));
LibraryEntity rootLibrary = null;
+ Iterable<ir.Library> libraries = program.libraries;
if (program.mainMethod != null) {
- rootLibrary = _elementMap
- .lookupLibrary(program.mainMethod.enclosingLibrary.importUri);
+ var root = program.mainMethod.enclosingLibrary;
+ rootLibrary = _elementMap.lookupLibrary(root.importUri);
+
+ // Filter unreachable libraries: [Program] was built by linking in the
+ // entire SDK libraries, not all of them are used. We include anything
+ // that is reachable from `main`. Note that all internal libraries that
+ // the compiler relies on are reachable from `dart:core`.
+ var seen = new Set<Library>();
+ search(ir.Library current) {
+ if (!seen.add(current)) return;
+ for (ir.LibraryDependency dep in current.dependencies) {
+ search(dep.targetLibrary);
+ }
+ }
+
+ search(root);
+
+ // Libraries dependencies do not show implicit imports to `dart:core`.
+ var dartCore = program.libraries.firstWhere((lib) {
+ return lib.importUri.scheme == 'dart' && lib.importUri.path == 'core';
+ });
+ search(dartCore);
+
+ libraries = libraries.where(seen.contains);
}
+ _allLoadedLibraries.addAll(
+ libraries.map((lib) => _elementMap.lookupLibrary(lib.importUri)));
return new _LoadedLibrariesAdapter(
rootLibrary, _allLoadedLibraries, _elementMap);
}
« no previous file with comments | « no previous file | pkg/compiler/tool/status_files/update_all.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698