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 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 'cache_strategy.dart' show CacheStrategy; | 10 import 'cache_strategy.dart' show CacheStrategy; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 LibraryLoaderTask, | 49 LibraryLoaderTask, |
50 LoadedLibraries, | 50 LoadedLibraries, |
51 LibraryLoaderListener, | 51 LibraryLoaderListener, |
52 ScriptLoader; | 52 ScriptLoader; |
53 import 'mirrors_used.dart' show MirrorUsageAnalyzerTask; | 53 import 'mirrors_used.dart' show MirrorUsageAnalyzerTask; |
54 import 'null_compiler_output.dart' show NullCompilerOutput, NullSink; | 54 import 'null_compiler_output.dart' show NullCompilerOutput, NullSink; |
55 import 'options.dart' show CompilerOptions, DiagnosticOptions; | 55 import 'options.dart' show CompilerOptions, DiagnosticOptions; |
56 import 'parser/diet_parser_task.dart' show DietParserTask; | 56 import 'parser/diet_parser_task.dart' show DietParserTask; |
57 import 'parser/parser_task.dart' show ParserTask; | 57 import 'parser/parser_task.dart' show ParserTask; |
58 import 'patch_parser.dart' show PatchParserTask; | 58 import 'patch_parser.dart' show PatchParserTask; |
59 import 'resolution/registry.dart' show ResolutionRegistry; | |
60 import 'resolution/resolution.dart' show ResolverTask; | 59 import 'resolution/resolution.dart' show ResolverTask; |
61 import 'resolution/tree_elements.dart' show TreeElementMapping; | |
62 import 'resolved_uri_translator.dart'; | 60 import 'resolved_uri_translator.dart'; |
63 import 'scanner/scanner_task.dart' show ScannerTask; | 61 import 'scanner/scanner_task.dart' show ScannerTask; |
64 import 'script.dart' show Script; | 62 import 'script.dart' show Script; |
65 import 'serialization/task.dart' show SerializationTask; | 63 import 'serialization/task.dart' show SerializationTask; |
66 import 'ssa/nodes.dart' show HInstruction; | 64 import 'ssa/nodes.dart' show HInstruction; |
67 import 'tokens/token.dart' show StringToken, Token, TokenPair; | 65 import 'tokens/token.dart' show StringToken, Token, TokenPair; |
68 import 'tokens/token_map.dart' show TokenMap; | 66 import 'tokens/token_map.dart' show TokenMap; |
69 import 'tracer.dart' show Tracer; | 67 import 'tracer.dart' show Tracer; |
70 import 'tree/tree.dart' show Node, TypeAnnotation; | 68 import 'tree/tree.dart' show Node, TypeAnnotation; |
71 import 'typechecker.dart' show TypeCheckerTask; | 69 import 'typechecker.dart' show TypeCheckerTask; |
72 import 'types/types.dart' show GlobalTypeInferenceTask; | 70 import 'types/types.dart' show GlobalTypeInferenceTask; |
73 import 'types/masks.dart' show CommonMasks; | |
74 import 'universe/selector.dart' show Selector; | 71 import 'universe/selector.dart' show Selector; |
75 import 'universe/world_builder.dart' | 72 import 'universe/world_builder.dart' |
76 show ResolutionWorldBuilder, CodegenWorldBuilder; | 73 show ResolutionWorldBuilder, CodegenWorldBuilder; |
77 import 'universe/use.dart' show StaticUse; | 74 import 'universe/use.dart' show StaticUse, TypeUse; |
78 import 'universe/world_impact.dart' | 75 import 'universe/world_impact.dart' |
79 show | 76 show |
80 ImpactStrategy, | 77 ImpactStrategy, |
81 WorldImpact, | 78 WorldImpact, |
82 WorldImpactBuilder, | 79 WorldImpactBuilder, |
83 WorldImpactBuilderImpl; | 80 WorldImpactBuilderImpl; |
84 import 'util/util.dart' show Link, Setlet; | 81 import 'util/util.dart' show Link, Setlet; |
85 import 'world.dart' show ClosedWorld, ClosedWorldRefiner, OpenWorld, WorldImpl; | 82 import 'world.dart' show ClosedWorld, ClosedWorldRefiner, OpenWorld, WorldImpl; |
86 | 83 |
87 typedef Backend MakeBackendFuncion(Compiler compiler); | 84 typedef Backend MakeBackendFuncion(Compiler compiler); |
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 /// This operation assumes an unclosed resolution queue and is only supported | 621 /// This operation assumes an unclosed resolution queue and is only supported |
625 /// when the '--analyze-main' option is used. | 622 /// when the '--analyze-main' option is used. |
626 Future<LibraryElement> analyzeUri(Uri libraryUri, | 623 Future<LibraryElement> analyzeUri(Uri libraryUri, |
627 {bool skipLibraryWithPartOfTag: true}) { | 624 {bool skipLibraryWithPartOfTag: true}) { |
628 assert(options.analyzeMain); | 625 assert(options.analyzeMain); |
629 reporter.log('Analyzing $libraryUri (${options.buildId})'); | 626 reporter.log('Analyzing $libraryUri (${options.buildId})'); |
630 return libraryLoader | 627 return libraryLoader |
631 .loadLibrary(libraryUri, skipFileWithPartOfTag: true) | 628 .loadLibrary(libraryUri, skipFileWithPartOfTag: true) |
632 .then((LibraryElement library) { | 629 .then((LibraryElement library) { |
633 if (library == null) return null; | 630 if (library == null) return null; |
634 fullyEnqueueLibrary(library, enqueuer.resolution); | 631 enqueuer.resolution.applyImpact(computeImpactForLibrary(library)); |
635 emptyQueue(enqueuer.resolution); | 632 emptyQueue(enqueuer.resolution); |
636 enqueuer.resolution.logSummary(reporter.log); | 633 enqueuer.resolution.logSummary(reporter.log); |
637 return library; | 634 return library; |
638 }); | 635 }); |
639 } | 636 } |
640 | 637 |
641 /// Performs the compilation when all libraries have been loaded. | 638 /// Performs the compilation when all libraries have been loaded. |
642 void compileLoadedLibraries() => | 639 void compileLoadedLibraries() => |
643 selfTask.measureSubtask("Compiler.compileLoadedLibraries", () { | 640 selfTask.measureSubtask("Compiler.compileLoadedLibraries", () { |
644 WorldImpact mainImpact = computeMain(); | 641 WorldImpact mainImpact = computeMain(); |
(...skipping 10 matching lines...) Expand all Loading... |
655 supportDumpInfo: options.dumpInfo, | 652 supportDumpInfo: options.dumpInfo, |
656 supportSerialization: serialization.supportSerialization); | 653 supportSerialization: serialization.supportSerialization); |
657 | 654 |
658 phase = PHASE_RESOLVING; | 655 phase = PHASE_RESOLVING; |
659 enqueuer.resolution.applyImpact(mainImpact); | 656 enqueuer.resolution.applyImpact(mainImpact); |
660 if (options.resolveOnly) { | 657 if (options.resolveOnly) { |
661 libraryLoader.libraries.where((LibraryElement library) { | 658 libraryLoader.libraries.where((LibraryElement library) { |
662 return !serialization.isDeserialized(library); | 659 return !serialization.isDeserialized(library); |
663 }).forEach((LibraryElement library) { | 660 }).forEach((LibraryElement library) { |
664 reporter.log('Enqueuing ${library.canonicalUri}'); | 661 reporter.log('Enqueuing ${library.canonicalUri}'); |
665 fullyEnqueueLibrary(library, enqueuer.resolution); | 662 enqueuer.resolution.applyImpact(computeImpactForLibrary(library)); |
666 }); | 663 }); |
667 } else if (analyzeAll) { | 664 } else if (analyzeAll) { |
668 libraryLoader.libraries.forEach((LibraryElement library) { | 665 libraryLoader.libraries.forEach((LibraryElement library) { |
669 reporter.log('Enqueuing ${library.canonicalUri}'); | 666 reporter.log('Enqueuing ${library.canonicalUri}'); |
670 fullyEnqueueLibrary(library, enqueuer.resolution); | 667 enqueuer.resolution.applyImpact(computeImpactForLibrary(library)); |
671 }); | 668 }); |
672 } else if (options.analyzeMain) { | 669 } else if (options.analyzeMain) { |
673 if (mainApp != null) { | 670 if (mainApp != null) { |
674 fullyEnqueueLibrary(mainApp, enqueuer.resolution); | 671 enqueuer.resolution.applyImpact(computeImpactForLibrary(mainApp)); |
675 } | 672 } |
676 if (librariesToAnalyzeWhenRun != null) { | 673 if (librariesToAnalyzeWhenRun != null) { |
677 for (Uri libraryUri in librariesToAnalyzeWhenRun) { | 674 for (Uri libraryUri in librariesToAnalyzeWhenRun) { |
678 fullyEnqueueLibrary( | 675 enqueuer.resolution.applyImpact(computeImpactForLibrary( |
679 libraryLoader.lookupLibrary(libraryUri), enqueuer.resolution); | 676 libraryLoader.lookupLibrary(libraryUri))); |
680 } | 677 } |
681 } | 678 } |
682 } | 679 } |
683 if (deferredLoadTask.isProgramSplit) { | 680 if (deferredLoadTask.isProgramSplit) { |
684 enqueuer.resolution | 681 enqueuer.resolution |
685 .applyImpact(backend.computeDeferredLoadingImpact()); | 682 .applyImpact(backend.computeDeferredLoadingImpact()); |
686 } | 683 } |
687 // Elements required by enqueueHelpers are global dependencies | 684 // Elements required by enqueueHelpers are global dependencies |
688 // that are not pulled in by a particular element. | 685 // that are not pulled in by a particular element. |
689 enqueuer.resolution.applyImpact(backend.computeHelpersImpact()); | 686 enqueuer.resolution.applyImpact(backend.computeHelpersImpact()); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 | 729 |
733 reporter.log('Inferring types...'); | 730 reporter.log('Inferring types...'); |
734 globalInference.runGlobalTypeInference(mainFunction); | 731 globalInference.runGlobalTypeInference(mainFunction); |
735 | 732 |
736 if (stopAfterTypeInference) return; | 733 if (stopAfterTypeInference) return; |
737 | 734 |
738 backend.onTypeInferenceComplete(); | 735 backend.onTypeInferenceComplete(); |
739 | 736 |
740 reporter.log('Compiling...'); | 737 reporter.log('Compiling...'); |
741 phase = PHASE_COMPILING; | 738 phase = PHASE_COMPILING; |
| 739 |
742 backend.onCodegenStart(); | 740 backend.onCodegenStart(); |
743 if (hasIsolateSupport) { | 741 if (hasIsolateSupport) { |
744 enqueuer.codegen | 742 enqueuer.codegen |
745 .applyImpact(backend.enableIsolateSupport(forResolution: false)); | 743 .applyImpact(backend.enableIsolateSupport(forResolution: false)); |
746 } | 744 } |
747 if (compileAll) { | 745 if (compileAll) { |
748 libraryLoader.libraries.forEach((LibraryElement library) { | 746 libraryLoader.libraries.forEach((LibraryElement library) { |
749 fullyEnqueueLibrary(library, enqueuer.codegen); | 747 enqueuer.codegen.applyImpact(computeImpactForLibrary(library)); |
750 }); | 748 }); |
751 } | 749 } |
752 processQueue(enqueuer.codegen, mainFunction); | 750 processQueue(enqueuer.codegen, mainFunction); |
753 enqueuer.codegen.logSummary(reporter.log); | 751 enqueuer.codegen.logSummary(reporter.log); |
754 | 752 |
755 int programSize = backend.assembleProgram(); | 753 int programSize = backend.assembleProgram(); |
756 | 754 |
757 if (options.dumpInfo) { | 755 if (options.dumpInfo) { |
758 dumpInfoTask.reportSize(programSize); | 756 dumpInfoTask.reportSize(programSize); |
759 dumpInfoTask.dumpInfo(); | 757 dumpInfoTask.dumpInfo(); |
(...skipping 13 matching lines...) Expand all Loading... |
773 // require the information computed in [world.closeWorld].) | 771 // require the information computed in [world.closeWorld].) |
774 backend.onResolutionComplete(); | 772 backend.onResolutionComplete(); |
775 | 773 |
776 deferredLoadTask.onResolutionComplete(mainFunction); | 774 deferredLoadTask.onResolutionComplete(mainFunction); |
777 | 775 |
778 // TODO(johnniwinther): Move this after rti computation but before | 776 // TODO(johnniwinther): Move this after rti computation but before |
779 // reflection members computation, and (re-)close the world afterwards. | 777 // reflection members computation, and (re-)close the world afterwards. |
780 closureToClassMapper.createClosureClasses(); | 778 closureToClassMapper.createClosureClasses(); |
781 } | 779 } |
782 | 780 |
783 void fullyEnqueueLibrary(LibraryElement library, Enqueuer world) { | 781 /// Compute the [WorldImpact] for accessing all elements in [library]. |
784 void enqueueAll(Element element) { | 782 WorldImpact computeImpactForLibrary(LibraryElement library) { |
785 fullyEnqueueTopLevelElement(element, world); | 783 WorldImpactBuilderImpl impactBuilder = new WorldImpactBuilderImpl(); |
| 784 |
| 785 void registerStaticUse(Element element) { |
| 786 impactBuilder.registerStaticUse(new StaticUse.directUse(element)); |
786 } | 787 } |
787 | 788 |
788 library.implementation.forEachLocalMember(enqueueAll); | 789 void registerElement(Element element) { |
| 790 if (element.isClass) { |
| 791 ClassElement cls = element; |
| 792 cls.ensureResolved(resolution); |
| 793 cls.forEachLocalMember(registerStaticUse); |
| 794 impactBuilder.registerTypeUse(new TypeUse.instantiation(cls.rawType)); |
| 795 } else { |
| 796 registerStaticUse(element); |
| 797 } |
| 798 } |
| 799 |
| 800 library.implementation.forEachLocalMember(registerElement); |
| 801 |
789 library.imports.forEach((ImportElement import) { | 802 library.imports.forEach((ImportElement import) { |
790 if (import.isDeferred) { | 803 if (import.isDeferred) { |
791 // `import.prefix` and `loadLibrary` may be `null` when the deferred | 804 // `import.prefix` and `loadLibrary` may be `null` when the deferred |
792 // import has compile-time errors. | 805 // import has compile-time errors. |
793 GetterElement loadLibrary = import.prefix?.loadLibrary; | 806 GetterElement loadLibrary = import.prefix?.loadLibrary; |
794 if (loadLibrary != null) { | 807 if (loadLibrary != null) { |
795 world.addToWorkList(loadLibrary); | 808 registerStaticUse(loadLibrary); |
796 } | 809 } |
797 } | 810 } |
798 if (serialization.supportSerialization) { | 811 if (serialization.supportSerialization) { |
799 for (MetadataAnnotation metadata in import.metadata) { | 812 for (MetadataAnnotation metadata in import.metadata) { |
800 metadata.ensureResolved(resolution); | 813 metadata.ensureResolved(resolution); |
801 } | 814 } |
802 } | 815 } |
803 }); | 816 }); |
804 if (serialization.supportSerialization) { | 817 if (serialization.supportSerialization) { |
805 library.exports.forEach((ExportElement export) { | 818 library.exports.forEach((ExportElement export) { |
806 for (MetadataAnnotation metadata in export.metadata) { | 819 for (MetadataAnnotation metadata in export.metadata) { |
807 metadata.ensureResolved(resolution); | 820 metadata.ensureResolved(resolution); |
808 } | 821 } |
809 }); | 822 }); |
810 library.compilationUnits.forEach((CompilationUnitElement unit) { | 823 library.compilationUnits.forEach((CompilationUnitElement unit) { |
811 for (MetadataAnnotation metadata in unit.metadata) { | 824 for (MetadataAnnotation metadata in unit.metadata) { |
812 metadata.ensureResolved(resolution); | 825 metadata.ensureResolved(resolution); |
813 } | 826 } |
814 }); | 827 }); |
815 } | 828 } |
816 } | 829 return impactBuilder; |
817 | |
818 void fullyEnqueueTopLevelElement(Element element, Enqueuer world) { | |
819 if (element.isClass) { | |
820 ClassElement cls = element; | |
821 cls.ensureResolved(resolution); | |
822 cls.forEachLocalMember(enqueuer.resolution.addToWorkList); | |
823 world.registerInstantiatedType(cls.rawType); | |
824 } else { | |
825 world.addToWorkList(element); | |
826 } | |
827 } | 830 } |
828 | 831 |
829 // Resolves metadata on library elements. This is necessary in order to | 832 // Resolves metadata on library elements. This is necessary in order to |
830 // resolve metadata classes referenced only from metadata on library tags. | 833 // resolve metadata classes referenced only from metadata on library tags. |
831 // TODO(ahe): Figure out how to do this lazily. | 834 // TODO(ahe): Figure out how to do this lazily. |
832 void resolveLibraryMetadata() { | 835 void resolveLibraryMetadata() { |
833 for (LibraryElement library in libraryLoader.libraries) { | 836 for (LibraryElement library in libraryLoader.libraries) { |
834 if (library.metadata != null) { | 837 if (library.metadata != null) { |
835 for (MetadataAnnotation metadata in library.metadata) { | 838 for (MetadataAnnotation metadata in library.metadata) { |
836 metadata.ensureResolved(resolution); | 839 metadata.ensureResolved(resolution); |
(...skipping 1417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2254 _ElementScanner(this.scanner); | 2257 _ElementScanner(this.scanner); |
2255 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); | 2258 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); |
2256 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); | 2259 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); |
2257 } | 2260 } |
2258 | 2261 |
2259 class _EmptyEnvironment implements Environment { | 2262 class _EmptyEnvironment implements Environment { |
2260 const _EmptyEnvironment(); | 2263 const _EmptyEnvironment(); |
2261 | 2264 |
2262 String valueOf(String key) => null; | 2265 String valueOf(String key) => null; |
2263 } | 2266 } |
OLD | NEW |