| 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; | 10 import 'common/tasks.dart' show CompilerTask; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 LibraryDependencyElementX, | 28 LibraryDependencyElementX, |
| 29 PrefixElementX, | 29 PrefixElementX, |
| 30 SyntheticImportElement; | 30 SyntheticImportElement; |
| 31 import 'environment.dart'; | 31 import 'environment.dart'; |
| 32 import 'resolved_uri_translator.dart'; | 32 import 'resolved_uri_translator.dart'; |
| 33 import 'script.dart'; | 33 import 'script.dart'; |
| 34 import 'serialization/serialization.dart' show LibraryDeserializer; | 34 import 'serialization/serialization.dart' show LibraryDeserializer; |
| 35 import 'tree/tree.dart'; | 35 import 'tree/tree.dart'; |
| 36 import 'util/util.dart' show Link, LinkBuilder; | 36 import 'util/util.dart' show Link, LinkBuilder; |
| 37 | 37 |
| 38 typedef Future<Iterable<LibraryElement>> ReuseLibrariesFunction( |
| 39 Iterable<LibraryElement> libraries); |
| 40 |
| 38 /** | 41 /** |
| 39 * [CompilerTask] for loading libraries and setting up the import/export scopes. | 42 * [CompilerTask] for loading libraries and setting up the import/export scopes. |
| 40 * | 43 * |
| 41 * The library loader uses four different kinds of URIs in different parts of | 44 * The library loader uses four different kinds of URIs in different parts of |
| 42 * the loading process. | 45 * the loading process. |
| 43 * | 46 * |
| 44 * ## User URI ## | 47 * ## User URI ## |
| 45 * | 48 * |
| 46 * A 'user URI' is a URI provided by the user in code and as the main entry URI | 49 * A 'user URI' is a URI provided by the user in code and as the main entry URI |
| 47 * at the command line. These generally come in 3 versions: | 50 * at the command line. These generally come in 3 versions: |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 {bool skipFileWithPartOfTag: false}); | 163 {bool skipFileWithPartOfTag: false}); |
| 161 | 164 |
| 162 /// Reset the library loader task to prepare for compilation. If provided, | 165 /// Reset the library loader task to prepare for compilation. If provided, |
| 163 /// libraries matching [reuseLibrary] are reused. | 166 /// libraries matching [reuseLibrary] are reused. |
| 164 /// | 167 /// |
| 165 /// This method is used for incremental compilation. | 168 /// This method is used for incremental compilation. |
| 166 void reset({bool reuseLibrary(LibraryElement library)}); | 169 void reset({bool reuseLibrary(LibraryElement library)}); |
| 167 | 170 |
| 168 /// Asynchronous version of [reset]. | 171 /// Asynchronous version of [reset]. |
| 169 Future resetAsync(Future<bool> reuseLibrary(LibraryElement library)); | 172 Future resetAsync(Future<bool> reuseLibrary(LibraryElement library)); |
| 173 |
| 174 /// Similar to [resetAsync] but [reuseLibrary] maps all libraries to a list |
| 175 /// of libraries that can be reused. |
| 176 Future<Null> resetLibraries(ReuseLibrariesFunction reuseLibraries); |
| 170 } | 177 } |
| 171 | 178 |
| 172 /// Handle for creating synthesized/patch libraries during library loading. | 179 /// Handle for creating synthesized/patch libraries during library loading. |
| 173 abstract class LibraryLoader { | 180 abstract class LibraryLoader { |
| 174 /// This method must be called when a new synthesized/patch library has been | 181 /// This method must be called when a new synthesized/patch library has been |
| 175 /// created to ensure that [library] will part of library dependency graph | 182 /// created to ensure that [library] will part of library dependency graph |
| 176 /// used for computing import/export scopes. | 183 /// used for computing import/export scopes. |
| 177 void registerNewLibrary(LibraryElement library); | 184 void registerNewLibrary(LibraryElement library); |
| 178 | 185 |
| 179 /// This method must be called when a new synthesized/patch library has been | 186 /// This method must be called when a new synthesized/patch library has been |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 } | 363 } |
| 357 } | 364 } |
| 358 | 365 |
| 359 List<Future<LibraryElement>> reusedLibrariesFuture = | 366 List<Future<LibraryElement>> reusedLibrariesFuture = |
| 360 // TODO(sigmund): make measurements separate from compiler | 367 // TODO(sigmund): make measurements separate from compiler |
| 361 compiler.reuseLibraryTask.measure( | 368 compiler.reuseLibraryTask.measure( |
| 362 () => libraryCanonicalUriMap.values.map(wrapper).toList()); | 369 () => libraryCanonicalUriMap.values.map(wrapper).toList()); |
| 363 | 370 |
| 364 return Future | 371 return Future |
| 365 .wait(reusedLibrariesFuture) | 372 .wait(reusedLibrariesFuture) |
| 366 .then((List<LibraryElement> reusedLibraries) { | 373 .then((Iterable<LibraryElement> reusedLibraries) { |
| 367 resetImplementation(reusedLibraries.where((e) => e != null)); | 374 resetImplementation(reusedLibraries.where((e) => e != null)); |
| 368 }); | 375 }); |
| 369 }); | 376 }); |
| 370 } | 377 } |
| 371 | 378 |
| 379 Future<Null> resetLibraries( |
| 380 Future<Iterable<LibraryElement>> reuseLibraries( |
| 381 Iterable<LibraryElement> libraries)) { |
| 382 assert(currentHandler == null); |
| 383 return compiler.reuseLibraryTask.measure(() { |
| 384 return new Future<Iterable<LibraryElement>>(() { |
| 385 // Wrap in Future to shield against errors in user code. |
| 386 return reuseLibraries(libraryCanonicalUriMap.values); |
| 387 }).catchError((exception, StackTrace trace) { |
| 388 compiler.reportCrashInUserCode( |
| 389 'Uncaught exception in reuseLibraries', exception, trace); |
| 390 throw exception; // Async rethrow. |
| 391 }).then((Iterable<LibraryElement> reusedLibraries) { |
| 392 measure(() { |
| 393 resetImplementation(reusedLibraries); |
| 394 }); |
| 395 }); |
| 396 }); |
| 397 } |
| 398 |
| 372 /// Insert [library] in the internal maps. Used for compiler reuse. | 399 /// Insert [library] in the internal maps. Used for compiler reuse. |
| 373 void mapLibrary(LibraryElement library) { | 400 void mapLibrary(LibraryElement library) { |
| 374 libraryCanonicalUriMap[library.canonicalUri] = library; | 401 libraryCanonicalUriMap[library.canonicalUri] = library; |
| 375 | 402 |
| 376 Uri resourceUri = library.entryCompilationUnit.script.resourceUri; | 403 Uri resourceUri = library.entryCompilationUnit.script.resourceUri; |
| 377 libraryResourceUriMap[resourceUri] = library; | 404 libraryResourceUriMap[resourceUri] = library; |
| 378 | 405 |
| 379 if (library.hasLibraryName) { | 406 if (library.hasLibraryName) { |
| 380 String name = library.libraryName; | 407 String name = library.libraryName; |
| 381 libraryNames[name] = library; | 408 libraryNames[name] = library; |
| (...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1474 /// Called after a request to load a library. The [results] will include all | 1501 /// Called after a request to load a library. The [results] will include all |
| 1475 /// transitive libraries loaded as a result of the initial request. | 1502 /// transitive libraries loaded as a result of the initial request. |
| 1476 Future onLibrariesLoaded(LoadedLibraries results); | 1503 Future onLibrariesLoaded(LoadedLibraries results); |
| 1477 | 1504 |
| 1478 /// Called whenever a library element is created. | 1505 /// Called whenever a library element is created. |
| 1479 void onLibraryCreated(LibraryElement library); | 1506 void onLibraryCreated(LibraryElement library); |
| 1480 | 1507 |
| 1481 /// Called whenever a library is scanned from a script file. | 1508 /// Called whenever a library is scanned from a script file. |
| 1482 Future onLibraryScanned(LibraryElement library, LibraryLoader loader); | 1509 Future onLibraryScanned(LibraryElement library, LibraryLoader loader); |
| 1483 } | 1510 } |
| OLD | NEW |