| 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.compiler_base; | 5 library dart2js.compiler_base; |
| 6 | 6 |
| 7 import 'dart:async' show Future; | 7 import 'dart:async' show Future; |
| 8 | 8 |
| 9 import '../compiler_new.dart' as api; | 9 import '../compiler_new.dart' as api; |
| 10 import 'backend_strategy.dart'; | 10 import 'backend_strategy.dart'; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 show ImpactStrategy, WorldImpact, WorldImpactBuilderImpl; | 75 show ImpactStrategy, WorldImpact, WorldImpactBuilderImpl; |
| 76 import 'util/util.dart' show Link; | 76 import 'util/util.dart' show Link; |
| 77 import 'world.dart' show ClosedWorld, ClosedWorldRefiner; | 77 import 'world.dart' show ClosedWorld, ClosedWorldRefiner; |
| 78 | 78 |
| 79 typedef CompilerDiagnosticReporter MakeReporterFunction( | 79 typedef CompilerDiagnosticReporter MakeReporterFunction( |
| 80 Compiler compiler, CompilerOptions options); | 80 Compiler compiler, CompilerOptions options); |
| 81 | 81 |
| 82 abstract class Compiler { | 82 abstract class Compiler { |
| 83 Measurer get measurer; | 83 Measurer get measurer; |
| 84 | 84 |
| 85 api.CompilerInput get provider; |
| 86 |
| 85 final IdGenerator idGenerator = new IdGenerator(); | 87 final IdGenerator idGenerator = new IdGenerator(); |
| 86 FrontendStrategy frontendStrategy; | 88 FrontendStrategy frontendStrategy; |
| 87 BackendStrategy backendStrategy; | 89 BackendStrategy backendStrategy; |
| 88 CompilerDiagnosticReporter _reporter; | 90 CompilerDiagnosticReporter _reporter; |
| 89 CompilerResolution _resolution; | 91 CompilerResolution _resolution; |
| 90 ParsingContext _parsingContext; | 92 ParsingContext _parsingContext; |
| 91 | 93 |
| 92 ImpactStrategy impactStrategy = const ImpactStrategy(); | 94 ImpactStrategy impactStrategy = const ImpactStrategy(); |
| 93 | 95 |
| 94 /** | 96 /** |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 MakeReporterFunction makeReporter}) | 183 MakeReporterFunction makeReporter}) |
| 182 : this.options = options, | 184 : this.options = options, |
| 183 this.userOutputProvider = outputProvider == null | 185 this.userOutputProvider = outputProvider == null |
| 184 ? const NullCompilerOutput() | 186 ? const NullCompilerOutput() |
| 185 : outputProvider { | 187 : outputProvider { |
| 186 if (makeReporter != null) { | 188 if (makeReporter != null) { |
| 187 _reporter = makeReporter(this, options); | 189 _reporter = makeReporter(this, options); |
| 188 } else { | 190 } else { |
| 189 _reporter = new CompilerDiagnosticReporter(this, options); | 191 _reporter = new CompilerDiagnosticReporter(this, options); |
| 190 } | 192 } |
| 191 frontendStrategy = options.loadFromDill | 193 frontendStrategy = options.useKernel |
| 192 ? new KernelFrontEndStrategy(options, reporter, environment) | 194 ? new KernelFrontEndStrategy(options, reporter, environment) |
| 193 : new ResolutionFrontEndStrategy(this); | 195 : new ResolutionFrontEndStrategy(this); |
| 194 backendStrategy = options.loadFromDill | 196 backendStrategy = options.useKernel |
| 195 ? new KernelBackendStrategy(this) | 197 ? new KernelBackendStrategy(this) |
| 196 : new ElementBackendStrategy(this); | 198 : new ElementBackendStrategy(this); |
| 197 _resolution = createResolution(); | 199 _resolution = createResolution(); |
| 198 | 200 |
| 199 if (options.verbose) { | 201 if (options.verbose) { |
| 200 progress = new Stopwatch()..start(); | 202 progress = new Stopwatch()..start(); |
| 201 } | 203 } |
| 202 | 204 |
| 203 backend = createBackend(); | 205 backend = createBackend(); |
| 204 enqueuer = backend.makeEnqueuer(); | 206 enqueuer = backend.makeEnqueuer(); |
| 205 | 207 |
| 206 tasks = [ | 208 tasks = [ |
| 207 dietParser = new DietParserTask(idGenerator, backend, reporter, measurer), | 209 dietParser = new DietParserTask(idGenerator, backend, reporter, measurer), |
| 208 scanner = createScannerTask(), | 210 scanner = createScannerTask(), |
| 209 serialization = new SerializationTask(this), | 211 serialization = new SerializationTask(this), |
| 210 patchParser = new PatchParserTask(this), | 212 patchParser = new PatchParserTask(this), |
| 211 libraryLoader = frontendStrategy.createLibraryLoader( | 213 libraryLoader = frontendStrategy.createLibraryLoader( |
| 212 resolvedUriTranslator, | 214 resolvedUriTranslator, |
| 213 options.compileOnly | 215 options.compileOnly |
| 214 ? new _NoScriptLoader(this) | 216 ? new _NoScriptLoader(this) |
| 215 : new _ScriptLoader(this), | 217 : new _ScriptLoader(this), |
| 218 provider, |
| 216 new _ElementScanner(scanner), | 219 new _ElementScanner(scanner), |
| 217 serialization, | 220 serialization, |
| 218 resolvePatchUri, | 221 resolvePatchUri, |
| 219 patchParser, | 222 patchParser, |
| 220 environment, | 223 environment, |
| 221 reporter, | 224 reporter, |
| 222 measurer), | 225 measurer), |
| 223 parser = new ParserTask(this), | 226 parser = new ParserTask(this), |
| 224 resolver = createResolverTask(), | 227 resolver = createResolverTask(), |
| 225 checker = new TypeCheckerTask(this), | 228 checker = new TypeCheckerTask(this), |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 /// libraries. | 376 /// libraries. |
| 374 LoadedLibraries processLoadedLibraries(LoadedLibraries loadedLibraries) { | 377 LoadedLibraries processLoadedLibraries(LoadedLibraries loadedLibraries) { |
| 375 loadedLibraries.forEachLibrary((LibraryEntity library) { | 378 loadedLibraries.forEachLibrary((LibraryEntity library) { |
| 376 backend.setAnnotations(library); | 379 backend.setAnnotations(library); |
| 377 }); | 380 }); |
| 378 | 381 |
| 379 // TODO(efortuna, sigmund): These validation steps should be done in the | 382 // TODO(efortuna, sigmund): These validation steps should be done in the |
| 380 // front end for the Kernel path since Kernel doesn't have the notion of | 383 // front end for the Kernel path since Kernel doesn't have the notion of |
| 381 // imports (everything has already been resolved). (See | 384 // imports (everything has already been resolved). (See |
| 382 // https://github.com/dart-lang/sdk/issues/29368) | 385 // https://github.com/dart-lang/sdk/issues/29368) |
| 383 if (!options.useKernel && !options.loadFromDill) { | 386 if (!options.useKernel) { |
| 384 for (Uri uri in resolvedUriTranslator.disallowedLibraryUris) { | 387 for (Uri uri in resolvedUriTranslator.disallowedLibraryUris) { |
| 385 if (loadedLibraries.containsLibrary(uri)) { | 388 if (loadedLibraries.containsLibrary(uri)) { |
| 386 Set<String> importChains = | 389 Set<String> importChains = |
| 387 computeImportChainsFor(loadedLibraries, uri); | 390 computeImportChainsFor(loadedLibraries, uri); |
| 388 reporter.reportInfo( | 391 reporter.reportInfo( |
| 389 NO_LOCATION_SPANNABLE, MessageKind.DISALLOWED_LIBRARY_IMPORT, { | 392 NO_LOCATION_SPANNABLE, MessageKind.DISALLOWED_LIBRARY_IMPORT, { |
| 390 'uri': uri, | 393 'uri': uri, |
| 391 'importChain': importChains | 394 'importChain': importChains |
| 392 .join(MessageTemplate.DISALLOWED_LIBRARY_IMPORT_PADDING) | 395 .join(MessageTemplate.DISALLOWED_LIBRARY_IMPORT_PADDING) |
| 393 }); | 396 }); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 }); | 457 }); |
| 455 } | 458 } |
| 456 LibraryEntity mainApp; | 459 LibraryEntity mainApp; |
| 457 if (uri != null) { | 460 if (uri != null) { |
| 458 if (options.analyzeOnly) { | 461 if (options.analyzeOnly) { |
| 459 reporter.log('Analyzing $uri (${options.buildId})'); | 462 reporter.log('Analyzing $uri (${options.buildId})'); |
| 460 } else { | 463 } else { |
| 461 reporter.log('Compiling $uri (${options.buildId})'); | 464 reporter.log('Compiling $uri (${options.buildId})'); |
| 462 } | 465 } |
| 463 LoadedLibraries libraries = await libraryLoader.loadLibrary(uri); | 466 LoadedLibraries libraries = await libraryLoader.loadLibrary(uri); |
| 467 // Note: libraries may be null because of errors trying to find files or |
| 468 // parse-time errors (when using `package:front_end` as a loader). |
| 469 if (libraries == null) return; |
| 464 processLoadedLibraries(libraries); | 470 processLoadedLibraries(libraries); |
| 465 mainApp = libraries.rootLibrary; | 471 mainApp = libraries.rootLibrary; |
| 466 } | 472 } |
| 467 compileLoadedLibraries(mainApp); | 473 compileLoadedLibraries(mainApp); |
| 468 } | 474 } |
| 469 | 475 |
| 470 /// Analyze all members of the library in [libraryUri]. | 476 /// Analyze all members of the library in [libraryUri]. |
| 471 /// | 477 /// |
| 472 /// If [skipLibraryWithPartOfTag] is `true`, member analysis is skipped if the | 478 /// If [skipLibraryWithPartOfTag] is `true`, member analysis is skipped if the |
| 473 /// library has a `part of` tag, assuming it is a part and not a library. | 479 /// library has a `part of` tag, assuming it is a part and not a library. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 } | 514 } |
| 509 | 515 |
| 510 /// Performs the compilation when all libraries have been loaded. | 516 /// Performs the compilation when all libraries have been loaded. |
| 511 void compileLoadedLibraries(LibraryEntity rootLibrary) => | 517 void compileLoadedLibraries(LibraryEntity rootLibrary) => |
| 512 selfTask.measureSubtask("Compiler.compileLoadedLibraries", () { | 518 selfTask.measureSubtask("Compiler.compileLoadedLibraries", () { |
| 513 ResolutionEnqueuer resolutionEnqueuer = startResolution(); | 519 ResolutionEnqueuer resolutionEnqueuer = startResolution(); |
| 514 WorldImpactBuilderImpl mainImpact = new WorldImpactBuilderImpl(); | 520 WorldImpactBuilderImpl mainImpact = new WorldImpactBuilderImpl(); |
| 515 FunctionEntity mainFunction = | 521 FunctionEntity mainFunction = |
| 516 frontendStrategy.computeMain(rootLibrary, mainImpact); | 522 frontendStrategy.computeMain(rootLibrary, mainImpact); |
| 517 | 523 |
| 518 if (!options.loadFromDill) { | 524 if (!options.useKernel) { |
| 519 // TODO(johnniwinther): Support mirrors usages analysis from dill. | 525 // TODO(johnniwinther): Support mirrors usages analysis from dill. |
| 520 mirrorUsageAnalyzerTask.analyzeUsage(rootLibrary); | 526 mirrorUsageAnalyzerTask.analyzeUsage(rootLibrary); |
| 521 } | 527 } |
| 522 | 528 |
| 523 // In order to see if a library is deferred, we must compute the | 529 // In order to see if a library is deferred, we must compute the |
| 524 // compile-time constants that are metadata. This means adding | 530 // compile-time constants that are metadata. This means adding |
| 525 // something to the resolution queue. So we cannot wait with | 531 // something to the resolution queue. So we cannot wait with |
| 526 // this until after the resolution queue is processed. | 532 // this until after the resolution queue is processed. |
| 527 deferredLoadTask.beforeResolution(rootLibrary); | 533 deferredLoadTask.beforeResolution(rootLibrary); |
| 528 impactStrategy = backend.createImpactStrategy( | 534 impactStrategy = backend.createImpactStrategy( |
| (...skipping 21 matching lines...) Expand all Loading... |
| 550 .applyImpact(computeImpactForLibrary(rootLibrary)); | 556 .applyImpact(computeImpactForLibrary(rootLibrary)); |
| 551 } | 557 } |
| 552 if (librariesToAnalyzeWhenRun != null) { | 558 if (librariesToAnalyzeWhenRun != null) { |
| 553 for (Uri libraryUri in librariesToAnalyzeWhenRun) { | 559 for (Uri libraryUri in librariesToAnalyzeWhenRun) { |
| 554 resolutionEnqueuer.applyImpact(computeImpactForLibrary( | 560 resolutionEnqueuer.applyImpact(computeImpactForLibrary( |
| 555 libraryLoader.lookupLibrary(libraryUri))); | 561 libraryLoader.lookupLibrary(libraryUri))); |
| 556 } | 562 } |
| 557 } | 563 } |
| 558 } | 564 } |
| 559 if (frontendStrategy.commonElements.mirrorsLibrary != null && | 565 if (frontendStrategy.commonElements.mirrorsLibrary != null && |
| 560 !options.loadFromDill) { | 566 !options.useKernel) { |
| 561 // TODO(johnniwinther): Support mirrors from dill. | 567 // TODO(johnniwinther): Support mirrors from dill. |
| 562 resolveLibraryMetadata(); | 568 resolveLibraryMetadata(); |
| 563 } | 569 } |
| 564 reporter.log('Resolving...'); | 570 reporter.log('Resolving...'); |
| 565 | 571 |
| 566 processQueue(frontendStrategy.elementEnvironment, resolutionEnqueuer, | 572 processQueue(frontendStrategy.elementEnvironment, resolutionEnqueuer, |
| 567 mainFunction, libraryLoader.libraries, | 573 mainFunction, libraryLoader.libraries, |
| 568 onProgress: showResolutionProgress); | 574 onProgress: showResolutionProgress); |
| 569 backend.onResolutionEnd(); | 575 backend.onResolutionEnd(); |
| 570 resolutionEnqueuer.logSummary(reporter.log); | 576 resolutionEnqueuer.logSummary(reporter.log); |
| 571 | 577 |
| 572 _reporter.reportSuppressedMessagesSummary(); | 578 _reporter.reportSuppressedMessagesSummary(); |
| 573 | 579 |
| 574 if (compilationFailed) { | 580 if (compilationFailed) { |
| 575 if (!options.generateCodeWithCompileTimeErrors || options.useKernel) { | 581 if (!options.generateCodeWithCompileTimeErrors || |
| 582 options.useKernelInSsa) { |
| 576 return; | 583 return; |
| 577 } | 584 } |
| 578 if (mainFunction == null) return; | 585 if (mainFunction == null) return; |
| 579 if (!backend | 586 if (!backend |
| 580 .enableCodegenWithErrorsIfSupported(NO_LOCATION_SPANNABLE)) { | 587 .enableCodegenWithErrorsIfSupported(NO_LOCATION_SPANNABLE)) { |
| 581 return; | 588 return; |
| 582 } | 589 } |
| 583 } | 590 } |
| 584 | 591 |
| 585 if (options.resolveOnly && !compilationFailed) { | 592 if (options.resolveOnly && !compilationFailed) { |
| (...skipping 1012 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1598 _ElementScanner(this.scanner); | 1605 _ElementScanner(this.scanner); |
| 1599 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); | 1606 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); |
| 1600 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); | 1607 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); |
| 1601 } | 1608 } |
| 1602 | 1609 |
| 1603 class _EmptyEnvironment implements Environment { | 1610 class _EmptyEnvironment implements Environment { |
| 1604 const _EmptyEnvironment(); | 1611 const _EmptyEnvironment(); |
| 1605 | 1612 |
| 1606 String valueOf(String key) => null; | 1613 String valueOf(String key) => null; |
| 1607 } | 1614 } |
| OLD | NEW |