Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: pkg/compiler/lib/src/compiler.dart

Issue 2760923004: Eliminate multi-callback structure for LibraryLoader. (Closed)
Patch Set: . Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.compiler_base; 5 library dart2js.compiler_base;
6 6
7 import 'dart:async' show EventSink, Future; 7 import 'dart:async' show EventSink, Future;
8 8
9 import '../compiler_new.dart' as api; 9 import '../compiler_new.dart' as api;
10 import 'io/source_file.dart' show SourceFile;
Siggi Cherem (dart-lang) 2017/03/24 17:40:27 nit: move this further down to keep the alphabetic
Emily Fortuna 2017/03/24 18:30:19 removed
10 import 'closure.dart' as closureMapping show ClosureTask; 11 import 'closure.dart' as closureMapping show ClosureTask;
11 import 'common/names.dart' show Selectors; 12 import 'common/names.dart' show Selectors;
12 import 'common/names.dart' show Identifiers, Uris; 13 import 'common/names.dart' show Identifiers, Uris;
13 import 'common/resolution.dart' 14 import 'common/resolution.dart'
14 show 15 show
15 ParsingContext, 16 ParsingContext,
16 Resolution, 17 Resolution,
17 ResolutionWorkItem, 18 ResolutionWorkItem,
18 ResolutionImpact, 19 ResolutionImpact,
19 Target; 20 Target;
(...skipping 24 matching lines...) Expand all
44 import 'environment.dart'; 45 import 'environment.dart';
45 import 'id_generator.dart'; 46 import 'id_generator.dart';
46 import 'io/source_information.dart' show SourceInformation; 47 import 'io/source_information.dart' show SourceInformation;
47 import 'js_backend/backend.dart' show JavaScriptBackend; 48 import 'js_backend/backend.dart' show JavaScriptBackend;
48 import 'library_loader.dart' 49 import 'library_loader.dart'
49 show 50 show
50 ElementScanner, 51 ElementScanner,
51 LibraryLoader, 52 LibraryLoader,
52 LibraryLoaderTask, 53 LibraryLoaderTask,
53 LoadedLibraries, 54 LoadedLibraries,
54 LibraryLoaderListener,
55 LibraryProvider, 55 LibraryProvider,
56 ScriptLoader; 56 ScriptLoader;
57 import 'mirrors_used.dart' show MirrorUsageAnalyzerTask; 57 import 'mirrors_used.dart' show MirrorUsageAnalyzerTask;
58 import 'null_compiler_output.dart' show NullCompilerOutput, NullSink; 58 import 'null_compiler_output.dart' show NullCompilerOutput, NullSink;
59 import 'options.dart' show CompilerOptions, DiagnosticOptions; 59 import 'options.dart' show CompilerOptions, DiagnosticOptions;
60 import 'parser/diet_parser_task.dart' show DietParserTask; 60 import 'parser/diet_parser_task.dart' show DietParserTask;
61 import 'parser/parser_task.dart' show ParserTask; 61 import 'parser/parser_task.dart' show ParserTask;
62 import 'patch_parser.dart' show PatchParserTask; 62 import 'patch_parser.dart' show PatchParserTask;
63 import 'resolution/resolution.dart' show ResolverTask; 63 import 'resolution/resolution.dart' show ResolverTask;
64 import 'resolved_uri_translator.dart'; 64 import 'resolved_uri_translator.dart';
(...skipping 12 matching lines...) Expand all
77 show ResolutionWorldBuilder, CodegenWorldBuilder; 77 show ResolutionWorldBuilder, CodegenWorldBuilder;
78 import 'universe/use.dart' show StaticUse, TypeUse; 78 import 'universe/use.dart' show StaticUse, TypeUse;
79 import 'universe/world_impact.dart' 79 import 'universe/world_impact.dart'
80 show ImpactStrategy, WorldImpact, WorldImpactBuilderImpl; 80 show ImpactStrategy, WorldImpact, WorldImpactBuilderImpl;
81 import 'util/util.dart' show Link; 81 import 'util/util.dart' show Link;
82 import 'world.dart' show ClosedWorld, ClosedWorldRefiner, ClosedWorldImpl; 82 import 'world.dart' show ClosedWorld, ClosedWorldRefiner, ClosedWorldImpl;
83 83
84 typedef CompilerDiagnosticReporter MakeReporterFunction( 84 typedef CompilerDiagnosticReporter MakeReporterFunction(
85 Compiler compiler, CompilerOptions options); 85 Compiler compiler, CompilerOptions options);
86 86
87 abstract class Compiler implements LibraryLoaderListener { 87 abstract class Compiler {
88 Measurer get measurer; 88 Measurer get measurer;
89 89
90 final IdGenerator idGenerator = new IdGenerator(); 90 final IdGenerator idGenerator = new IdGenerator();
91 Types types; 91 Types types;
92 _CompilerCommonElements _commonElements; 92 _CompilerCommonElements _commonElements;
93 _CompilerElementEnvironment _elementEnvironment; 93 _CompilerElementEnvironment _elementEnvironment;
94 CompilerDiagnosticReporter _reporter; 94 CompilerDiagnosticReporter _reporter;
95 CompilerResolution _resolution; 95 CompilerResolution _resolution;
96 ParsingContext _parsingContext; 96 ParsingContext _parsingContext;
97 97
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 progress = new Stopwatch()..start(); 206 progress = new Stopwatch()..start();
207 } 207 }
208 208
209 backend = createBackend(); 209 backend = createBackend();
210 enqueuer = backend.makeEnqueuer(); 210 enqueuer = backend.makeEnqueuer();
211 211
212 tasks = [ 212 tasks = [
213 dietParser = new DietParserTask(idGenerator, backend, reporter, measurer), 213 dietParser = new DietParserTask(idGenerator, backend, reporter, measurer),
214 scanner = createScannerTask(), 214 scanner = createScannerTask(),
215 serialization = new SerializationTask(this), 215 serialization = new SerializationTask(this),
216 patchParser = new PatchParserTask(this),
216 libraryLoader = new LibraryLoaderTask( 217 libraryLoader = new LibraryLoaderTask(
217 resolvedUriTranslator, 218 resolvedUriTranslator,
218 options.compileOnly 219 options.compileOnly
219 ? new _NoScriptLoader(this) 220 ? new _NoScriptLoader(this)
220 : new _ScriptLoader(this), 221 : new _ScriptLoader(this),
221 new _ElementScanner(scanner), 222 new _ElementScanner(scanner),
222 serialization, 223 serialization,
223 this, 224 resolvePatchUri,
225 patchParser,
224 environment, 226 environment,
225 reporter, 227 reporter,
226 measurer), 228 measurer),
227 parser = new ParserTask(this), 229 parser = new ParserTask(this),
228 patchParser = new PatchParserTask(this),
229 resolver = createResolverTask(), 230 resolver = createResolverTask(),
230 closureToClassMapper = new closureMapping.ClosureTask(this), 231 closureToClassMapper = new closureMapping.ClosureTask(this),
231 checker = new TypeCheckerTask(this), 232 checker = new TypeCheckerTask(this),
232 globalInference = new GlobalTypeInferenceTask(this), 233 globalInference = new GlobalTypeInferenceTask(this),
233 constants = backend.constantCompilerTask, 234 constants = backend.constantCompilerTask,
234 deferredLoadTask = new DeferredLoadTask(this), 235 deferredLoadTask = new DeferredLoadTask(this),
235 mirrorUsageAnalyzerTask = new MirrorUsageAnalyzerTask(this), 236 mirrorUsageAnalyzerTask = new MirrorUsageAnalyzerTask(this),
236 // [enqueuer] is created earlier because it contains the resolution world 237 // [enqueuer] is created earlier because it contains the resolution world
237 // objects needed by other tasks. 238 // objects needed by other tasks.
238 enqueuer, 239 enqueuer,
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 311
311 return new Future.sync(() => runInternal(uri)) 312 return new Future.sync(() => runInternal(uri))
312 .catchError((error) => _reporter.onError(uri, error)) 313 .catchError((error) => _reporter.onError(uri, error))
313 .whenComplete(() { 314 .whenComplete(() {
314 measurer.stopWallClock(); 315 measurer.stopWallClock();
315 }).then((_) { 316 }).then((_) {
316 return !compilationFailed; 317 return !compilationFailed;
317 }); 318 });
318 }); 319 });
319 320
320 /// This method is called immediately after the [LibraryElement] [library] has
321 /// been created.
322 ///
323 /// Use this callback method to store references to specific libraries.
324 /// Note that [library] has not been scanned yet, nor has its imports/exports
325 /// been resolved.
326 void onLibraryCreated(LibraryElement library) {
327 _commonElements.onLibraryCreated(library);
328 }
329
330 /// This method is called immediately after the [library] and its parts have
331 /// been scanned.
332 ///
333 /// Use this callback method to store references to specific member declared
334 /// in certain libraries. Note that [library] has not been patched yet, nor
335 /// has its imports/exports been resolved.
336 ///
337 /// Use [loader] to register the creation and scanning of a patch library
338 /// for [library].
339 Future onLibraryScanned(LibraryElement library, LibraryLoader loader) {
340 return backend.onLibraryScanned(library, loader);
341 }
342
343 /// Compute the set of distinct import chains to the library at [uri] within 321 /// Compute the set of distinct import chains to the library at [uri] within
344 /// [loadedLibraries]. 322 /// [loadedLibraries].
345 /// 323 ///
346 /// The chains are strings of the form 324 /// The chains are strings of the form
347 /// 325 ///
348 /// <main-uri> => <intermediate-uri1> => <intermediate-uri2> => <uri> 326 /// <main-uri> => <intermediate-uri1> => <intermediate-uri2> => <uri>
349 /// 327 ///
350 Set<String> computeImportChainsFor(LoadedLibraries loadedLibraries, Uri uri) { 328 Set<String> computeImportChainsFor(LoadedLibraries loadedLibraries, Uri uri) {
351 // TODO(johnniwinther): Move computation of dependencies to the library 329 // TODO(johnniwinther): Move computation of dependencies to the library
352 // loader. 330 // loader.
353 Uri rootUri = loadedLibraries.rootUri;
354 Set<String> importChains = new Set<String>(); 331 Set<String> importChains = new Set<String>();
355 // The maximum number of full imports chains to process. 332 // The maximum number of full imports chains to process.
356 final int chainLimit = 10000; 333 final int chainLimit = 10000;
357 // The maximum number of imports chains to show. 334 // The maximum number of imports chains to show.
358 final int compactChainLimit = options.verbose ? 20 : 10; 335 final int compactChainLimit = options.verbose ? 20 : 10;
359 int chainCount = 0; 336 int chainCount = 0;
360 loadedLibraries.forEachImportChain(uri, 337 loadedLibraries.forEachImportChain(uri,
361 callback: (Link<Uri> importChainReversed) { 338 callback: (Link<Uri> importChainReversed) {
362 Link<CodeLocation> compactImportChain = const Link<CodeLocation>(); 339 Link<CodeLocation> compactImportChain = const Link<CodeLocation>();
363 CodeLocation currentCodeLocation = 340 CodeLocation currentCodeLocation =
364 new UriLocation(importChainReversed.head); 341 new UriLocation(importChainReversed.head);
365 compactImportChain = compactImportChain.prepend(currentCodeLocation); 342 compactImportChain = compactImportChain.prepend(currentCodeLocation);
366 for (Link<Uri> link = importChainReversed.tail; 343 for (Link<Uri> link = importChainReversed.tail;
367 !link.isEmpty; 344 !link.isEmpty;
368 link = link.tail) { 345 link = link.tail) {
369 Uri uri = link.head; 346 Uri uri = link.head;
370 if (!currentCodeLocation.inSameLocation(uri)) { 347 if (!currentCodeLocation.inSameLocation(uri)) {
371 currentCodeLocation = 348 currentCodeLocation =
372 options.verbose ? new UriLocation(uri) : new CodeLocation(uri); 349 options.verbose ? new UriLocation(uri) : new CodeLocation(uri);
373 compactImportChain = compactImportChain.prepend(currentCodeLocation); 350 compactImportChain = compactImportChain.prepend(currentCodeLocation);
374 } 351 }
375 } 352 }
376 String importChain = compactImportChain.map((CodeLocation codeLocation) { 353 String importChain = compactImportChain.map((CodeLocation codeLocation) {
377 return codeLocation.relativize(rootUri); 354 return codeLocation
355 .relativize(loadedLibraries.rootLibrary.canonicalUri);
378 }).join(' => '); 356 }).join(' => ');
379 357
380 if (!importChains.contains(importChain)) { 358 if (!importChains.contains(importChain)) {
381 if (importChains.length > compactChainLimit) { 359 if (importChains.length > compactChainLimit) {
382 importChains.add('...'); 360 importChains.add('...');
383 return false; 361 return false;
384 } else { 362 } else {
385 importChains.add(importChain); 363 importChains.add(importChain);
386 } 364 }
387 } 365 }
(...skipping 10 matching lines...) Expand all
398 } 376 }
399 377
400 /// This method is called when all new libraries loaded through 378 /// This method is called when all new libraries loaded through
401 /// [LibraryLoader.loadLibrary] has been loaded and their imports/exports 379 /// [LibraryLoader.loadLibrary] has been loaded and their imports/exports
402 /// have been computed. 380 /// have been computed.
403 /// 381 ///
404 /// [loadedLibraries] contains the newly loaded libraries. 382 /// [loadedLibraries] contains the newly loaded libraries.
405 /// 383 ///
406 /// The method returns a [Future] allowing for the loading of additional 384 /// The method returns a [Future] allowing for the loading of additional
407 /// libraries. 385 /// libraries.
408 Future onLibrariesLoaded(LoadedLibraries loadedLibraries) { 386 LoadedLibraries processLoadedLibraries(LoadedLibraries loadedLibraries) {
409 return new Future.sync(() { 387 loadedLibraries.forEachLibrary((LibraryElement library) {
410 for (Uri uri in resolvedUriTranslator.disallowedLibraryUris) { 388 _commonElements.registerCommonLibraries(library);
411 if (loadedLibraries.containsLibrary(uri)) { 389 backend.setAnnotations(library);
412 Set<String> importChains = 390 });
413 computeImportChainsFor(loadedLibraries, uri); 391
414 reporter.reportInfo( 392 for (Uri uri in resolvedUriTranslator.disallowedLibraryUris) {
415 NO_LOCATION_SPANNABLE, MessageKind.DISALLOWED_LIBRARY_IMPORT, { 393 if (loadedLibraries.containsLibrary(uri)) {
416 'uri': uri, 394 Set<String> importChains = computeImportChainsFor(loadedLibraries, uri);
417 'importChain': importChains 395 reporter.reportInfo(
418 .join(MessageTemplate.DISALLOWED_LIBRARY_IMPORT_PADDING) 396 NO_LOCATION_SPANNABLE, MessageKind.DISALLOWED_LIBRARY_IMPORT, {
419 }); 397 'uri': uri,
420 } 398 'importChain': importChains
399 .join(MessageTemplate.DISALLOWED_LIBRARY_IMPORT_PADDING)
400 });
421 } 401 }
402 }
422 403
423 if (!loadedLibraries.containsLibrary(Uris.dart_core)) { 404 if (loadedLibraries.containsLibrary(Uris.dart_core)) {
424 return null;
425 }
426
427 bool importsMirrorsLibrary = 405 bool importsMirrorsLibrary =
428 loadedLibraries.containsLibrary(Uris.dart_mirrors); 406 loadedLibraries.containsLibrary(Uris.dart_mirrors);
429 if (importsMirrorsLibrary && !backend.supportsReflection) { 407 if (importsMirrorsLibrary && !backend.supportsReflection) {
430 Set<String> importChains = 408 Set<String> importChains =
431 computeImportChainsFor(loadedLibraries, Uris.dart_mirrors); 409 computeImportChainsFor(loadedLibraries, Uris.dart_mirrors);
432 reporter.reportErrorMessage(NO_LOCATION_SPANNABLE, 410 reporter.reportErrorMessage(NO_LOCATION_SPANNABLE,
433 MessageKind.MIRRORS_LIBRARY_NOT_SUPPORT_BY_BACKEND, { 411 MessageKind.MIRRORS_LIBRARY_NOT_SUPPORT_BY_BACKEND, {
434 'importChain': importChains 412 'importChain': importChains
435 .join(MessageTemplate.MIRRORS_NOT_SUPPORTED_BY_BACKEND_PADDING) 413 .join(MessageTemplate.MIRRORS_NOT_SUPPORTED_BY_BACKEND_PADDING)
436 }); 414 });
437 } else if (importsMirrorsLibrary && !options.enableExperimentalMirrors) { 415 } else if (importsMirrorsLibrary && !options.enableExperimentalMirrors) {
438 Set<String> importChains = 416 Set<String> importChains =
439 computeImportChainsFor(loadedLibraries, Uris.dart_mirrors); 417 computeImportChainsFor(loadedLibraries, Uris.dart_mirrors);
440 reporter.reportWarningMessage( 418 reporter.reportWarningMessage(
441 NO_LOCATION_SPANNABLE, MessageKind.IMPORT_EXPERIMENTAL_MIRRORS, { 419 NO_LOCATION_SPANNABLE, MessageKind.IMPORT_EXPERIMENTAL_MIRRORS, {
442 'importChain': importChains 420 'importChain': importChains
443 .join(MessageTemplate.IMPORT_EXPERIMENTAL_MIRRORS_PADDING) 421 .join(MessageTemplate.IMPORT_EXPERIMENTAL_MIRRORS_PADDING)
444 }); 422 });
445 } 423 }
446 }).then((_) => backend.onLibrariesLoaded(loadedLibraries)); 424 }
425 backend.onLibrariesLoaded(loadedLibraries);
426 return loadedLibraries;
447 } 427 }
448 428
449 // TODO(johnniwinther): Move this to [PatchParser] when it is moved to the 429 // TODO(johnniwinther): Move this to [PatchParser] when it is moved to the
450 // [JavaScriptBackend]. Currently needed for testing. 430 // [JavaScriptBackend]. Currently needed for testing.
451 String get patchVersion => backend.patchVersion; 431 String get patchVersion => backend.patchVersion;
452 432
453 /** 433 /**
454 * Get an [Uri] pointing to a patch for the dart: library with 434 * Get an [Uri] pointing to a patch for the dart: library with
455 * the given path. Returns null if there is no patch. 435 * the given path. Returns null if there is no patch.
456 */ 436 */
457 Uri resolvePatchUri(String dartLibraryPath); 437 Uri resolvePatchUri(String dartLibraryPath);
458 438
459 Future runInternal(Uri uri) { 439 Future runInternal(Uri uri) async {
460 // TODO(ahe): This prevents memory leaks when invoking the compiler 440 // TODO(ahe): This prevents memory leaks when invoking the compiler
461 // multiple times. Implement a better mechanism where we can store 441 // multiple times. Implement a better mechanism where we can store
462 // such caches in the compiler and get access to them through a 442 // such caches in the compiler and get access to them through a
463 // suitably maintained static reference to the current compiler. 443 // suitably maintained static reference to the current compiler.
464 StringToken.canonicalizer.clear(); 444 StringToken.canonicalizer.clear();
465 Selector.canonicalizedValues.clear(); 445 Selector.canonicalizedValues.clear();
466 446
467 // The selector objects held in static fields must remain canonical. 447 // The selector objects held in static fields must remain canonical.
468 for (Selector selector in Selectors.ALL) { 448 for (Selector selector in Selectors.ALL) {
469 Selector.canonicalizedValues 449 Selector.canonicalizedValues
470 .putIfAbsent(selector.hashCode, () => <Selector>[]) 450 .putIfAbsent(selector.hashCode, () => <Selector>[])
471 .add(selector); 451 .add(selector);
472 } 452 }
473 453
474 assert(uri != null || options.analyzeOnly); 454 assert(uri != null || options.analyzeOnly);
475 return new Future.sync(() { 455 // As far as I can tell, this branch is only used by test code.
476 if (librariesToAnalyzeWhenRun != null) { 456 if (librariesToAnalyzeWhenRun != null) {
477 return Future.forEach(librariesToAnalyzeWhenRun, (libraryUri) { 457 await Future.forEach(librariesToAnalyzeWhenRun, (libraryUri) async {
478 reporter.log('Analyzing $libraryUri (${options.buildId})'); 458 reporter.log('Analyzing $libraryUri (${options.buildId})');
479 return libraryLoader.loadLibrary(libraryUri); 459 LoadedLibraries loadedLibraries =
480 }); 460 await libraryLoader.loadLibrary(libraryUri);
461 processLoadedLibraries(loadedLibraries);
462 });
463 }
464 if (uri != null) {
465 if (options.analyzeOnly) {
466 reporter.log('Analyzing $uri (${options.buildId})');
467 } else {
468 reporter.log('Compiling $uri (${options.buildId})');
481 } 469 }
482 }).then((_) { 470 LoadedLibraries libraries = await libraryLoader.loadLibrary(uri);
483 if (uri != null) { 471 processLoadedLibraries(libraries);
484 if (options.analyzeOnly) { 472 mainApp = libraries.rootLibrary;
485 reporter.log('Analyzing $uri (${options.buildId})'); 473 }
486 } else { 474 compileLoadedLibraries();
487 reporter.log('Compiling $uri (${options.buildId})');
488 }
489 return libraryLoader.loadLibrary(uri).then((LibraryElement library) {
490 mainApp = library;
491 });
492 }
493 }).then((_) {
494 compileLoadedLibraries();
495 });
496 } 475 }
497 476
498 WorldImpact computeMain() { 477 WorldImpact computeMain() {
499 if (mainApp == null) return const WorldImpact(); 478 if (mainApp == null) return const WorldImpact();
500 479
501 WorldImpactBuilderImpl impactBuilder = new WorldImpactBuilderImpl(); 480 WorldImpactBuilderImpl impactBuilder = new WorldImpactBuilderImpl();
502 Element main = mainApp.findExported(Identifiers.main); 481 Element main = mainApp.findExported(Identifiers.main);
503 ErroneousElement errorElement = null; 482 ErroneousElement errorElement = null;
504 if (main == null) { 483 if (main == null) {
505 if (options.analyzeOnly) { 484 if (options.analyzeOnly) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 } 541 }
563 542
564 /// Analyze all members of the library in [libraryUri]. 543 /// Analyze all members of the library in [libraryUri].
565 /// 544 ///
566 /// If [skipLibraryWithPartOfTag] is `true`, member analysis is skipped if the 545 /// If [skipLibraryWithPartOfTag] is `true`, member analysis is skipped if the
567 /// library has a `part of` tag, assuming it is a part and not a library. 546 /// library has a `part of` tag, assuming it is a part and not a library.
568 /// 547 ///
569 /// This operation assumes an unclosed resolution queue and is only supported 548 /// This operation assumes an unclosed resolution queue and is only supported
570 /// when the '--analyze-main' option is used. 549 /// when the '--analyze-main' option is used.
571 Future<LibraryElement> analyzeUri(Uri libraryUri, 550 Future<LibraryElement> analyzeUri(Uri libraryUri,
572 {bool skipLibraryWithPartOfTag: true}) { 551 {bool skipLibraryWithPartOfTag: true}) async {
573 assert(options.analyzeMain); 552 assert(options.analyzeMain);
574 reporter.log('Analyzing $libraryUri (${options.buildId})'); 553 reporter.log('Analyzing $libraryUri (${options.buildId})');
575 return libraryLoader 554 LoadedLibraries loadedLibraries = await libraryLoader
576 .loadLibrary(libraryUri, skipFileWithPartOfTag: true) 555 .loadLibrary(libraryUri, skipFileWithPartOfTag: true);
577 .then((LibraryElement library) { 556 if (loadedLibraries != null) {
Siggi Cherem (dart-lang) 2017/03/24 17:40:27 minor nit - we tend to prefer the fast-exit patter
Emily Fortuna 2017/03/24 18:30:19 Done.
578 if (library == null) return null; 557 processLoadedLibraries(loadedLibraries);
558 LibraryElement library = loadedLibraries.rootLibrary;
Siggi Cherem (dart-lang) 2017/03/24 17:40:27 is it safe to say that the root library is not nul
Emily Fortuna 2017/03/24 18:30:19 As the code is currently written if you receive a
579 ResolutionEnqueuer resolutionEnqueuer = startResolution(); 559 ResolutionEnqueuer resolutionEnqueuer = startResolution();
580 resolutionEnqueuer.applyImpact(computeImpactForLibrary(library)); 560 resolutionEnqueuer.applyImpact(computeImpactForLibrary(library));
581 emptyQueue(resolutionEnqueuer, onProgress: showResolutionProgress); 561 emptyQueue(resolutionEnqueuer, onProgress: showResolutionProgress);
582 resolutionEnqueuer.logSummary(reporter.log); 562 resolutionEnqueuer.logSummary(reporter.log);
583 return library; 563 return library;
584 }); 564 }
565 return null;
585 } 566 }
586 567
587 /// Starts the resolution phase, creating the [ResolutionEnqueuer] if not 568 /// Starts the resolution phase, creating the [ResolutionEnqueuer] if not
588 /// already created. 569 /// already created.
589 /// 570 ///
590 /// During normal compilation resolution only started once, but through 571 /// During normal compilation resolution only started once, but through
591 /// [analyzeUri] resolution is started repeatedly. 572 /// [analyzeUri] resolution is started repeatedly.
592 ResolutionEnqueuer startResolution() { 573 ResolutionEnqueuer startResolution() {
593 ResolutionEnqueuer resolutionEnqueuer; 574 ResolutionEnqueuer resolutionEnqueuer;
594 if (enqueuer.hasResolution) { 575 if (enqueuer.hasResolution) {
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
1119 LibraryElement coreLibrary; 1100 LibraryElement coreLibrary;
1120 LibraryElement asyncLibrary; 1101 LibraryElement asyncLibrary;
1121 LibraryElement mirrorsLibrary; 1102 LibraryElement mirrorsLibrary;
1122 LibraryElement typedDataLibrary; 1103 LibraryElement typedDataLibrary;
1123 1104
1124 _CompilerCommonElements(this.environment, this.resolution, this.reporter); 1105 _CompilerCommonElements(this.environment, this.resolution, this.reporter);
1125 1106
1126 @override 1107 @override
1127 ResolutionDynamicType get dynamicType => const ResolutionDynamicType(); 1108 ResolutionDynamicType get dynamicType => const ResolutionDynamicType();
1128 1109
1129 void onLibraryCreated(LibraryElement library) { 1110 void registerCommonLibraries(LibraryElement library) {
1130 Uri uri = library.canonicalUri; 1111 Uri uri = library.canonicalUri;
1131 if (uri == Uris.dart_core) { 1112 if (uri == Uris.dart_core) {
1132 coreLibrary = library; 1113 coreLibrary = library;
1133 } else if (uri == Uris.dart_async) { 1114 } else if (uri == Uris.dart_async) {
1134 asyncLibrary = library; 1115 asyncLibrary = library;
1135 } else if (uri == Uris.dart__native_typed_data) { 1116 } else if (uri == Uris.dart__native_typed_data) {
1136 typedDataLibrary = library; 1117 typedDataLibrary = library;
1137 } else if (uri == Uris.dart_mirrors) { 1118 } else if (uri == Uris.dart_mirrors) {
1138 mirrorsLibrary = library; 1119 mirrorsLibrary = library;
1139 } 1120 }
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after
1925 compiler.reporter 1906 compiler.reporter
1926 .internalError(spannable, "Script loading of '$uri' is not enabled."); 1907 .internalError(spannable, "Script loading of '$uri' is not enabled.");
1927 } 1908 }
1928 } 1909 }
1929 1910
1930 class _ElementScanner implements ElementScanner { 1911 class _ElementScanner implements ElementScanner {
1931 ScannerTask scanner; 1912 ScannerTask scanner;
1932 _ElementScanner(this.scanner); 1913 _ElementScanner(this.scanner);
1933 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); 1914 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library);
1934 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); 1915 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit);
1916 Token scanFile(SourceFile file) => scanner.scanFile(file);
1935 } 1917 }
1936 1918
1937 class _EmptyEnvironment implements Environment { 1919 class _EmptyEnvironment implements Environment {
1938 const _EmptyEnvironment(); 1920 const _EmptyEnvironment();
1939 1921
1940 String valueOf(String key) => null; 1922 String valueOf(String key) => null;
1941 } 1923 }
1942 1924
1943 /// An element environment base on a [Compiler]. 1925 /// An element environment base on a [Compiler].
1944 class _CompilerElementEnvironment implements ElementEnvironment { 1926 class _CompilerElementEnvironment implements ElementEnvironment {
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
2062 if (library != null && library.isSynthesized) { 2044 if (library != null && library.isSynthesized) {
2063 return null; 2045 return null;
2064 } 2046 }
2065 if (library == null && required) { 2047 if (library == null && required) {
2066 throw new SpannableAssertionFailure( 2048 throw new SpannableAssertionFailure(
2067 library, "The library '${uri}' was not found."); 2049 library, "The library '${uri}' was not found.");
2068 } 2050 }
2069 return library; 2051 return library;
2070 } 2052 }
2071 } 2053 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698