| 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 'closure.dart' as closureMapping show ClosureTask; | 10 import 'closure.dart' as closureMapping show ClosureTask; |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 | 205 |
| 206 backend = createBackend(); | 206 backend = createBackend(); |
| 207 enqueuer = backend.makeEnqueuer(); | 207 enqueuer = backend.makeEnqueuer(); |
| 208 | 208 |
| 209 tasks = [ | 209 tasks = [ |
| 210 dietParser = new DietParserTask(idGenerator, backend, reporter, measurer), | 210 dietParser = new DietParserTask(idGenerator, backend, reporter, measurer), |
| 211 scanner = createScannerTask(), | 211 scanner = createScannerTask(), |
| 212 serialization = new SerializationTask(this), | 212 serialization = new SerializationTask(this), |
| 213 patchParser = new PatchParserTask(this), | 213 patchParser = new PatchParserTask(this), |
| 214 libraryLoader = new LibraryLoaderTask( | 214 libraryLoader = new LibraryLoaderTask( |
| 215 options.loadFromDill, |
| 215 resolvedUriTranslator, | 216 resolvedUriTranslator, |
| 216 options.compileOnly | 217 options.compileOnly |
| 217 ? new _NoScriptLoader(this) | 218 ? new _NoScriptLoader(this) |
| 218 : new _ScriptLoader(this), | 219 : new _ScriptLoader(this), |
| 219 new _ElementScanner(scanner), | 220 new _ElementScanner(scanner), |
| 220 serialization, | 221 serialization, |
| 221 resolvePatchUri, | 222 resolvePatchUri, |
| 222 patchParser, | 223 patchParser, |
| 223 environment, | 224 environment, |
| 224 reporter, | 225 reporter, |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 !link.isEmpty; | 342 !link.isEmpty; |
| 342 link = link.tail) { | 343 link = link.tail) { |
| 343 Uri uri = link.head; | 344 Uri uri = link.head; |
| 344 if (!currentCodeLocation.inSameLocation(uri)) { | 345 if (!currentCodeLocation.inSameLocation(uri)) { |
| 345 currentCodeLocation = | 346 currentCodeLocation = |
| 346 options.verbose ? new UriLocation(uri) : new CodeLocation(uri); | 347 options.verbose ? new UriLocation(uri) : new CodeLocation(uri); |
| 347 compactImportChain = compactImportChain.prepend(currentCodeLocation); | 348 compactImportChain = compactImportChain.prepend(currentCodeLocation); |
| 348 } | 349 } |
| 349 } | 350 } |
| 350 String importChain = compactImportChain.map((CodeLocation codeLocation) { | 351 String importChain = compactImportChain.map((CodeLocation codeLocation) { |
| 351 return codeLocation | 352 return codeLocation.relativize( |
| 352 .relativize(loadedLibraries.rootLibrary.canonicalUri); | 353 (loadedLibraries.rootLibrary as LibraryElement).canonicalUri); |
| 353 }).join(' => '); | 354 }).join(' => '); |
| 354 | 355 |
| 355 if (!importChains.contains(importChain)) { | 356 if (!importChains.contains(importChain)) { |
| 356 if (importChains.length > compactChainLimit) { | 357 if (importChains.length > compactChainLimit) { |
| 357 importChains.add('...'); | 358 importChains.add('...'); |
| 358 return false; | 359 return false; |
| 359 } else { | 360 } else { |
| 360 importChains.add(importChain); | 361 importChains.add(importChain); |
| 361 } | 362 } |
| 362 } | 363 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 374 | 375 |
| 375 /// This method is called when all new libraries loaded through | 376 /// This method is called when all new libraries loaded through |
| 376 /// [LibraryLoader.loadLibrary] has been loaded and their imports/exports | 377 /// [LibraryLoader.loadLibrary] has been loaded and their imports/exports |
| 377 /// have been computed. | 378 /// have been computed. |
| 378 /// | 379 /// |
| 379 /// [loadedLibraries] contains the newly loaded libraries. | 380 /// [loadedLibraries] contains the newly loaded libraries. |
| 380 /// | 381 /// |
| 381 /// The method returns a [Future] allowing for the loading of additional | 382 /// The method returns a [Future] allowing for the loading of additional |
| 382 /// libraries. | 383 /// libraries. |
| 383 LoadedLibraries processLoadedLibraries(LoadedLibraries loadedLibraries) { | 384 LoadedLibraries processLoadedLibraries(LoadedLibraries loadedLibraries) { |
| 384 loadedLibraries.forEachLibrary((LibraryElement library) { | 385 loadedLibraries.forEachLibrary((LibraryEntity library) { |
| 385 backend.setAnnotations(library); | 386 backend.setAnnotations(library); |
| 386 }); | 387 }); |
| 387 | 388 |
| 388 for (Uri uri in resolvedUriTranslator.disallowedLibraryUris) { | 389 for (Uri uri in resolvedUriTranslator.disallowedLibraryUris) { |
| 389 if (loadedLibraries.containsLibrary(uri)) { | 390 if (loadedLibraries.containsLibrary(uri)) { |
| 390 Set<String> importChains = computeImportChainsFor(loadedLibraries, uri); | 391 Set<String> importChains = computeImportChainsFor(loadedLibraries, uri); |
| 391 reporter.reportInfo( | 392 reporter.reportInfo( |
| 392 NO_LOCATION_SPANNABLE, MessageKind.DISALLOWED_LIBRARY_IMPORT, { | 393 NO_LOCATION_SPANNABLE, MessageKind.DISALLOWED_LIBRARY_IMPORT, { |
| 393 'uri': uri, | 394 'uri': uri, |
| 394 'importChain': importChains | 395 'importChain': importChains |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 // this until after the resolution queue is processed. | 591 // this until after the resolution queue is processed. |
| 591 deferredLoadTask.beforeResolution(this); | 592 deferredLoadTask.beforeResolution(this); |
| 592 impactStrategy = backend.createImpactStrategy( | 593 impactStrategy = backend.createImpactStrategy( |
| 593 supportDeferredLoad: deferredLoadTask.isProgramSplit, | 594 supportDeferredLoad: deferredLoadTask.isProgramSplit, |
| 594 supportDumpInfo: options.dumpInfo, | 595 supportDumpInfo: options.dumpInfo, |
| 595 supportSerialization: serialization.supportSerialization); | 596 supportSerialization: serialization.supportSerialization); |
| 596 | 597 |
| 597 phase = PHASE_RESOLVING; | 598 phase = PHASE_RESOLVING; |
| 598 resolutionEnqueuer.applyImpact(mainImpact); | 599 resolutionEnqueuer.applyImpact(mainImpact); |
| 599 if (options.resolveOnly) { | 600 if (options.resolveOnly) { |
| 600 libraryLoader.libraries.where((LibraryElement library) { | 601 libraryLoader.libraries.where((LibraryEntity library) { |
| 601 return !serialization.isDeserialized(library); | 602 return !serialization.isDeserialized(library); |
| 602 }).forEach((LibraryElement library) { | 603 }).forEach((LibraryEntity library) { |
| 603 reporter.log('Enqueuing ${library.canonicalUri}'); | 604 reporter |
| 605 .log('Enqueuing ${(library as LibraryElement).canonicalUri}'); |
| 604 resolutionEnqueuer.applyImpact(computeImpactForLibrary(library)); | 606 resolutionEnqueuer.applyImpact(computeImpactForLibrary(library)); |
| 605 }); | 607 }); |
| 606 } else if (analyzeAll) { | 608 } else if (analyzeAll) { |
| 607 libraryLoader.libraries.forEach((LibraryElement library) { | 609 libraryLoader.libraries.forEach((LibraryEntity library) { |
| 608 reporter.log('Enqueuing ${library.canonicalUri}'); | 610 reporter |
| 611 .log('Enqueuing ${(library as LibraryElement).canonicalUri}'); |
| 609 resolutionEnqueuer.applyImpact(computeImpactForLibrary(library)); | 612 resolutionEnqueuer.applyImpact(computeImpactForLibrary(library)); |
| 610 }); | 613 }); |
| 611 } else if (options.analyzeMain) { | 614 } else if (options.analyzeMain) { |
| 612 if (mainApp != null) { | 615 if (mainApp != null) { |
| 613 resolutionEnqueuer.applyImpact(computeImpactForLibrary(mainApp)); | 616 resolutionEnqueuer.applyImpact(computeImpactForLibrary(mainApp)); |
| 614 } | 617 } |
| 615 if (librariesToAnalyzeWhenRun != null) { | 618 if (librariesToAnalyzeWhenRun != null) { |
| 616 for (Uri libraryUri in librariesToAnalyzeWhenRun) { | 619 for (Uri libraryUri in librariesToAnalyzeWhenRun) { |
| 617 resolutionEnqueuer.applyImpact(computeImpactForLibrary( | 620 resolutionEnqueuer.applyImpact(computeImpactForLibrary( |
| 618 libraryLoader.lookupLibrary(libraryUri))); | 621 libraryLoader.lookupLibrary(libraryUri))); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 643 .enableCodegenWithErrorsIfSupported(NO_LOCATION_SPANNABLE)) { | 646 .enableCodegenWithErrorsIfSupported(NO_LOCATION_SPANNABLE)) { |
| 644 return; | 647 return; |
| 645 } | 648 } |
| 646 } | 649 } |
| 647 | 650 |
| 648 if (options.resolveOnly && !compilationFailed) { | 651 if (options.resolveOnly && !compilationFailed) { |
| 649 reporter.log('Serializing to ${options.resolutionOutput}'); | 652 reporter.log('Serializing to ${options.resolutionOutput}'); |
| 650 serialization.serializeToSink( | 653 serialization.serializeToSink( |
| 651 userOutputProvider.createOutputSink( | 654 userOutputProvider.createOutputSink( |
| 652 '', 'data', api.OutputType.serializationData), | 655 '', 'data', api.OutputType.serializationData), |
| 653 libraryLoader.libraries.where((LibraryElement library) { | 656 libraryLoader.libraries.where((LibraryEntity library) { |
| 654 return !serialization.isDeserialized(library); | 657 return !serialization.isDeserialized(library); |
| 655 })); | 658 })); |
| 656 } | 659 } |
| 657 if (options.analyzeOnly) { | 660 if (options.analyzeOnly) { |
| 658 if (!analyzeAll && !compilationFailed) { | 661 if (!analyzeAll && !compilationFailed) { |
| 659 // No point in reporting unused code when [analyzeAll] is true: all | 662 // No point in reporting unused code when [analyzeAll] is true: all |
| 660 // code is artificially used. | 663 // code is artificially used. |
| 661 // If compilation failed, it is possible that the error prevents the | 664 // If compilation failed, it is possible that the error prevents the |
| 662 // compiler from analyzing all the code. | 665 // compiler from analyzing all the code. |
| 663 // TODO(johnniwinther): Reenable this when the reporting is more | 666 // TODO(johnniwinther): Reenable this when the reporting is more |
| (...skipping 16 matching lines...) Expand all Loading... |
| 680 backend.onTypeInferenceComplete(globalInference.results); | 683 backend.onTypeInferenceComplete(globalInference.results); |
| 681 | 684 |
| 682 reporter.log('Compiling...'); | 685 reporter.log('Compiling...'); |
| 683 phase = PHASE_COMPILING; | 686 phase = PHASE_COMPILING; |
| 684 | 687 |
| 685 Enqueuer codegenEnqueuer = enqueuer.createCodegenEnqueuer(closedWorld); | 688 Enqueuer codegenEnqueuer = enqueuer.createCodegenEnqueuer(closedWorld); |
| 686 _codegenWorldBuilder = codegenEnqueuer.worldBuilder; | 689 _codegenWorldBuilder = codegenEnqueuer.worldBuilder; |
| 687 codegenEnqueuer.applyImpact( | 690 codegenEnqueuer.applyImpact( |
| 688 backend.onCodegenStart(closedWorld, _codegenWorldBuilder)); | 691 backend.onCodegenStart(closedWorld, _codegenWorldBuilder)); |
| 689 if (compileAll) { | 692 if (compileAll) { |
| 690 libraryLoader.libraries.forEach((LibraryElement library) { | 693 libraryLoader.libraries.forEach((LibraryEntity library) { |
| 691 codegenEnqueuer.applyImpact(computeImpactForLibrary(library)); | 694 codegenEnqueuer.applyImpact(computeImpactForLibrary(library)); |
| 692 }); | 695 }); |
| 693 } | 696 } |
| 694 processQueue(codegenEnqueuer, mainMethod, libraryLoader.libraries, | 697 processQueue(codegenEnqueuer, mainMethod, libraryLoader.libraries, |
| 695 onProgress: showCodegenProgress); | 698 onProgress: showCodegenProgress); |
| 696 codegenEnqueuer.logSummary(reporter.log); | 699 codegenEnqueuer.logSummary(reporter.log); |
| 697 | 700 |
| 698 int programSize = backend.assembleProgram(closedWorld); | 701 int programSize = backend.assembleProgram(closedWorld); |
| 699 | 702 |
| 700 if (options.dumpInfo) { | 703 if (options.dumpInfo) { |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 957 member.forEachLocalMember(checkLive); | 960 member.forEachLocalMember(checkLive); |
| 958 } | 961 } |
| 959 } else if (member.isTypedef) { | 962 } else if (member.isTypedef) { |
| 960 if (!member.isResolved) { | 963 if (!member.isResolved) { |
| 961 reporter.reportHintMessage( | 964 reporter.reportHintMessage( |
| 962 member, MessageKind.UNUSED_TYPEDEF, {'name': member.name}); | 965 member, MessageKind.UNUSED_TYPEDEF, {'name': member.name}); |
| 963 } | 966 } |
| 964 } | 967 } |
| 965 } | 968 } |
| 966 | 969 |
| 967 libraryLoader.libraries.forEach((LibraryElement library) { | 970 libraryLoader.libraries.forEach((LibraryEntity entity) { |
| 968 // TODO(ahe): Implement better heuristics to discover entry points of | 971 // TODO(ahe): Implement better heuristics to discover entry points of |
| 969 // packages and use that to discover unused implementation details in | 972 // packages and use that to discover unused implementation details in |
| 970 // packages. | 973 // packages. |
| 974 LibraryElement library = entity; |
| 971 if (library.isPlatformLibrary || library.isPackageLibrary) return; | 975 if (library.isPlatformLibrary || library.isPackageLibrary) return; |
| 972 library.compilationUnits.forEach((unit) { | 976 library.compilationUnits.forEach((unit) { |
| 973 unit.forEachLocalMember(checkLive); | 977 unit.forEachLocalMember(checkLive); |
| 974 }); | 978 }); |
| 975 }); | 979 }); |
| 976 } | 980 } |
| 977 | 981 |
| 978 /// Helper for determining whether the current element is declared within | 982 /// Helper for determining whether the current element is declared within |
| 979 /// 'user code'. | 983 /// 'user code'. |
| 980 /// | 984 /// |
| (...skipping 985 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1966 if (library != null && library.isSynthesized) { | 1970 if (library != null && library.isSynthesized) { |
| 1967 return null; | 1971 return null; |
| 1968 } | 1972 } |
| 1969 if (library == null && required) { | 1973 if (library == null && required) { |
| 1970 throw new SpannableAssertionFailure( | 1974 throw new SpannableAssertionFailure( |
| 1971 library, "The library '${uri}' was not found."); | 1975 library, "The library '${uri}' was not found."); |
| 1972 } | 1976 } |
| 1973 return library; | 1977 return library; |
| 1974 } | 1978 } |
| 1975 } | 1979 } |
| OLD | NEW |