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

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

Issue 2990233003: Filter unreachable libraries in kernel loader (Closed)
Patch Set: 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 | no next file » | 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 6bea483442eeb0adb0de94c71a80283b64202369..9ad77ee6ef0b151fa79acc471e221621d1714c7a 100644
--- a/pkg/compiler/lib/src/library_loader.dart
+++ b/pkg/compiler/lib/src/library_loader.dart
@@ -874,13 +874,49 @@ 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` and a few libraries that the compiler
+ // relies on.
+ 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);
+
+ const requiredLibraries = const [
+ '_foreign_helper',
+ '_interceptors',
+ '_internal',
+ '_js_embedded_names',
+ '_js_helpers',
+ '_native_typed_data',
sra1 2017/08/03 22:26:13 This will be a problem for the dart2js_native test
+ 'async',
+ 'core',
+ ];
+
+ for (var lib in libraries) {
+ var uri = lib.importUri;
+ if (uri.scheme != 'dart') continue;
+ if (requiredLibraries.contains(uri.path)) {
+ search(lib);
+ }
+ }
+
+ 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 | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698