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

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

Issue 2494093002: Refactor enqueuers (Closed)
Patch Set: Refactor enqueuers Created 4 years, 1 month 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 'cache_strategy.dart' show CacheStrategy; 10 import 'cache_strategy.dart' show CacheStrategy;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 import 'tokens/token_map.dart' show TokenMap; 69 import 'tokens/token_map.dart' show TokenMap;
70 import 'tracer.dart' show Tracer; 70 import 'tracer.dart' show Tracer;
71 import 'tree/tree.dart' show Node, TypeAnnotation; 71 import 'tree/tree.dart' show Node, TypeAnnotation;
72 import 'typechecker.dart' show TypeCheckerTask; 72 import 'typechecker.dart' show TypeCheckerTask;
73 import 'types/types.dart' show GlobalTypeInferenceTask; 73 import 'types/types.dart' show GlobalTypeInferenceTask;
74 import 'types/masks.dart' show CommonMasks; 74 import 'types/masks.dart' show CommonMasks;
75 import 'universe/selector.dart' show Selector; 75 import 'universe/selector.dart' show Selector;
76 import 'universe/world_builder.dart' 76 import 'universe/world_builder.dart'
77 show ResolutionWorldBuilder, CodegenWorldBuilder; 77 show ResolutionWorldBuilder, CodegenWorldBuilder;
78 import 'universe/use.dart' show StaticUse; 78 import 'universe/use.dart' show StaticUse;
79 import 'universe/world_impact.dart' show ImpactStrategy, WorldImpact; 79 import 'universe/world_impact.dart' show ImpactStrategy, WorldImpact, WorldImpac tBuilderImpl;
80 import 'util/util.dart' show Link, Setlet; 80 import 'util/util.dart' show Link, Setlet;
81 import 'world.dart' show ClosedWorld, ClosedWorldRefiner, OpenWorld, WorldImpl; 81 import 'world.dart' show ClosedWorld, ClosedWorldRefiner, OpenWorld, WorldImpl;
82 82
83 typedef Backend MakeBackendFuncion(Compiler compiler); 83 typedef Backend MakeBackendFuncion(Compiler compiler);
84 84
85 typedef CompilerDiagnosticReporter MakeReporterFunction( 85 typedef CompilerDiagnosticReporter MakeReporterFunction(
86 Compiler compiler, CompilerOptions options); 86 Compiler compiler, CompilerOptions options);
87 87
88 abstract class Compiler implements LibraryLoaderListener { 88 abstract class Compiler implements LibraryLoaderListener {
89 Measurer get measurer; 89 Measurer get measurer;
(...skipping 17 matching lines...) Expand all
107 107
108 /** 108 /**
109 * Records global dependencies, that is, dependencies that don't 109 * Records global dependencies, that is, dependencies that don't
110 * correspond to a particular element. 110 * correspond to a particular element.
111 * 111 *
112 * We should get rid of this and ensure that all dependencies are 112 * We should get rid of this and ensure that all dependencies are
113 * associated with a particular element. 113 * associated with a particular element.
114 */ 114 */
115 GlobalDependencyRegistry globalDependencies; 115 GlobalDependencyRegistry globalDependencies;
116 116
117 /**
118 * Dependencies that are only included due to mirrors.
119 *
120 * We should get rid of this and ensure that all dependencies are
121 * associated with a particular element.
122 */
123 // TODO(johnniwinther): This should not be a [ResolutionRegistry].
124 final Registry mirrorDependencies =
125 new ResolutionRegistry(null, new TreeElementMapping(null));
126
127 /// Options provided from command-line arguments. 117 /// Options provided from command-line arguments.
128 final CompilerOptions options; 118 final CompilerOptions options;
129 119
130 /** 120 /**
131 * If true, stop compilation after type inference is complete. Used for 121 * If true, stop compilation after type inference is complete. Used for
132 * debugging and testing purposes only. 122 * debugging and testing purposes only.
133 */ 123 */
134 bool stopAfterTypeInference = false; 124 bool stopAfterTypeInference = false;
135 125
136 /// Output provider from user of Compiler API. 126 /// Output provider from user of Compiler API.
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 } 670 }
681 if (librariesToAnalyzeWhenRun != null) { 671 if (librariesToAnalyzeWhenRun != null) {
682 for (Uri libraryUri in librariesToAnalyzeWhenRun) { 672 for (Uri libraryUri in librariesToAnalyzeWhenRun) {
683 fullyEnqueueLibrary( 673 fullyEnqueueLibrary(
684 libraryLoader.lookupLibrary(libraryUri), enqueuer.resolution); 674 libraryLoader.lookupLibrary(libraryUri), enqueuer.resolution);
685 } 675 }
686 } 676 }
687 } 677 }
688 // Elements required by enqueueHelpers are global dependencies 678 // Elements required by enqueueHelpers are global dependencies
689 // that are not pulled in by a particular element. 679 // that are not pulled in by a particular element.
690 backend.enqueueHelpers(enqueuer.resolution, globalDependencies); 680 backend.enqueueHelpers(enqueuer.resolution);
691 resolveLibraryMetadata(); 681 resolveLibraryMetadata();
692 reporter.log('Resolving...'); 682 reporter.log('Resolving...');
693 processQueue(enqueuer.resolution, mainFunction); 683 processQueue(enqueuer.resolution, mainFunction);
694 enqueuer.resolution.logSummary(reporter.log); 684 enqueuer.resolution.logSummary(reporter.log);
695 685
696 _reporter.reportSuppressedMessagesSummary(); 686 _reporter.reportSuppressedMessagesSummary();
697 687
698 if (compilationFailed) { 688 if (compilationFailed) {
699 if (!options.generateCodeWithCompileTimeErrors) return; 689 if (!options.generateCodeWithCompileTimeErrors) return;
700 if (!backend 690 if (!backend
(...skipping 29 matching lines...) Expand all
730 reporter.log('Inferring types...'); 720 reporter.log('Inferring types...');
731 globalInference.runGlobalTypeInference(mainFunction); 721 globalInference.runGlobalTypeInference(mainFunction);
732 722
733 if (stopAfterTypeInference) return; 723 if (stopAfterTypeInference) return;
734 724
735 backend.onTypeInferenceComplete(); 725 backend.onTypeInferenceComplete();
736 726
737 reporter.log('Compiling...'); 727 reporter.log('Compiling...');
738 phase = PHASE_COMPILING; 728 phase = PHASE_COMPILING;
739 backend.onCodegenStart(); 729 backend.onCodegenStart();
740 // TODO(johnniwinther): Move these to [CodegenEnqueuer].
741 if (hasIsolateSupport) { 730 if (hasIsolateSupport) {
742 backend.enableIsolateSupport(enqueuer.codegen); 731 backend.enableIsolateSupport(enqueuer.codegen);
743 } 732 }
744 if (compileAll) { 733 if (compileAll) {
745 libraryLoader.libraries.forEach((LibraryElement library) { 734 libraryLoader.libraries.forEach((LibraryElement library) {
746 fullyEnqueueLibrary(library, enqueuer.codegen); 735 fullyEnqueueLibrary(library, enqueuer.codegen);
747 }); 736 });
748 } 737 }
749 processQueue(enqueuer.codegen, mainFunction); 738 processQueue(enqueuer.codegen, mainFunction);
750 enqueuer.codegen.logSummary(reporter.log); 739 enqueuer.codegen.logSummary(reporter.log);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 } 799 }
811 }); 800 });
812 } 801 }
813 } 802 }
814 803
815 void fullyEnqueueTopLevelElement(Element element, Enqueuer world) { 804 void fullyEnqueueTopLevelElement(Element element, Enqueuer world) {
816 if (element.isClass) { 805 if (element.isClass) {
817 ClassElement cls = element; 806 ClassElement cls = element;
818 cls.ensureResolved(resolution); 807 cls.ensureResolved(resolution);
819 cls.forEachLocalMember(enqueuer.resolution.addToWorkList); 808 cls.forEachLocalMember(enqueuer.resolution.addToWorkList);
820 backend.registerInstantiatedType(cls.rawType, world, globalDependencies); 809 world.registerInstantiatedType(cls.rawType);
821 } else { 810 } else {
822 world.addToWorkList(element); 811 world.addToWorkList(element);
823 } 812 }
824 } 813 }
825 814
826 // Resolves metadata on library elements. This is necessary in order to 815 // Resolves metadata on library elements. This is necessary in order to
827 // resolve metadata classes referenced only from metadata on library tags. 816 // resolve metadata classes referenced only from metadata on library tags.
828 // TODO(ahe): Figure out how to do this lazily. 817 // TODO(ahe): Figure out how to do this lazily.
829 void resolveLibraryMetadata() { 818 void resolveLibraryMetadata() {
830 for (LibraryElement library in libraryLoader.libraries) { 819 for (LibraryElement library in libraryLoader.libraries) {
(...skipping 15 matching lines...) Expand all
846 work.element, 835 work.element,
847 () => selfTask.measureSubtask("world.applyImpact", () { 836 () => selfTask.measureSubtask("world.applyImpact", () {
848 world.applyImpact( 837 world.applyImpact(
849 selfTask.measureSubtask( 838 selfTask.measureSubtask(
850 "work.run", () => work.run(this, world)), 839 "work.run", () => work.run(this, world)),
851 impactSource: work.element); 840 impactSource: work.element);
852 })); 841 }));
853 }); 842 });
854 }); 843 });
855 844
856 void processQueue(Enqueuer world, Element main) => 845 void processQueue(Enqueuer enqueuer, Element main) {
857 selfTask.measureSubtask("Compiler.processQueue", () { 846 selfTask.measureSubtask("Compiler.processQueue", () {
858 world.nativeEnqueuer.processNativeClasses(libraryLoader.libraries); 847 WorldImpactBuilderImpl nativeImpact = new WorldImpactBuilderImpl();
859 if (main != null && !main.isMalformed) { 848 enqueuer.nativeEnqueuer
860 FunctionElement mainMethod = main; 849 .processNativeClasses(nativeImpact, libraryLoader.libraries);
861 mainMethod.computeType(resolution); 850 enqueuer.applyImpact(nativeImpact);
862 if (mainMethod.functionSignature.parameterCount != 0) { 851 if (main != null && !main.isMalformed) {
863 // The first argument could be a list of strings. 852 FunctionElement mainMethod = main;
864 backend.backendClasses.listImplementation 853 mainMethod.computeType(resolution);
865 .ensureResolved(resolution); 854 if (mainMethod.functionSignature.parameterCount != 0) {
866 backend.registerInstantiatedType( 855 // The first argument could be a list of strings.
867 backend.backendClasses.listImplementation.rawType, 856 backend.backendClasses.listImplementation.ensureResolved(resolution);
868 world, 857 enqueuer.registerInstantiatedType(
869 globalDependencies); 858 backend.backendClasses.listImplementation.rawType);
870 backend.backendClasses.stringImplementation 859 backend.backendClasses.stringImplementation
871 .ensureResolved(resolution); 860 .ensureResolved(resolution);
872 backend.registerInstantiatedType( 861 enqueuer.registerInstantiatedType(
873 backend.backendClasses.stringImplementation.rawType, 862 backend.backendClasses.stringImplementation.rawType);
874 world,
875 globalDependencies);
876 863
877 backend.registerMainHasArguments(world); 864 backend.registerMainHasArguments(enqueuer);
878 }
879 world.addToWorkList(main);
880 } 865 }
881 if (options.verbose) { 866 enqueuer.addToWorkList(main);
882 progress.reset(); 867 }
883 } 868 if (options.verbose) {
884 emptyQueue(world); 869 progress.reset();
885 world.queueIsClosed = true; 870 }
886 // Notify the impact strategy impacts are no longer needed for this 871 emptyQueue(enqueuer);
887 // enqueuer. 872 enqueuer.queueIsClosed = true;
888 impactStrategy.onImpactUsed(world.impactUse); 873 // Notify the impact strategy impacts are no longer needed for this
889 backend.onQueueClosed(); 874 // enqueuer.
890 assert( 875 impactStrategy.onImpactUsed(enqueuer.impactUse);
891 compilationFailed || world.checkNoEnqueuedInvokedInstanceMethods()); 876 backend.onQueueClosed();
892 }); 877 assert(compilationFailed ||
878 enqueuer.checkNoEnqueuedInvokedInstanceMethods());
879 });
880 }
893 881
894 /** 882 /**
895 * Perform various checks of the queues. This includes checking that 883 * Perform various checks of the queues. This includes checking that
896 * the queues are empty (nothing was added after we stopped 884 * the queues are empty (nothing was added after we stopped
897 * processing the queues). Also compute the number of methods that 885 * processing the queues). Also compute the number of methods that
898 * were resolved, but not compiled (aka excess resolution). 886 * were resolved, but not compiled (aka excess resolution).
899 */ 887 */
900 checkQueues() { 888 checkQueues() {
901 for (Enqueuer world in [enqueuer.resolution, enqueuer.codegen]) { 889 for (Enqueuer world in [enqueuer.resolution, enqueuer.codegen]) {
902 world.forEach((WorkItem work) { 890 world.forEach((WorkItem work) {
(...skipping 1240 matching lines...) Expand 10 before | Expand all | Expand 10 after
2143 compiler.checker.check(element); 2131 compiler.checker.check(element);
2144 } 2132 }
2145 return transformResolutionImpact(element, resolutionImpact); 2133 return transformResolutionImpact(element, resolutionImpact);
2146 }); 2134 });
2147 } 2135 }
2148 2136
2149 @override 2137 @override
2150 WorldImpact transformResolutionImpact( 2138 WorldImpact transformResolutionImpact(
2151 Element element, ResolutionImpact resolutionImpact) { 2139 Element element, ResolutionImpact resolutionImpact) {
2152 WorldImpact worldImpact = compiler.backend.impactTransformer 2140 WorldImpact worldImpact = compiler.backend.impactTransformer
2153 .transformResolutionImpact(resolutionImpact); 2141 .transformResolutionImpact(compiler.enqueuer.resolution, resolutionImpac t);
Harry Terkelsen 2016/11/11 21:24:27 dartfmt
Johnni Winther 2016/11/14 09:08:36 Done.
2154 _worldImpactCache[element] = worldImpact; 2142 _worldImpactCache[element] = worldImpact;
2155 return worldImpact; 2143 return worldImpact;
2156 } 2144 }
2157 2145
2158 @override 2146 @override
2159 void uncacheWorldImpact(Element element) { 2147 void uncacheWorldImpact(Element element) {
2160 assert(invariant(element, element.isDeclaration, 2148 assert(invariant(element, element.isDeclaration,
2161 message: "Element $element must be the declaration.")); 2149 message: "Element $element must be the declaration."));
2162 if (retainCachesForTesting) return; 2150 if (retainCachesForTesting) return;
2163 if (compiler.serialization.isDeserialized(element)) return; 2151 if (compiler.serialization.isDeserialized(element)) return;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
2256 _ElementScanner(this.scanner); 2244 _ElementScanner(this.scanner);
2257 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); 2245 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library);
2258 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); 2246 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit);
2259 } 2247 }
2260 2248
2261 class _EmptyEnvironment implements Environment { 2249 class _EmptyEnvironment implements Environment {
2262 const _EmptyEnvironment(); 2250 const _EmptyEnvironment();
2263 2251
2264 String valueOf(String key) => null; 2252 String valueOf(String key) => null;
2265 } 2253 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698