| OLD | NEW |
| 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 855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 866 program = await fe.kernelForProgram(resolvedUri, options); | 866 program = await fe.kernelForProgram(resolvedUri, options); |
| 867 } | 867 } |
| 868 if (program == null) return null; | 868 if (program == null) return null; |
| 869 return createLoadedLibraries(program); | 869 return createLoadedLibraries(program); |
| 870 }); | 870 }); |
| 871 } | 871 } |
| 872 | 872 |
| 873 // Only visible for unit testing. | 873 // Only visible for unit testing. |
| 874 LoadedLibraries createLoadedLibraries(ir.Program program) { | 874 LoadedLibraries createLoadedLibraries(ir.Program program) { |
| 875 _elementMap.addProgram(program); | 875 _elementMap.addProgram(program); |
| 876 program.libraries.forEach((ir.Library library) => | |
| 877 _allLoadedLibraries.add(_elementMap.lookupLibrary(library.importUri))); | |
| 878 LibraryEntity rootLibrary = null; | 876 LibraryEntity rootLibrary = null; |
| 877 Iterable<ir.Library> libraries = program.libraries; |
| 879 if (program.mainMethod != null) { | 878 if (program.mainMethod != null) { |
| 880 rootLibrary = _elementMap | 879 var root = program.mainMethod.enclosingLibrary; |
| 881 .lookupLibrary(program.mainMethod.enclosingLibrary.importUri); | 880 rootLibrary = _elementMap.lookupLibrary(root.importUri); |
| 881 |
| 882 // Filter unreachable libraries: [Program] was built by linking in the |
| 883 // entire SDK libraries, not all of them are used. We include anything |
| 884 // that is reachable from `main`. Note that all internal libraries that |
| 885 // the compiler relies on are reachable from `dart:core`. |
| 886 var seen = new Set<Library>(); |
| 887 search(ir.Library current) { |
| 888 if (!seen.add(current)) return; |
| 889 for (ir.LibraryDependency dep in current.dependencies) { |
| 890 search(dep.targetLibrary); |
| 891 } |
| 892 } |
| 893 |
| 894 search(root); |
| 895 |
| 896 // Libraries dependencies do not show implicit imports to `dart:core`. |
| 897 var dartCore = program.libraries.firstWhere((lib) { |
| 898 return lib.importUri.scheme == 'dart' && lib.importUri.path == 'core'; |
| 899 }); |
| 900 search(dartCore); |
| 901 |
| 902 libraries = libraries.where(seen.contains); |
| 882 } | 903 } |
| 904 _allLoadedLibraries.addAll( |
| 905 libraries.map((lib) => _elementMap.lookupLibrary(lib.importUri))); |
| 883 return new _LoadedLibrariesAdapter( | 906 return new _LoadedLibrariesAdapter( |
| 884 rootLibrary, _allLoadedLibraries, _elementMap); | 907 rootLibrary, _allLoadedLibraries, _elementMap); |
| 885 } | 908 } |
| 886 | 909 |
| 887 KernelToElementMapForImpactImpl get elementMap => _elementMap; | 910 KernelToElementMapForImpactImpl get elementMap => _elementMap; |
| 888 | 911 |
| 889 void reset({bool reuseLibrary(LibraryElement library)}) { | 912 void reset({bool reuseLibrary(LibraryElement library)}) { |
| 890 throw new UnimplementedError('KernelLibraryLoaderTask.reset'); | 913 throw new UnimplementedError('KernelLibraryLoaderTask.reset'); |
| 891 } | 914 } |
| 892 | 915 |
| (...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1689 } | 1712 } |
| 1690 | 1713 |
| 1691 /// API used by the library loader to synchronously scan a library or | 1714 /// API used by the library loader to synchronously scan a library or |
| 1692 /// compilation unit and ensure that their library tags are computed. | 1715 /// compilation unit and ensure that their library tags are computed. |
| 1693 abstract class ElementScanner { | 1716 abstract class ElementScanner { |
| 1694 void scanLibrary(LibraryElement library); | 1717 void scanLibrary(LibraryElement library); |
| 1695 void scanUnit(CompilationUnitElement unit); | 1718 void scanUnit(CompilationUnitElement unit); |
| 1696 } | 1719 } |
| 1697 | 1720 |
| 1698 const _reuseLibrarySubtaskName = "Reuse library"; | 1721 const _reuseLibrarySubtaskName = "Reuse library"; |
| OLD | NEW |