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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 dart2js.library_loader; 5 library dart2js.library_loader;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:front_end/front_end.dart' as fe; 9 import 'package:front_end/front_end.dart' as fe;
10 import 'package:kernel/ast.dart' as ir; 10 import 'package:kernel/ast.dart' as ir;
(...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 program = await fe.kernelForProgram(resolvedUri, options); 867 program = await fe.kernelForProgram(resolvedUri, options);
868 } 868 }
869 if (program == null) return null; 869 if (program == null) return null;
870 return createLoadedLibraries(program); 870 return createLoadedLibraries(program);
871 }); 871 });
872 } 872 }
873 873
874 // Only visible for unit testing. 874 // Only visible for unit testing.
875 LoadedLibraries createLoadedLibraries(ir.Program program) { 875 LoadedLibraries createLoadedLibraries(ir.Program program) {
876 _elementMap.addProgram(program); 876 _elementMap.addProgram(program);
877 program.libraries.forEach((ir.Library library) =>
878 _allLoadedLibraries.add(_elementMap.lookupLibrary(library.importUri)));
879 LibraryEntity rootLibrary = null; 877 LibraryEntity rootLibrary = null;
878 Iterable<ir.Library> libraries = program.libraries;
880 if (program.mainMethod != null) { 879 if (program.mainMethod != null) {
881 rootLibrary = _elementMap 880 var root = program.mainMethod.enclosingLibrary;
882 .lookupLibrary(program.mainMethod.enclosingLibrary.importUri); 881 rootLibrary = _elementMap.lookupLibrary(root.importUri);
882
883 // Filter unreachable libraries: [Program] was built by linking in the
884 // entire SDK libraries, not all of them are used. We include anything
885 // that is reachable from `main` and a few libraries that the compiler
886 // relies on.
887 var seen = new Set<Library>();
888 search(ir.Library current) {
889 if (!seen.add(current)) return;
890 for (ir.LibraryDependency dep in current.dependencies) {
891 search(dep.targetLibrary);
892 }
893 }
894
895 search(root);
896
897 const requiredLibraries = const [
898 '_foreign_helper',
899 '_interceptors',
900 '_internal',
901 '_js_embedded_names',
902 '_js_helpers',
903 '_native_typed_data',
sra1 2017/08/03 22:26:13 This will be a problem for the dart2js_native test
904 'async',
905 'core',
906 ];
907
908 for (var lib in libraries) {
909 var uri = lib.importUri;
910 if (uri.scheme != 'dart') continue;
911 if (requiredLibraries.contains(uri.path)) {
912 search(lib);
913 }
914 }
915
916 libraries = libraries.where(seen.contains);
883 } 917 }
918 _allLoadedLibraries.addAll(
919 libraries.map((lib) => _elementMap.lookupLibrary(lib.importUri)));
884 return new _LoadedLibrariesAdapter( 920 return new _LoadedLibrariesAdapter(
885 rootLibrary, _allLoadedLibraries, _elementMap); 921 rootLibrary, _allLoadedLibraries, _elementMap);
886 } 922 }
887 923
888 KernelToElementMapForImpactImpl get elementMap => _elementMap; 924 KernelToElementMapForImpactImpl get elementMap => _elementMap;
889 925
890 void reset({bool reuseLibrary(LibraryElement library)}) { 926 void reset({bool reuseLibrary(LibraryElement library)}) {
891 throw new UnimplementedError('KernelLibraryLoaderTask.reset'); 927 throw new UnimplementedError('KernelLibraryLoaderTask.reset');
892 } 928 }
893 929
(...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after
1690 } 1726 }
1691 1727
1692 /// API used by the library loader to synchronously scan a library or 1728 /// API used by the library loader to synchronously scan a library or
1693 /// compilation unit and ensure that their library tags are computed. 1729 /// compilation unit and ensure that their library tags are computed.
1694 abstract class ElementScanner { 1730 abstract class ElementScanner {
1695 void scanLibrary(LibraryElement library); 1731 void scanLibrary(LibraryElement library);
1696 void scanUnit(CompilationUnitElement unit); 1732 void scanUnit(CompilationUnitElement unit);
1697 } 1733 }
1698 1734
1699 const _reuseLibrarySubtaskName = "Reuse library"; 1735 const _reuseLibrarySubtaskName = "Reuse library";
OLDNEW
« 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