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

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

Issue 2000323006: Make CompilerTask independent of compiler. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 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.enqueue; 5 library dart2js.enqueue;
6 6
7 import 'dart:collection' show Queue; 7 import 'dart:collection' show Queue;
8 8
9 import 'common/codegen.dart' show CodegenWorkItem; 9 import 'common/codegen.dart' show CodegenWorkItem;
10 import 'common/names.dart' show Identifiers; 10 import 'common/names.dart' show Identifiers;
11 import 'common/resolution.dart' show Resolution; 11 import 'common/resolution.dart' show Resolution;
12 import 'common/resolution.dart' show ResolutionWorkItem; 12 import 'common/resolution.dart' show ResolutionWorkItem;
13 import 'common/tasks.dart' show CompilerTask, DeferredAction, DeferredTask; 13 import 'common/tasks.dart' show CompilerTask;
14 import 'common/work.dart' show ItemCompilationContext, WorkItem; 14 import 'common/work.dart' show ItemCompilationContext, WorkItem;
15 import 'common.dart'; 15 import 'common.dart';
16 import 'compiler.dart' show Compiler; 16 import 'compiler.dart' show Compiler;
17 import 'dart_types.dart' show DartType, InterfaceType; 17 import 'dart_types.dart' show DartType, InterfaceType;
18 import 'elements/elements.dart' 18 import 'elements/elements.dart'
19 show 19 show
20 AnalyzableElement, 20 AnalyzableElement,
21 AstElement, 21 AstElement,
22 ClassElement, 22 ClassElement,
23 ConstructorElement, 23 ConstructorElement,
(...skipping 15 matching lines...) Expand all
39 show DynamicUse, StaticUse, StaticUseKind, TypeUse, TypeUseKind; 39 show DynamicUse, StaticUse, StaticUseKind, TypeUse, TypeUseKind;
40 import 'universe/world_impact.dart' 40 import 'universe/world_impact.dart'
41 show ImpactUseCase, WorldImpact, WorldImpactVisitor; 41 show ImpactUseCase, WorldImpact, WorldImpactVisitor;
42 import 'util/util.dart' show Setlet; 42 import 'util/util.dart' show Setlet;
43 43
44 typedef ItemCompilationContext ItemCompilationContextCreator(); 44 typedef ItemCompilationContext ItemCompilationContextCreator();
45 45
46 class EnqueueTask extends CompilerTask { 46 class EnqueueTask extends CompilerTask {
47 final ResolutionEnqueuer resolution; 47 final ResolutionEnqueuer resolution;
48 final CodegenEnqueuer codegen; 48 final CodegenEnqueuer codegen;
49 final Compiler compiler;
49 50
50 String get name => 'Enqueue'; 51 String get name => 'Enqueue';
51 52
52 EnqueueTask(Compiler compiler) 53 EnqueueTask(Compiler compiler)
53 : resolution = new ResolutionEnqueuer( 54 : compiler = compiler,
55 resolution = new ResolutionEnqueuer(
54 compiler, 56 compiler,
55 compiler.backend.createItemCompilationContext, 57 compiler.backend.createItemCompilationContext,
56 compiler.options.analyzeOnly && compiler.options.analyzeMain 58 compiler.options.analyzeOnly && compiler.options.analyzeMain
57 ? const EnqueuerStrategy() 59 ? const EnqueuerStrategy()
58 : const TreeShakingEnqueuerStrategy()), 60 : const TreeShakingEnqueuerStrategy()),
59 codegen = new CodegenEnqueuer( 61 codegen = new CodegenEnqueuer(
60 compiler, 62 compiler,
61 compiler.backend.createItemCompilationContext, 63 compiler.backend.createItemCompilationContext,
62 const TreeShakingEnqueuerStrategy()), 64 const TreeShakingEnqueuerStrategy()),
63 super(compiler) { 65 super(compiler.measurer) {
64 codegen.task = this; 66 codegen.task = this;
65 resolution.task = this; 67 resolution.task = this;
66 68
67 codegen.nativeEnqueuer = compiler.backend.nativeCodegenEnqueuer(codegen); 69 codegen.nativeEnqueuer = compiler.backend.nativeCodegenEnqueuer(codegen);
68 resolution.nativeEnqueuer = 70 resolution.nativeEnqueuer =
69 compiler.backend.nativeResolutionEnqueuer(resolution); 71 compiler.backend.nativeResolutionEnqueuer(resolution);
70 } 72 }
71 73
72 void forgetElement(Element element) { 74 void forgetElement(Element element) {
73 resolution.forgetElement(element); 75 resolution.forgetElement(element);
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 } 709 }
708 } 710 }
709 711
710 /// [Enqueuer] which is specific to resolution. 712 /// [Enqueuer] which is specific to resolution.
711 class ResolutionEnqueuer extends Enqueuer { 713 class ResolutionEnqueuer extends Enqueuer {
712 /// All declaration elements that have been processed by the resolver. 714 /// All declaration elements that have been processed by the resolver.
713 final Set<AstElement> processedElements; 715 final Set<AstElement> processedElements;
714 716
715 final Queue<ResolutionWorkItem> queue; 717 final Queue<ResolutionWorkItem> queue;
716 718
717 /** 719 /// Queue of deferred resolution actions to execute when the resolution queue
718 * A deferred task queue for the resolution phase which is processed 720 /// has been emptied.
719 * when the resolution queue has been emptied. 721 final Queue<_DeferredAction> deferredQueue;
720 */
721 final Queue<DeferredTask> deferredTaskQueue;
722 722
723 static const ImpactUseCase IMPACT_USE = 723 static const ImpactUseCase IMPACT_USE =
724 const ImpactUseCase('ResolutionEnqueuer'); 724 const ImpactUseCase('ResolutionEnqueuer');
725 725
726 ImpactUseCase get impactUse => IMPACT_USE; 726 ImpactUseCase get impactUse => IMPACT_USE;
727 727
728 ResolutionEnqueuer( 728 ResolutionEnqueuer(
729 Compiler compiler, 729 Compiler compiler,
730 ItemCompilationContext itemCompilationContextCreator(), 730 ItemCompilationContext itemCompilationContextCreator(),
731 EnqueuerStrategy strategy) 731 EnqueuerStrategy strategy)
732 : super('resolution enqueuer', compiler, itemCompilationContextCreator, 732 : super('resolution enqueuer', compiler, itemCompilationContextCreator,
733 strategy), 733 strategy),
734 processedElements = new Set<AstElement>(), 734 processedElements = new Set<AstElement>(),
735 queue = new Queue<ResolutionWorkItem>(), 735 queue = new Queue<ResolutionWorkItem>(),
736 deferredTaskQueue = new Queue<DeferredTask>(); 736 deferredQueue = new Queue<_DeferredAction>();
737 737
738 bool get isResolutionQueue => true; 738 bool get isResolutionQueue => true;
739 739
740 bool isProcessed(Element member) => processedElements.contains(member); 740 bool isProcessed(Element member) => processedElements.contains(member);
741 741
742 /// Returns `true` if [element] has been processed by the resolution enqueuer. 742 /// Returns `true` if [element] has been processed by the resolution enqueuer.
743 bool hasBeenProcessed(Element element) { 743 bool hasBeenProcessed(Element element) {
744 return processedElements.contains(element.analyzableElement.declaration); 744 return processedElements.contains(element.analyzableElement.declaration);
745 } 745 }
746 746
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 } 824 }
825 825
826 /** 826 /**
827 * Adds an action to the deferred task queue. 827 * Adds an action to the deferred task queue.
828 * 828 *
829 * The action is performed the next time the resolution queue has been 829 * The action is performed the next time the resolution queue has been
830 * emptied. 830 * emptied.
831 * 831 *
832 * The queue is processed in FIFO order. 832 * The queue is processed in FIFO order.
833 */ 833 */
834 void addDeferredAction(Element element, DeferredAction action) { 834 void addDeferredAction(Element element, void action()) {
835 if (queueIsClosed) { 835 if (queueIsClosed) {
836 throw new SpannableAssertionFailure( 836 throw new SpannableAssertionFailure(
837 element, 837 element,
838 "Resolution work list is closed. " 838 "Resolution work list is closed. "
839 "Trying to add deferred action for $element"); 839 "Trying to add deferred action for $element");
840 } 840 }
841 deferredTaskQueue.add(new DeferredTask(element, action)); 841 deferredQueue.add(new _DeferredAction(element, action));
842 } 842 }
843 843
844 bool onQueueEmpty(Iterable<ClassElement> recentClasses) { 844 bool onQueueEmpty(Iterable<ClassElement> recentClasses) {
845 emptyDeferredTaskQueue(); 845 _emptyDeferredQueue();
846 return super.onQueueEmpty(recentClasses); 846 return super.onQueueEmpty(recentClasses);
847 } 847 }
848 848
849 void emptyDeferredTaskQueue() { 849 void emptyDeferredQueueForTesting() => _emptyDeferredQueue();
850 while (!deferredTaskQueue.isEmpty) { 850
851 DeferredTask task = deferredTaskQueue.removeFirst(); 851 void _emptyDeferredQueue() {
852 while (!deferredQueue.isEmpty) {
853 _DeferredAction task = deferredQueue.removeFirst();
852 reporter.withCurrentElement(task.element, task.action); 854 reporter.withCurrentElement(task.element, task.action);
853 } 855 }
854 } 856 }
855 857
856 void _logSpecificSummary(log(message)) { 858 void _logSpecificSummary(log(message)) {
857 log('Resolved ${processedElements.length} elements.'); 859 log('Resolved ${processedElements.length} elements.');
858 } 860 }
859 861
860 void forgetElement(Element element) { 862 void forgetElement(Element element) {
861 super.forgetElement(element); 863 super.forgetElement(element);
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 @override 1039 @override
1038 void visitStaticUse(StaticUse staticUse) { 1040 void visitStaticUse(StaticUse staticUse) {
1039 enqueuer.registerStaticUse(staticUse); 1041 enqueuer.registerStaticUse(staticUse);
1040 } 1042 }
1041 1043
1042 @override 1044 @override
1043 void visitTypeUse(TypeUse typeUse) { 1045 void visitTypeUse(TypeUse typeUse) {
1044 enqueuer.registerTypeUse(typeUse); 1046 enqueuer.registerTypeUse(typeUse);
1045 } 1047 }
1046 } 1048 }
1049
1050 typedef void _DeferredActionFunction();
1051
1052 class _DeferredAction {
1053 final Element element;
1054 final _DeferredActionFunction action;
1055
1056 _DeferredAction(this.element, this.action);
1057 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698