| 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.dart'; | 9 import 'common.dart'; |
| 10 import 'common/names.dart' show | 10 import 'common/names.dart' show |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 LibraryDependencyElementX, | 30 LibraryDependencyElementX, |
| 31 PrefixElementX, | 31 PrefixElementX, |
| 32 SyntheticImportElement; | 32 SyntheticImportElement; |
| 33 | 33 |
| 34 import 'script.dart'; | 34 import 'script.dart'; |
| 35 import 'tree/tree.dart'; | 35 import 'tree/tree.dart'; |
| 36 import 'util/util.dart' show | 36 import 'util/util.dart' show |
| 37 Link, | 37 Link, |
| 38 LinkBuilder; | 38 LinkBuilder; |
| 39 | 39 |
| 40 typedef Future<Iterable<LibraryElement>> ReuseLibrariesFunction( |
| 41 Iterable<LibraryElement> libraries); |
| 42 |
| 40 /** | 43 /** |
| 41 * [CompilerTask] for loading libraries and setting up the import/export scopes. | 44 * [CompilerTask] for loading libraries and setting up the import/export scopes. |
| 42 * | 45 * |
| 43 * The library loader uses four different kinds of URIs in different parts of | 46 * The library loader uses four different kinds of URIs in different parts of |
| 44 * the loading process. | 47 * the loading process. |
| 45 * | 48 * |
| 46 * ## User URI ## | 49 * ## User URI ## |
| 47 * | 50 * |
| 48 * A 'user URI' is a URI provided by the user in code and as the main entry URI | 51 * A 'user URI' is a URI provided by the user in code and as the main entry URI |
| 49 * at the command line. These generally come in 3 versions: | 52 * at the command line. These generally come in 3 versions: |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 Future<LibraryElement> loadLibrary(Uri resolvedUri); | 153 Future<LibraryElement> loadLibrary(Uri resolvedUri); |
| 151 | 154 |
| 152 /// Reset the library loader task to prepare for compilation. If provided, | 155 /// Reset the library loader task to prepare for compilation. If provided, |
| 153 /// libraries matching [reuseLibrary] are reused. | 156 /// libraries matching [reuseLibrary] are reused. |
| 154 /// | 157 /// |
| 155 /// This method is used for incremental compilation. | 158 /// This method is used for incremental compilation. |
| 156 void reset({bool reuseLibrary(LibraryElement library)}); | 159 void reset({bool reuseLibrary(LibraryElement library)}); |
| 157 | 160 |
| 158 /// Asynchronous version of [reset]. | 161 /// Asynchronous version of [reset]. |
| 159 Future resetAsync(Future<bool> reuseLibrary(LibraryElement library)); | 162 Future resetAsync(Future<bool> reuseLibrary(LibraryElement library)); |
| 163 |
| 164 /// Similar to [resetAsync] but [reuseLibrary] maps all libraries to a list |
| 165 /// of libraries that can be reused. |
| 166 Future<Null> resetLibraries(ReuseLibrariesFunction reuseLibraries); |
| 160 } | 167 } |
| 161 | 168 |
| 162 /// Handle for creating synthesized/patch libraries during library loading. | 169 /// Handle for creating synthesized/patch libraries during library loading. |
| 163 abstract class LibraryLoader { | 170 abstract class LibraryLoader { |
| 164 /// This method must be called when a new synthesized/patch library has been | 171 /// This method must be called when a new synthesized/patch library has been |
| 165 /// created to ensure that [library] will part of library dependency graph | 172 /// created to ensure that [library] will part of library dependency graph |
| 166 /// used for computing import/export scopes. | 173 /// used for computing import/export scopes. |
| 167 void registerNewLibrary(LibraryElement library); | 174 void registerNewLibrary(LibraryElement library); |
| 168 | 175 |
| 169 /// This method must be called when a new synthesized/patch library has been | 176 /// This method must be called when a new synthesized/patch library has been |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 'Uncaught exception in reuseLibrary', exception, trace); | 326 'Uncaught exception in reuseLibrary', exception, trace); |
| 320 rethrow; | 327 rethrow; |
| 321 } | 328 } |
| 322 } | 329 } |
| 323 | 330 |
| 324 List<Future<LibraryElement>> reusedLibrariesFuture = | 331 List<Future<LibraryElement>> reusedLibrariesFuture = |
| 325 compiler.reuseLibraryTask.measure( | 332 compiler.reuseLibraryTask.measure( |
| 326 () => libraryCanonicalUriMap.values.map(wrapper).toList()); | 333 () => libraryCanonicalUriMap.values.map(wrapper).toList()); |
| 327 | 334 |
| 328 return Future.wait(reusedLibrariesFuture).then( | 335 return Future.wait(reusedLibrariesFuture).then( |
| 329 (List<LibraryElement> reusedLibraries) { | 336 (Iterable<LibraryElement> reusedLibraries) { |
| 330 resetImplementation(reusedLibraries.where((e) => e != null)); | 337 resetImplementation(reusedLibraries.where((e) => e != null)); |
| 331 }); | 338 }); |
| 332 }); | 339 }); |
| 333 } | 340 } |
| 334 | 341 |
| 342 Future<Null> resetLibraries( |
| 343 Future<Iterable<LibraryElement>> reuseLibraries( |
| 344 Iterable<LibraryElement> libraries)) { |
| 345 assert(currentHandler == null); |
| 346 return compiler.reuseLibraryTask.measure(() { |
| 347 return new Future<Iterable<LibraryElement>>(() { |
| 348 // Wrap in Future to shield against errors in user code. |
| 349 return reuseLibraries(libraryCanonicalUriMap.values); |
| 350 }).catchError((exception, StackTrace trace) { |
| 351 compiler.diagnoseCrashInUserCode( |
| 352 'Uncaught exception in reuseLibraries', exception, trace); |
| 353 throw exception; // Async rethrow. |
| 354 }).then((Iterable<LibraryElement> reusedLibraries) { |
| 355 measure(() { |
| 356 resetImplementation(reusedLibraries); |
| 357 }); |
| 358 }); |
| 359 }); |
| 360 } |
| 361 |
| 335 /// Insert [library] in the internal maps. Used for compiler reuse. | 362 /// Insert [library] in the internal maps. Used for compiler reuse. |
| 336 void mapLibrary(LibraryElement library) { | 363 void mapLibrary(LibraryElement library) { |
| 337 libraryCanonicalUriMap[library.canonicalUri] = library; | 364 libraryCanonicalUriMap[library.canonicalUri] = library; |
| 338 | 365 |
| 339 Uri resourceUri = library.entryCompilationUnit.script.resourceUri; | 366 Uri resourceUri = library.entryCompilationUnit.script.resourceUri; |
| 340 libraryResourceUriMap[resourceUri] = library; | 367 libraryResourceUriMap[resourceUri] = library; |
| 341 | 368 |
| 342 String name = library.libraryOrScriptName; | 369 String name = library.libraryOrScriptName; |
| 343 libraryNames[name] = library; | 370 libraryNames[name] = library; |
| 344 } | 371 } |
| (...skipping 998 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1343 } | 1370 } |
| 1344 suffixes.add(const Link<Uri>().prepend(canonicalUri)); | 1371 suffixes.add(const Link<Uri>().prepend(canonicalUri)); |
| 1345 } | 1372 } |
| 1346 suffixChainMap[library] = suffixes; | 1373 suffixChainMap[library] = suffixes; |
| 1347 return; | 1374 return; |
| 1348 } | 1375 } |
| 1349 | 1376 |
| 1350 computeSuffixes(rootLibrary, const Link<Uri>()); | 1377 computeSuffixes(rootLibrary, const Link<Uri>()); |
| 1351 } | 1378 } |
| 1352 } | 1379 } |
| OLD | NEW |