| 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 import 'dart2jslib.dart' | 8 import 'dart2jslib.dart' |
| 9 show Compiler, | 9 show Compiler, |
| 10 CompilerTask, | 10 CompilerTask, |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 /// [LibraryElement] for the library and computes the import/export scope, | 136 /// [LibraryElement] for the library and computes the import/export scope, |
| 137 /// loading and computing the import/export scopes of all required libraries | 137 /// loading and computing the import/export scopes of all required libraries |
| 138 /// in the process. The method handles cyclic dependency between libraries. | 138 /// in the process. The method handles cyclic dependency between libraries. |
| 139 Future<LibraryElement> loadLibrary(Uri resolvedUri); | 139 Future<LibraryElement> loadLibrary(Uri resolvedUri); |
| 140 | 140 |
| 141 /// Reset the library loader task to prepare for compilation. If provided, | 141 /// Reset the library loader task to prepare for compilation. If provided, |
| 142 /// libraries matching [reuseLibrary] are reused. | 142 /// libraries matching [reuseLibrary] are reused. |
| 143 /// | 143 /// |
| 144 /// This method is used for incremental compilation. | 144 /// This method is used for incremental compilation. |
| 145 void reset({bool reuseLibrary(LibraryElement library)}); | 145 void reset({bool reuseLibrary(LibraryElement library)}); |
| 146 |
| 147 /// Asynchronous version of [reset]. |
| 148 Future resetAsync(Future<bool> reuseLibrary(LibraryElement library)); |
| 146 } | 149 } |
| 147 | 150 |
| 148 /// Handle for creating synthesized/patch libraries during library loading. | 151 /// Handle for creating synthesized/patch libraries during library loading. |
| 149 abstract class LibraryLoader { | 152 abstract class LibraryLoader { |
| 150 /// This method must be called when a new synthesized/patch library has been | 153 /// This method must be called when a new synthesized/patch library has been |
| 151 /// created to ensure that [library] will part of library dependency graph | 154 /// created to ensure that [library] will part of library dependency graph |
| 152 /// used for computing import/export scopes. | 155 /// used for computing import/export scopes. |
| 153 void registerNewLibrary(LibraryElement library); | 156 void registerNewLibrary(LibraryElement library); |
| 154 | 157 |
| 155 /// This method must be called when a new synthesized/patch library has been | 158 /// This method must be called when a new synthesized/patch library has been |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 | 262 |
| 260 Iterable<LibraryElement> get libraries => libraryCanonicalUriMap.values; | 263 Iterable<LibraryElement> get libraries => libraryCanonicalUriMap.values; |
| 261 | 264 |
| 262 LibraryElement lookupLibrary(Uri canonicalUri) { | 265 LibraryElement lookupLibrary(Uri canonicalUri) { |
| 263 return libraryCanonicalUriMap[canonicalUri]; | 266 return libraryCanonicalUriMap[canonicalUri]; |
| 264 } | 267 } |
| 265 | 268 |
| 266 void reset({bool reuseLibrary(LibraryElement library)}) { | 269 void reset({bool reuseLibrary(LibraryElement library)}) { |
| 267 measure(() { | 270 measure(() { |
| 268 assert(currentHandler == null); | 271 assert(currentHandler == null); |
| 269 Iterable<LibraryElement> libraries = | |
| 270 new List.from(libraryCanonicalUriMap.values); | |
| 271 | 272 |
| 273 Iterable<LibraryElement> reusedLibraries = null; |
| 274 if (reuseLibrary != null) { |
| 275 reusedLibraries = compiler.reuseLibraryTask.measure(() { |
| 276 // Call [toList] to force eager calls to [reuseLibrary]. |
| 277 return libraryCanonicalUriMap.values.where(reuseLibrary).toList(); |
| 278 }); |
| 279 } |
| 280 |
| 281 resetImplementation(reusedLibraries); |
| 282 }); |
| 283 } |
| 284 |
| 285 void resetImplementation(Iterable<LibraryElement> reusedLibraries) { |
| 286 measure(() { |
| 272 libraryCanonicalUriMap.clear(); | 287 libraryCanonicalUriMap.clear(); |
| 273 libraryResourceUriMap.clear(); | 288 libraryResourceUriMap.clear(); |
| 274 libraryNames.clear(); | 289 libraryNames.clear(); |
| 275 | 290 |
| 276 if (reuseLibrary == null) return; | 291 if (reusedLibraries != null) { |
| 277 | 292 reusedLibraries.forEach(mapLibrary); |
| 278 compiler.reuseLibraryTask.measure( | 293 } |
| 279 () => libraries.where(reuseLibrary).toList()).forEach(mapLibrary); | |
| 280 }); | 294 }); |
| 281 } | 295 } |
| 282 | 296 |
| 297 Future resetAsync(Future<bool> reuseLibrary(LibraryElement library)) { |
| 298 return measure(() { |
| 299 assert(currentHandler == null); |
| 300 |
| 301 Future<LibraryElement> wrapper(LibraryElement library) { |
| 302 try { |
| 303 return reuseLibrary(library).then( |
| 304 (bool reuse) => reuse ? library : null); |
| 305 } catch (exception, trace) { |
| 306 compiler.diagnoseCrashInUserCode( |
| 307 'Uncaught exception in reuseLibrary', exception, trace); |
| 308 rethrow; |
| 309 } |
| 310 } |
| 311 |
| 312 List<Future<LibraryElement>> reusedLibrariesFuture = |
| 313 compiler.reuseLibraryTask.measure( |
| 314 () => libraryCanonicalUriMap.values.map(wrapper).toList()); |
| 315 |
| 316 return Future.wait(reusedLibrariesFuture).then( |
| 317 (List<LibraryElement> reusedLibraries) { |
| 318 resetImplementation(reusedLibraries.where((e) => e != null)); |
| 319 }); |
| 320 }); |
| 321 } |
| 322 |
| 283 /// Insert [library] in the internal maps. Used for compiler reuse. | 323 /// Insert [library] in the internal maps. Used for compiler reuse. |
| 284 void mapLibrary(LibraryElement library) { | 324 void mapLibrary(LibraryElement library) { |
| 285 libraryCanonicalUriMap[library.canonicalUri] = library; | 325 libraryCanonicalUriMap[library.canonicalUri] = library; |
| 286 | 326 |
| 287 Uri resourceUri = library.entryCompilationUnit.script.resourceUri; | 327 Uri resourceUri = library.entryCompilationUnit.script.resourceUri; |
| 288 libraryResourceUriMap[resourceUri] = library; | 328 libraryResourceUriMap[resourceUri] = library; |
| 289 | 329 |
| 290 String name = library.getLibraryOrScriptName(); | 330 String name = library.getLibraryOrScriptName(); |
| 291 libraryNames[name] = library; | 331 libraryNames[name] = library; |
| 292 } | 332 } |
| (...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 985 * fixed-point computation of the import/export scopes. | 1025 * fixed-point computation of the import/export scopes. |
| 986 */ | 1026 */ |
| 987 void registerLibraryExports(LibraryElement library) { | 1027 void registerLibraryExports(LibraryElement library) { |
| 988 nodeMap[library].registerInitialExports(); | 1028 nodeMap[library].registerInitialExports(); |
| 989 } | 1029 } |
| 990 | 1030 |
| 991 Future processLibraryTags(LibraryElement library) { | 1031 Future processLibraryTags(LibraryElement library) { |
| 992 return task.processLibraryTags(this, library); | 1032 return task.processLibraryTags(this, library); |
| 993 } | 1033 } |
| 994 } | 1034 } |
| OLD | NEW |