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, GenericTask; |
11 import 'common.dart'; | 11 import 'common.dart'; |
12 import 'compiler.dart' show Compiler; | 12 import 'compiler.dart' show Compiler; |
13 import 'elements/elements.dart' | 13 import 'elements/elements.dart' |
14 show | 14 show |
15 CompilationUnitElement, | 15 CompilationUnitElement, |
16 Element, | 16 Element, |
17 ImportElement, | 17 ImportElement, |
18 ExportElement, | 18 ExportElement, |
19 LibraryElement; | 19 LibraryElement; |
20 import 'elements/modelx.dart' | 20 import 'elements/modelx.dart' |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 final LibraryDeserializer deserializer; | 290 final LibraryDeserializer deserializer; |
291 | 291 |
292 /// Hooks to inform others about progress done by this loader. | 292 /// Hooks to inform others about progress done by this loader. |
293 // TODO(sigmund): move away from this. | 293 // TODO(sigmund): move away from this. |
294 final LibraryLoaderListener listener; | 294 final LibraryLoaderListener listener; |
295 | 295 |
296 /// Definitions provided via the `-D` command line flags. Used to resolve | 296 /// Definitions provided via the `-D` command line flags. Used to resolve |
297 /// conditional imports. | 297 /// conditional imports. |
298 final Environment environment; | 298 final Environment environment; |
299 | 299 |
| 300 final Compiler compiler; |
| 301 DiagnosticReporter get reporter => compiler.reporter; |
| 302 |
300 _LibraryLoaderTask(Compiler compiler, this.uriTranslator, this.scriptLoader, | 303 _LibraryLoaderTask(Compiler compiler, this.uriTranslator, this.scriptLoader, |
301 this.scanner, this.deserializer, this.listener, this.environment) | 304 this.scanner, this.deserializer, this.listener, this.environment) |
302 // TODO(sigmund): make measurements separate from compiler | 305 : compiler = compiler, |
303 : super(compiler); | 306 super(compiler.measurer); |
304 | 307 |
305 String get name => 'LibraryLoader'; | 308 String get name => 'LibraryLoader'; |
306 | 309 |
307 final Map<Uri, LibraryElement> libraryCanonicalUriMap = | 310 final Map<Uri, LibraryElement> libraryCanonicalUriMap = |
308 new Map<Uri, LibraryElement>(); | 311 new Map<Uri, LibraryElement>(); |
309 final Map<Uri, LibraryElement> libraryResourceUriMap = | 312 final Map<Uri, LibraryElement> libraryResourceUriMap = |
310 new Map<Uri, LibraryElement>(); | 313 new Map<Uri, LibraryElement>(); |
311 final Map<String, LibraryElement> libraryNames = | 314 final Map<String, LibraryElement> libraryNames = |
312 new Map<String, LibraryElement>(); | 315 new Map<String, LibraryElement>(); |
313 | 316 |
314 LibraryDependencyHandler currentHandler; | 317 LibraryDependencyHandler currentHandler; |
315 | 318 |
316 Iterable<LibraryElement> get libraries => libraryCanonicalUriMap.values; | 319 Iterable<LibraryElement> get libraries => libraryCanonicalUriMap.values; |
317 | 320 |
318 LibraryElement lookupLibrary(Uri canonicalUri) { | 321 LibraryElement lookupLibrary(Uri canonicalUri) { |
319 return libraryCanonicalUriMap[canonicalUri]; | 322 return libraryCanonicalUriMap[canonicalUri]; |
320 } | 323 } |
321 | 324 |
322 void reset({bool reuseLibrary(LibraryElement library)}) { | 325 void reset({bool reuseLibrary(LibraryElement library)}) { |
323 measure(() { | 326 measure(() { |
324 assert(currentHandler == null); | 327 assert(currentHandler == null); |
325 | 328 |
326 Iterable<LibraryElement> reusedLibraries = null; | 329 Iterable<LibraryElement> reusedLibraries = null; |
327 if (reuseLibrary != null) { | 330 if (reuseLibrary != null) { |
328 // TODO(sigmund): make measurements separate from compiler | 331 reusedLibraries = measureSubtask(_reuseLibrarySubtaskName, () { |
329 reusedLibraries = compiler.reuseLibraryTask.measure(() { | |
330 // Call [toList] to force eager calls to [reuseLibrary]. | 332 // Call [toList] to force eager calls to [reuseLibrary]. |
331 return libraryCanonicalUriMap.values.where(reuseLibrary).toList(); | 333 return libraryCanonicalUriMap.values.where(reuseLibrary).toList(); |
332 }); | 334 }); |
333 } | 335 } |
334 | 336 |
335 resetImplementation(reusedLibraries); | 337 resetImplementation(reusedLibraries); |
336 }); | 338 }); |
337 } | 339 } |
338 | 340 |
339 void resetImplementation(Iterable<LibraryElement> reusedLibraries) { | 341 void resetImplementation(Iterable<LibraryElement> reusedLibraries) { |
(...skipping 17 matching lines...) Expand all Loading... |
357 return reuseLibrary(library) | 359 return reuseLibrary(library) |
358 .then((bool reuse) => reuse ? library : null); | 360 .then((bool reuse) => reuse ? library : null); |
359 } catch (exception, trace) { | 361 } catch (exception, trace) { |
360 reporter.onCrashInUserCode( | 362 reporter.onCrashInUserCode( |
361 'Uncaught exception in reuseLibrary', exception, trace); | 363 'Uncaught exception in reuseLibrary', exception, trace); |
362 rethrow; | 364 rethrow; |
363 } | 365 } |
364 } | 366 } |
365 | 367 |
366 List<Future<LibraryElement>> reusedLibrariesFuture = | 368 List<Future<LibraryElement>> reusedLibrariesFuture = |
367 // TODO(sigmund): make measurements separate from compiler | 369 measureSubtask(_reuseLibrarySubtaskName, |
368 compiler.reuseLibraryTask.measure( | |
369 () => libraryCanonicalUriMap.values.map(wrapper).toList()); | 370 () => libraryCanonicalUriMap.values.map(wrapper).toList()); |
370 | 371 |
371 return Future | 372 return Future |
372 .wait(reusedLibrariesFuture) | 373 .wait(reusedLibrariesFuture) |
373 .then((Iterable<LibraryElement> reusedLibraries) { | 374 .then((Iterable<LibraryElement> reusedLibraries) { |
374 resetImplementation(reusedLibraries.where((e) => e != null)); | 375 resetImplementation(reusedLibraries.where((e) => e != null)); |
375 }); | 376 }); |
376 }); | 377 }); |
377 } | 378 } |
378 | 379 |
379 Future<Null> resetLibraries( | 380 Future<Null> resetLibraries( |
380 Future<Iterable<LibraryElement>> reuseLibraries( | 381 Future<Iterable<LibraryElement>> reuseLibraries( |
381 Iterable<LibraryElement> libraries)) { | 382 Iterable<LibraryElement> libraries)) { |
382 assert(currentHandler == null); | 383 assert(currentHandler == null); |
383 return compiler.reuseLibraryTask.measure(() { | 384 return measureSubtask(_reuseLibrarySubtaskName, () { |
384 return new Future<Iterable<LibraryElement>>(() { | 385 return new Future<Iterable<LibraryElement>>(() { |
385 // Wrap in Future to shield against errors in user code. | 386 // Wrap in Future to shield against errors in user code. |
386 return reuseLibraries(libraryCanonicalUriMap.values); | 387 return reuseLibraries(libraryCanonicalUriMap.values); |
387 }).catchError((exception, StackTrace trace) { | 388 }).catchError((exception, StackTrace trace) { |
388 compiler.reportCrashInUserCode( | 389 compiler.reportCrashInUserCode( |
389 'Uncaught exception in reuseLibraries', exception, trace); | 390 'Uncaught exception in reuseLibraries', exception, trace); |
390 throw exception; // Async rethrow. | 391 throw exception; // Async rethrow. |
391 }).then((Iterable<LibraryElement> reusedLibraries) { | 392 }).then((Iterable<LibraryElement> reusedLibraries) { |
392 measure(() { | 393 measure(() { |
393 resetImplementation(reusedLibraries); | 394 resetImplementation(reusedLibraries); |
(...skipping 1107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1501 /// Called after a request to load a library. The [results] will include all | 1502 /// Called after a request to load a library. The [results] will include all |
1502 /// transitive libraries loaded as a result of the initial request. | 1503 /// transitive libraries loaded as a result of the initial request. |
1503 Future onLibrariesLoaded(LoadedLibraries results); | 1504 Future onLibrariesLoaded(LoadedLibraries results); |
1504 | 1505 |
1505 /// Called whenever a library element is created. | 1506 /// Called whenever a library element is created. |
1506 void onLibraryCreated(LibraryElement library); | 1507 void onLibraryCreated(LibraryElement library); |
1507 | 1508 |
1508 /// Called whenever a library is scanned from a script file. | 1509 /// Called whenever a library is scanned from a script file. |
1509 Future onLibraryScanned(LibraryElement library, LibraryLoader loader); | 1510 Future onLibraryScanned(LibraryElement library, LibraryLoader loader); |
1510 } | 1511 } |
| 1512 |
| 1513 const _reuseLibrarySubtaskName = "Reuse library"; |
OLD | NEW |