Chromium Code Reviews| 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); |
| } |