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 'common/names.dart' show Uris; | 9 import 'common/names.dart' show Uris; |
10 import 'common/tasks.dart' show CompilerTask, Measurer; | 10 import 'common/tasks.dart' show CompilerTask, Measurer; |
11 import 'common.dart'; | 11 import 'common.dart'; |
12 import 'elements/elements.dart' | 12 import 'elements/elements.dart' |
13 show | 13 show |
14 CompilationUnitElement, | 14 CompilationUnitElement, |
15 Element, | 15 Element, |
16 ImportElement, | 16 ImportElement, |
17 ExportElement, | 17 ExportElement, |
18 LibraryElement; | 18 LibraryElement; |
| 19 import 'elements/entities.dart' show LibraryEntity; |
19 import 'elements/modelx.dart' | 20 import 'elements/modelx.dart' |
20 show | 21 show |
21 CompilationUnitElementX, | 22 CompilationUnitElementX, |
22 DeferredLoaderGetterElementX, | 23 DeferredLoaderGetterElementX, |
23 ErroneousElementX, | 24 ErroneousElementX, |
24 ExportElementX, | 25 ExportElementX, |
25 ImportElementX, | 26 ImportElementX, |
26 LibraryElementX, | 27 LibraryElementX, |
27 LibraryDependencyElementX, | 28 LibraryDependencyElementX, |
28 PrefixElementX, | 29 PrefixElementX, |
29 SyntheticImportElement; | 30 SyntheticImportElement; |
30 import 'enqueue.dart' show DeferredAction; | 31 import 'enqueue.dart' show DeferredAction; |
31 import 'environment.dart'; | 32 import 'environment.dart'; |
| 33 import 'kernel/world_builder.dart' show KernelWorldBuilder; |
32 import 'patch_parser.dart' show PatchParserTask; | 34 import 'patch_parser.dart' show PatchParserTask; |
33 import 'resolved_uri_translator.dart'; | 35 import 'resolved_uri_translator.dart'; |
34 import 'script.dart'; | 36 import 'script.dart'; |
35 import 'serialization/serialization.dart' show LibraryDeserializer; | 37 import 'serialization/serialization.dart' show LibraryDeserializer; |
36 import 'tree/tree.dart'; | 38 import 'tree/tree.dart'; |
37 import 'util/util.dart' show Link, LinkBuilder; | 39 import 'util/util.dart' show Link, LinkBuilder; |
38 | 40 |
| 41 import 'package:kernel/ast.dart' as ir; |
| 42 import 'package:kernel/binary/ast_from_binary.dart' show BinaryBuilder; |
| 43 |
39 typedef Future<Iterable<LibraryElement>> ReuseLibrariesFunction( | 44 typedef Future<Iterable<LibraryElement>> ReuseLibrariesFunction( |
40 Iterable<LibraryElement> libraries); | 45 Iterable<LibraryElement> libraries); |
41 | 46 |
42 typedef Uri PatchResolverFunction(String dartLibraryPath); | 47 typedef Uri PatchResolverFunction(String dartLibraryPath); |
43 | 48 |
44 /** | 49 /** |
45 * [CompilerTask] for loading libraries and setting up the import/export scopes. | 50 * [CompilerTask] for loading libraries and setting up the import/export scopes. |
46 * | 51 * |
47 * The library loader uses four different kinds of URIs in different parts of | 52 * The library loader uses four different kinds of URIs in different parts of |
48 * the loading process. | 53 * the loading process. |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 * | 135 * |
131 * import 'package:foo.dart' as a; | 136 * import 'package:foo.dart' as a; |
132 * import 'packages/foo.dart' as b; | 137 * import 'packages/foo.dart' as b; |
133 * | 138 * |
134 * do _not_ resolve to the same library when the package root URI happens to | 139 * do _not_ resolve to the same library when the package root URI happens to |
135 * point to the 'packages' folder. | 140 * point to the 'packages' folder. |
136 * | 141 * |
137 */ | 142 */ |
138 abstract class LibraryLoaderTask implements LibraryProvider, CompilerTask { | 143 abstract class LibraryLoaderTask implements LibraryProvider, CompilerTask { |
139 factory LibraryLoaderTask( | 144 factory LibraryLoaderTask( |
140 ResolvedUriTranslator uriTranslator, | 145 bool loadFromDillFile, |
141 ScriptLoader scriptLoader, | 146 ResolvedUriTranslator uriTranslator, |
142 ElementScanner scriptScanner, | 147 ScriptLoader scriptLoader, |
143 LibraryDeserializer deserializer, | 148 ElementScanner scriptScanner, |
144 PatchResolverFunction patchResolverFunc, | 149 LibraryDeserializer deserializer, |
145 PatchParserTask patchParser, | 150 PatchResolverFunction patchResolverFunc, |
146 Environment environment, | 151 PatchParserTask patchParser, |
147 DiagnosticReporter reporter, | 152 Environment environment, |
148 Measurer measurer) = _LibraryLoaderTask; | 153 DiagnosticReporter reporter, |
| 154 Measurer measurer) => |
| 155 loadFromDillFile |
| 156 ? new _DillLibraryLoaderTask( |
| 157 uriTranslator, scriptLoader, reporter, measurer) |
| 158 : new _LibraryLoaderTask( |
| 159 uriTranslator, |
| 160 scriptLoader, |
| 161 scriptScanner, |
| 162 deserializer, |
| 163 patchResolverFunc, |
| 164 patchParser, |
| 165 environment, |
| 166 reporter, |
| 167 measurer); |
149 | 168 |
150 /// Returns all libraries that have been loaded. | 169 /// Returns all libraries that have been loaded. |
151 Iterable<LibraryElement> get libraries; | 170 Iterable<LibraryEntity> get libraries; |
152 | 171 |
153 /// Loads the library specified by the [resolvedUri] and returns the | 172 /// Loads the library specified by the [resolvedUri] and returns the |
154 /// [LoadedLibraries] that were loaded to load the specified uri. The | 173 /// [LoadedLibraries] that were loaded to load the specified uri. The |
155 /// [LibraryElement] itself can be found by calling | 174 /// [LibraryElement] itself can be found by calling |
156 /// `loadedLibraries.rootLibrary`. | 175 /// `loadedLibraries.rootLibrary`. |
157 /// | 176 /// |
158 /// If the library is not already loaded, the method creates the | 177 /// If the library is not already loaded, the method creates the |
159 /// [LibraryElement] for the library and computes the import/export scope, | 178 /// [LibraryElement] for the library and computes the import/export scope, |
160 /// loading and computing the import/export scopes of all required libraries | 179 /// loading and computing the import/export scopes of all required libraries |
161 /// in the process. The method handles cyclic dependency between libraries. | 180 /// in the process. The method handles cyclic dependency between libraries. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 | 223 |
205 /// Returns the location of the patch-file associated with [libraryName] | 224 /// Returns the location of the patch-file associated with [libraryName] |
206 /// resolved from [plaformConfigUri]. | 225 /// resolved from [plaformConfigUri]. |
207 /// | 226 /// |
208 /// Returns null if there is none. | 227 /// Returns null if there is none. |
209 static Uri resolvePatchUri(String libraryName, Uri platformConfigUri) { | 228 static Uri resolvePatchUri(String libraryName, Uri platformConfigUri) { |
210 String patchLocation = _patchLocations[libraryName]; | 229 String patchLocation = _patchLocations[libraryName]; |
211 if (patchLocation == null) return null; | 230 if (patchLocation == null) return null; |
212 return platformConfigUri.resolve(patchLocation); | 231 return platformConfigUri.resolve(patchLocation); |
213 } | 232 } |
| 233 |
| 234 /// This is horrible temporary addition to the API that is only useful if we |
| 235 /// are loading kernel files. Otherwise this returns null. |
| 236 KernelWorldBuilder get worldBuilder; |
214 } | 237 } |
215 | 238 |
216 /// Interface for an entity that provide libraries. For instance from normal | 239 /// Interface for an entity that provide libraries. For instance from normal |
217 /// library loading or from deserialization. | 240 /// library loading or from deserialization. |
218 // TODO(johnniwinther): Use this to integrate deserialized libraries better. | 241 // TODO(johnniwinther): Use this to integrate deserialized libraries better. |
219 abstract class LibraryProvider { | 242 abstract class LibraryProvider { |
220 /// Looks up the library with the [canonicalUri]. | 243 /// Looks up the library with the [canonicalUri]. |
221 LibraryElement lookupLibrary(Uri canonicalUri); | 244 LibraryEntity lookupLibrary(Uri canonicalUri); |
222 } | 245 } |
223 | 246 |
224 /// Handle for creating synthesized/patch libraries during library loading. | 247 /// Handle for creating synthesized/patch libraries during library loading. |
225 abstract class LibraryLoader { | 248 abstract class LibraryLoader { |
226 /// This method must be called when a new synthesized/patch library has been | 249 /// This method must be called when a new synthesized/patch library has been |
227 /// created to ensure that [library] will part of library dependency graph | 250 /// created to ensure that [library] will part of library dependency graph |
228 /// used for computing import/export scopes. | 251 /// used for computing import/export scopes. |
229 void registerNewLibrary(LibraryElement library); | 252 void registerNewLibrary(LibraryElement library); |
230 | 253 |
231 /// This method must be called when a new synthesized/patch library has been | 254 /// This method must be called when a new synthesized/patch library has been |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 | 388 |
366 String get name => 'LibraryLoader'; | 389 String get name => 'LibraryLoader'; |
367 | 390 |
368 final Map<Uri, LibraryElement> libraryCanonicalUriMap = | 391 final Map<Uri, LibraryElement> libraryCanonicalUriMap = |
369 new Map<Uri, LibraryElement>(); | 392 new Map<Uri, LibraryElement>(); |
370 final Map<Uri, LibraryElement> libraryResourceUriMap = | 393 final Map<Uri, LibraryElement> libraryResourceUriMap = |
371 new Map<Uri, LibraryElement>(); | 394 new Map<Uri, LibraryElement>(); |
372 final Map<String, LibraryElement> libraryNames = | 395 final Map<String, LibraryElement> libraryNames = |
373 new Map<String, LibraryElement>(); | 396 new Map<String, LibraryElement>(); |
374 | 397 |
375 Iterable<LibraryElement> get libraries => libraryCanonicalUriMap.values; | 398 Iterable<LibraryEntity> get libraries => libraryCanonicalUriMap.values; |
376 | 399 |
377 LibraryElement lookupLibrary(Uri canonicalUri) { | 400 LibraryEntity lookupLibrary(Uri canonicalUri) { |
378 return libraryCanonicalUriMap[canonicalUri]; | 401 return libraryCanonicalUriMap[canonicalUri]; |
379 } | 402 } |
380 | 403 |
381 void reset({bool reuseLibrary(LibraryElement library)}) { | 404 void reset({bool reuseLibrary(LibraryElement library)}) { |
382 measure(() { | 405 measure(() { |
383 Iterable<LibraryElement> reusedLibraries = null; | 406 Iterable<LibraryElement> reusedLibraries = null; |
384 if (reuseLibrary != null) { | 407 if (reuseLibrary != null) { |
385 reusedLibraries = measureSubtask(_reuseLibrarySubtaskName, () { | 408 reusedLibraries = measureSubtask(_reuseLibrarySubtaskName, () { |
386 // Call [toList] to force eager calls to [reuseLibrary]. | 409 // Call [toList] to force eager calls to [reuseLibrary]. |
387 return libraryCanonicalUriMap.values.where(reuseLibrary).toList(); | 410 return libraryCanonicalUriMap.values.where(reuseLibrary).toList(); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 {bool skipFileWithPartOfTag: false}) { | 488 {bool skipFileWithPartOfTag: false}) { |
466 return measure(() async { | 489 return measure(() async { |
467 LibraryDependencyHandler handler = new LibraryDependencyHandler(this); | 490 LibraryDependencyHandler handler = new LibraryDependencyHandler(this); |
468 LibraryElement library = await createLibrary( | 491 LibraryElement library = await createLibrary( |
469 handler, null, resolvedUri, NO_LOCATION_SPANNABLE, | 492 handler, null, resolvedUri, NO_LOCATION_SPANNABLE, |
470 skipFileWithPartOfTag: skipFileWithPartOfTag); | 493 skipFileWithPartOfTag: skipFileWithPartOfTag); |
471 if (library == null) return null; | 494 if (library == null) return null; |
472 return reporter.withCurrentElement(library, () { | 495 return reporter.withCurrentElement(library, () { |
473 return measure(() { | 496 return measure(() { |
474 handler.computeExports(); | 497 handler.computeExports(); |
475 return new _LoadedLibraries(library, handler.newLibraries, this); | 498 return new _LoadedLibraries(library, handler.newLibraries); |
476 }); | 499 }); |
477 }); | 500 }); |
478 }); | 501 }); |
479 } | 502 } |
480 | 503 |
481 /** | 504 /** |
482 * Processes the library tags in [library]. | 505 * Processes the library tags in [library]. |
483 * | 506 * |
484 * The imported/exported libraries are loaded and processed recursively but | 507 * The imported/exported libraries are loaded and processed recursively but |
485 * the import/export scopes are not set up. | 508 * the import/export scopes are not set up. |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
802 | 825 |
803 void registerDeferredAction(DeferredAction action) { | 826 void registerDeferredAction(DeferredAction action) { |
804 _deferredActions.add(action); | 827 _deferredActions.add(action); |
805 } | 828 } |
806 | 829 |
807 Iterable<DeferredAction> pullDeferredActions() { | 830 Iterable<DeferredAction> pullDeferredActions() { |
808 Iterable<DeferredAction> actions = _deferredActions.toList(); | 831 Iterable<DeferredAction> actions = _deferredActions.toList(); |
809 _deferredActions.clear(); | 832 _deferredActions.clear(); |
810 return actions; | 833 return actions; |
811 } | 834 } |
| 835 |
| 836 KernelWorldBuilder get worldBuilder => null; |
| 837 } |
| 838 |
| 839 /// A task for loading a pre-processed .dill file into memory rather than |
| 840 /// parsing Dart source. Use of this task only makes sense when used in |
| 841 /// conjunction with --use-kernel. |
| 842 class _DillLibraryLoaderTask extends CompilerTask implements LibraryLoaderTask { |
| 843 final DiagnosticReporter reporter; |
| 844 |
| 845 final ResolvedUriTranslator uriTranslator; |
| 846 |
| 847 /// Loads the contents of a script file (a .dart file). Used when loading |
| 848 /// libraries from source. |
| 849 final ScriptLoader scriptLoader; |
| 850 |
| 851 /// Holds the mapping of Kernel IR to KElements that is constructed as a |
| 852 /// result of loading a program. |
| 853 KernelWorldBuilder _worldBuilder; |
| 854 |
| 855 List<LibraryEntity> _allLoadedLibraries; |
| 856 |
| 857 _DillLibraryLoaderTask( |
| 858 this.uriTranslator, this.scriptLoader, this.reporter, Measurer measurer) |
| 859 : _allLoadedLibraries = new List<LibraryEntity>(), |
| 860 super(measurer); |
| 861 |
| 862 /// Loads an entire Kernel [Program] from a file on disk (note, not just a |
| 863 /// library, so this name is actuall a bit of a misnomer). |
| 864 // TODO(efortuna): Rename this once the Element library loader class goes |
| 865 // away. |
| 866 Future<LoadedLibraries> loadLibrary(Uri resolvedUri, |
| 867 {bool skipFileWithPartOfTag: false}) { |
| 868 assert(resolvedUri.pathSegments.last.endsWith('.dill')); |
| 869 Uri readableUri = uriTranslator.translate(null, resolvedUri, null); |
| 870 return measure(() async { |
| 871 Script script = await scriptLoader.readScript(readableUri, null); |
| 872 ir.Program program = new ir.Program(); |
| 873 // Hack because the existing file has a terminating 0 and the |
| 874 // BinaryBuilder doesn't expect that. |
| 875 var bytes = new List<int>.from(script.file.slowUtf8ZeroTerminatedBytes()); |
| 876 bytes.removeLast(); |
| 877 new BinaryBuilder(bytes).readProgram(program); |
| 878 return measure(() { |
| 879 _worldBuilder = new KernelWorldBuilder(reporter, program); |
| 880 program.libraries.forEach((ir.Library library) => _allLoadedLibraries |
| 881 .add(_worldBuilder.lookupLibrary(library.importUri))); |
| 882 // TODO(efortuna): Handle `prgram.mainMethod == null` gracefully. |
| 883 return new _LoadedLibrariesAdapter( |
| 884 _worldBuilder |
| 885 .lookupLibrary(program.mainMethod.enclosingLibrary.importUri), |
| 886 _allLoadedLibraries, |
| 887 _worldBuilder); |
| 888 }); |
| 889 }); |
| 890 } |
| 891 |
| 892 KernelWorldBuilder get worldBuilder => _worldBuilder; |
| 893 |
| 894 void reset({bool reuseLibrary(LibraryElement library)}) { |
| 895 throw new UnimplementedError('_DillLibraryLoaderTask.reset'); |
| 896 } |
| 897 |
| 898 Future resetAsync(Future<bool> reuseLibrary(LibraryElement library)) { |
| 899 throw new UnimplementedError('_DillLibraryLoaderTask.resetAsync'); |
| 900 } |
| 901 |
| 902 Iterable<LibraryEntity> get libraries => _allLoadedLibraries; |
| 903 |
| 904 LibraryEntity lookupLibrary(Uri canonicalUri) { |
| 905 return _worldBuilder?.lookupLibrary(canonicalUri); |
| 906 } |
| 907 |
| 908 Future<Null> resetLibraries(ReuseLibrariesFunction reuseLibraries) { |
| 909 throw new UnimplementedError('_DillLibraryLoaderTask.reuseLibraries'); |
| 910 } |
| 911 |
| 912 void registerDeferredAction(DeferredAction action) { |
| 913 throw new UnimplementedError( |
| 914 '_DillLibraryLoaderTask.registerDeferredAction'); |
| 915 } |
| 916 |
| 917 Iterable<DeferredAction> pullDeferredActions() { |
| 918 throw new UnimplementedError('_DillLibraryLoaderTask.pullDeferredActions'); |
| 919 } |
812 } | 920 } |
813 | 921 |
814 /// A state machine for checking script tags come in the correct order. | 922 /// A state machine for checking script tags come in the correct order. |
815 class TagState { | 923 class TagState { |
816 /// Initial state. | 924 /// Initial state. |
817 static const int NO_TAG_SEEN = 0; | 925 static const int NO_TAG_SEEN = 0; |
818 | 926 |
819 /// Passed to [checkTag] when a library declaration (the syntax "library | 927 /// Passed to [checkTag] when a library declaration (the syntax "library |
820 /// name;") has been seen. Not an actual state. | 928 /// name;") has been seen. Not an actual state. |
821 static const int LIBRARY = 1; | 929 static const int LIBRARY = 1; |
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1375 Future processLibraryTags(LibraryElement library) { | 1483 Future processLibraryTags(LibraryElement library) { |
1376 return task.processLibraryTags(this, library); | 1484 return task.processLibraryTags(this, library); |
1377 } | 1485 } |
1378 } | 1486 } |
1379 | 1487 |
1380 /// Information on the set libraries loaded as a result of a call to | 1488 /// Information on the set libraries loaded as a result of a call to |
1381 /// [LibraryLoader.loadLibrary]. | 1489 /// [LibraryLoader.loadLibrary]. |
1382 abstract class LoadedLibraries { | 1490 abstract class LoadedLibraries { |
1383 /// The accesss the library object created corresponding to the library | 1491 /// The accesss the library object created corresponding to the library |
1384 /// passed to [LibraryLoader.loadLibrary]. | 1492 /// passed to [LibraryLoader.loadLibrary]. |
1385 LibraryElement get rootLibrary; | 1493 LibraryEntity get rootLibrary; |
1386 | 1494 |
1387 /// Returns `true` if a library with canonical [uri] was loaded in this bulk. | 1495 /// Returns `true` if a library with canonical [uri] was loaded in this bulk. |
1388 bool containsLibrary(Uri uri); | 1496 bool containsLibrary(Uri uri); |
1389 | 1497 |
1390 /// Returns the library with canonical [uri] that was loaded in this bulk. | 1498 /// Returns the library with canonical [uri] that was loaded in this bulk. |
1391 LibraryElement getLibrary(Uri uri); | 1499 LibraryEntity getLibrary(Uri uri); |
1392 | 1500 |
1393 /// Applies all libraries in this bulk to [f]. | 1501 /// Applies all libraries in this bulk to [f]. |
1394 void forEachLibrary(f(LibraryElement library)); | 1502 void forEachLibrary(f(LibraryEntity library)); |
1395 | 1503 |
1396 /// Applies all imports chains of [uri] in this bulk to [callback]. | 1504 /// Applies all imports chains of [uri] in this bulk to [callback]. |
1397 /// | 1505 /// |
1398 /// The argument [importChainReversed] to [callback] contains the chain of | 1506 /// The argument [importChainReversed] to [callback] contains the chain of |
1399 /// imports uris that lead to importing [uri] starting in [uri] and ending in | 1507 /// imports uris that lead to importing [uri] starting in [uri] and ending in |
1400 /// the uri that was passed in with [loadLibrary]. | 1508 /// the uri that was passed in with [loadLibrary]. |
1401 /// | 1509 /// |
1402 /// [callback] is called once for each chain of imports leading to [uri] until | 1510 /// [callback] is called once for each chain of imports leading to [uri] until |
1403 /// [callback] returns `false`. | 1511 /// [callback] returns `false`. |
1404 void forEachImportChain(Uri uri, | 1512 void forEachImportChain(Uri uri, |
1405 {bool callback(Link<Uri> importChainReversed)}); | 1513 {bool callback(Link<Uri> importChainReversed)}); |
1406 } | 1514 } |
1407 | 1515 |
1408 class _LoadedLibraries implements LoadedLibraries { | 1516 class _LoadedLibraries implements LoadedLibraries { |
1409 final _LibraryLoaderTask task; | |
1410 final LibraryElement rootLibrary; | 1517 final LibraryElement rootLibrary; |
1411 final Map<Uri, LibraryElement> loadedLibraries = <Uri, LibraryElement>{}; | 1518 final Map<Uri, LibraryElement> loadedLibraries = <Uri, LibraryElement>{}; |
1412 final List<LibraryElement> _newLibraries; | 1519 final List<LibraryElement> _newLibraries; |
1413 | 1520 |
1414 _LoadedLibraries(this.rootLibrary, this._newLibraries, this.task) { | 1521 _LoadedLibraries(this.rootLibrary, this._newLibraries) { |
1415 _newLibraries.forEach((LibraryElement loadedLibrary) { | 1522 _newLibraries.forEach((LibraryElement loadedLibrary) { |
1416 loadedLibraries[loadedLibrary.canonicalUri] = loadedLibrary; | 1523 loadedLibraries[loadedLibrary.canonicalUri] = loadedLibrary; |
1417 }); | 1524 }); |
1418 assert(rootLibrary != null); | 1525 assert(rootLibrary != null); |
1419 } | 1526 } |
1420 | 1527 |
1421 bool containsLibrary(Uri uri) => loadedLibraries.containsKey(uri); | 1528 bool containsLibrary(Uri uri) => loadedLibraries.containsKey(uri); |
1422 | 1529 |
1423 LibraryElement getLibrary(Uri uri) => loadedLibraries[uri]; | 1530 LibraryElement getLibrary(Uri uri) => loadedLibraries[uri]; |
1424 | 1531 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1497 suffixChainMap[library] = suffixes; | 1604 suffixChainMap[library] = suffixes; |
1498 return; | 1605 return; |
1499 } | 1606 } |
1500 | 1607 |
1501 computeSuffixes(rootLibrary, const Link<Uri>()); | 1608 computeSuffixes(rootLibrary, const Link<Uri>()); |
1502 } | 1609 } |
1503 | 1610 |
1504 String toString() => 'root=$rootLibrary,libraries=${_newLibraries}'; | 1611 String toString() => 'root=$rootLibrary,libraries=${_newLibraries}'; |
1505 } | 1612 } |
1506 | 1613 |
| 1614 /// Adapter class to mimic the behavior of LoadedLibraries for Kernel element |
| 1615 /// behavior. Ultimately we'll just access worldBuilder instead. |
| 1616 class _LoadedLibrariesAdapter implements LoadedLibraries { |
| 1617 final LibraryEntity rootLibrary; |
| 1618 final List<LibraryEntity> _newLibraries; |
| 1619 final KernelWorldBuilder worldBuilder; |
| 1620 |
| 1621 _LoadedLibrariesAdapter( |
| 1622 this.rootLibrary, this._newLibraries, this.worldBuilder) { |
| 1623 assert(rootLibrary != null); |
| 1624 } |
| 1625 |
| 1626 bool containsLibrary(Uri uri) => getLibrary(uri) != null; |
| 1627 |
| 1628 LibraryEntity getLibrary(Uri uri) => worldBuilder.lookupLibrary(uri); |
| 1629 |
| 1630 void forEachLibrary(f(LibraryEntity library)) => _newLibraries.forEach(f); |
| 1631 |
| 1632 void forEachImportChain(Uri uri, |
| 1633 {bool callback(Link<Uri> importChainReversed)}) { |
| 1634 // Currently a no-op. This seems wrong. |
| 1635 } |
| 1636 |
| 1637 String toString() => 'root=$rootLibrary,libraries=${_newLibraries}'; |
| 1638 } |
| 1639 |
1507 // TODO(sigmund): remove ScriptLoader & ElementScanner. Such abstraction seems | 1640 // TODO(sigmund): remove ScriptLoader & ElementScanner. Such abstraction seems |
1508 // rather low-level. It might be more practical to split the library-loading | 1641 // rather low-level. It might be more practical to split the library-loading |
1509 // task itself. The task would continue to do the work of recursively loading | 1642 // task itself. The task would continue to do the work of recursively loading |
1510 // dependencies, but it can delegate to a set of subloaders how to do the actual | 1643 // dependencies, but it can delegate to a set of subloaders how to do the actual |
1511 // loading. We would then have a list of subloaders that use different | 1644 // loading. We would then have a list of subloaders that use different |
1512 // implementations: in-memory cache, deserialization, scanning from files. | 1645 // implementations: in-memory cache, deserialization, scanning from files. |
1513 // | 1646 // |
1514 // For example, the API might look like this: | 1647 // For example, the API might look like this: |
1515 // | 1648 // |
1516 // /// APIs to create [LibraryElement] and [CompilationUnitElements] given it's | 1649 // /// APIs to create [LibraryElement] and [CompilationUnitElements] given it's |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1550 } | 1683 } |
1551 | 1684 |
1552 /// API used by the library loader to synchronously scan a library or | 1685 /// API used by the library loader to synchronously scan a library or |
1553 /// compilation unit and ensure that their library tags are computed. | 1686 /// compilation unit and ensure that their library tags are computed. |
1554 abstract class ElementScanner { | 1687 abstract class ElementScanner { |
1555 void scanLibrary(LibraryElement library); | 1688 void scanLibrary(LibraryElement library); |
1556 void scanUnit(CompilationUnitElement unit); | 1689 void scanUnit(CompilationUnitElement unit); |
1557 } | 1690 } |
1558 | 1691 |
1559 const _reuseLibrarySubtaskName = "Reuse library"; | 1692 const _reuseLibrarySubtaskName = "Reuse library"; |
OLD | NEW |