| 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.enqueue; | 5 library dart2js.enqueue; |
| 6 | 6 |
| 7 import 'dart:collection' show | 7 import 'dart:collection' show |
| 8 Queue; | 8 Queue; |
| 9 | 9 |
| 10 import 'common.dart'; | 10 import 'common.dart'; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 import 'universe/selector.dart' show | 51 import 'universe/selector.dart' show |
| 52 Selector; | 52 Selector; |
| 53 import 'universe/universe.dart'; | 53 import 'universe/universe.dart'; |
| 54 import 'universe/use.dart' show | 54 import 'universe/use.dart' show |
| 55 DynamicUse, | 55 DynamicUse, |
| 56 StaticUse, | 56 StaticUse, |
| 57 StaticUseKind, | 57 StaticUseKind, |
| 58 TypeUse, | 58 TypeUse, |
| 59 TypeUseKind; | 59 TypeUseKind; |
| 60 import 'universe/world_impact.dart' show | 60 import 'universe/world_impact.dart' show |
| 61 ImpactUseCase, | 61 WorldImpact; |
| 62 WorldImpact, | |
| 63 WorldImpactVisitor; | |
| 64 import 'util/util.dart' show | 62 import 'util/util.dart' show |
| 65 Link, | 63 Link, |
| 66 Setlet; | 64 Setlet; |
| 67 | 65 |
| 68 typedef ItemCompilationContext ItemCompilationContextCreator(); | 66 typedef ItemCompilationContext ItemCompilationContextCreator(); |
| 69 | 67 |
| 70 class EnqueueTask extends CompilerTask { | 68 class EnqueueTask extends CompilerTask { |
| 71 final ResolutionEnqueuer resolution; | 69 final ResolutionEnqueuer resolution; |
| 72 final CodegenEnqueuer codegen; | 70 final CodegenEnqueuer codegen; |
| 73 | 71 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 static final TRACE_MIRROR_ENQUEUING = | 110 static final TRACE_MIRROR_ENQUEUING = |
| 113 const bool.fromEnvironment("TRACE_MIRROR_ENQUEUING"); | 111 const bool.fromEnvironment("TRACE_MIRROR_ENQUEUING"); |
| 114 | 112 |
| 115 bool queueIsClosed = false; | 113 bool queueIsClosed = false; |
| 116 EnqueueTask task; | 114 EnqueueTask task; |
| 117 native.NativeEnqueuer nativeEnqueuer; // Set by EnqueueTask | 115 native.NativeEnqueuer nativeEnqueuer; // Set by EnqueueTask |
| 118 | 116 |
| 119 bool hasEnqueuedReflectiveElements = false; | 117 bool hasEnqueuedReflectiveElements = false; |
| 120 bool hasEnqueuedReflectiveStaticFields = false; | 118 bool hasEnqueuedReflectiveStaticFields = false; |
| 121 | 119 |
| 122 WorldImpactVisitor impactVisitor; | |
| 123 | |
| 124 Enqueuer(this.name, | 120 Enqueuer(this.name, |
| 125 this.compiler, | 121 this.compiler, |
| 126 this.itemCompilationContextCreator, | 122 this.itemCompilationContextCreator, |
| 127 this.strategy) { | 123 this.strategy); |
| 128 impactVisitor = new _EnqueuerImpactVisitor(this); | |
| 129 } | |
| 130 | 124 |
| 131 // TODO(johnniwinther): Move this to [ResolutionEnqueuer]. | 125 // TODO(johnniwinther): Move this to [ResolutionEnqueuer]. |
| 132 Resolution get resolution => compiler.resolution; | 126 Resolution get resolution => compiler.resolution; |
| 133 | 127 |
| 134 Queue<WorkItem> get queue; | 128 Queue<WorkItem> get queue; |
| 135 bool get queueIsEmpty => queue.isEmpty; | 129 bool get queueIsEmpty => queue.isEmpty; |
| 136 | 130 |
| 137 /// Returns [:true:] if this enqueuer is the resolution enqueuer. | 131 /// Returns [:true:] if this enqueuer is the resolution enqueuer. |
| 138 bool get isResolutionQueue => false; | 132 bool get isResolutionQueue => false; |
| 139 | 133 |
| 140 QueueFilter get filter => compiler.enqueuerFilter; | 134 QueueFilter get filter => compiler.enqueuerFilter; |
| 141 | 135 |
| 142 DiagnosticReporter get reporter => compiler.reporter; | 136 DiagnosticReporter get reporter => compiler.reporter; |
| 143 | 137 |
| 144 /// Returns [:true:] if [member] has been processed by this enqueuer. | 138 /// Returns [:true:] if [member] has been processed by this enqueuer. |
| 145 bool isProcessed(Element member); | 139 bool isProcessed(Element member); |
| 146 | 140 |
| 147 bool isClassProcessed(ClassElement cls) => _processedClasses.contains(cls); | 141 bool isClassProcessed(ClassElement cls) => _processedClasses.contains(cls); |
| 148 | 142 |
| 149 Iterable<ClassElement> get processedClasses => _processedClasses; | 143 Iterable<ClassElement> get processedClasses => _processedClasses; |
| 150 | 144 |
| 151 ImpactUseCase get impactUse; | |
| 152 | |
| 153 /** | 145 /** |
| 154 * Documentation wanted -- johnniwinther | 146 * Documentation wanted -- johnniwinther |
| 155 * | 147 * |
| 156 * Invariant: [element] must be a declaration element. | 148 * Invariant: [element] must be a declaration element. |
| 157 */ | 149 */ |
| 158 void addToWorkList(Element element) { | 150 void addToWorkList(Element element) { |
| 159 assert(invariant(element, element.isDeclaration)); | 151 assert(invariant(element, element.isDeclaration)); |
| 160 if (internalAddToWorkList(element) && compiler.dumpInfo) { | 152 if (internalAddToWorkList(element) && compiler.dumpInfo) { |
| 161 // TODO(sigmund): add other missing dependencies (internals, selectors | 153 // TODO(sigmund): add other missing dependencies (internals, selectors |
| 162 // enqueued after allocations), also enable only for the codegen enqueuer. | 154 // enqueued after allocations), also enable only for the codegen enqueuer. |
| 163 compiler.dumpInfoTask.registerDependency( | 155 compiler.dumpInfoTask.registerDependency( |
| 164 compiler.currentElement, element); | 156 compiler.currentElement, element); |
| 165 } | 157 } |
| 166 } | 158 } |
| 167 | 159 |
| 168 /** | 160 /** |
| 169 * Adds [element] to the work list if it has not already been processed. | 161 * Adds [element] to the work list if it has not already been processed. |
| 170 * | 162 * |
| 171 * Returns [true] if the element was actually added to the queue. | 163 * Returns [true] if the element was actually added to the queue. |
| 172 */ | 164 */ |
| 173 bool internalAddToWorkList(Element element); | 165 bool internalAddToWorkList(Element element); |
| 174 | 166 |
| 175 /// Apply the [worldImpact] of processing [element] to this enqueuer. | 167 /// Apply the [worldImpact] of processing [element] to this enqueuer. |
| 176 void applyImpact(Element element, WorldImpact worldImpact) { | 168 void applyImpact(Element element, WorldImpact worldImpact) { |
| 177 compiler.impactStrategy.visitImpact( | 169 // TODO(johnniwinther): Optimize the application of the world impact. |
| 178 element, worldImpact, impactVisitor, impactUse); | 170 worldImpact.dynamicUses.forEach(registerDynamicUse); |
| 171 worldImpact.staticUses.forEach(registerStaticUse); |
| 172 worldImpact.typeUses.forEach(registerTypeUse); |
| 179 } | 173 } |
| 180 | 174 |
| 181 void registerInstantiatedType(InterfaceType type, | 175 void registerInstantiatedType(InterfaceType type, |
| 182 {bool mirrorUsage: false}) { | 176 {bool mirrorUsage: false}) { |
| 183 task.measure(() { | 177 task.measure(() { |
| 184 ClassElement cls = type.element; | 178 ClassElement cls = type.element; |
| 185 cls.ensureResolved(resolution); | 179 cls.ensureResolved(resolution); |
| 186 bool isNative = compiler.backend.isNative(cls); | 180 bool isNative = compiler.backend.isNative(cls); |
| 187 universe.registerTypeInstantiation( | 181 universe.registerTypeInstantiation( |
| 188 type, | 182 type, |
| (...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 740 final Set<AstElement> processedElements; | 734 final Set<AstElement> processedElements; |
| 741 | 735 |
| 742 final Queue<ResolutionWorkItem> queue; | 736 final Queue<ResolutionWorkItem> queue; |
| 743 | 737 |
| 744 /** | 738 /** |
| 745 * A deferred task queue for the resolution phase which is processed | 739 * A deferred task queue for the resolution phase which is processed |
| 746 * when the resolution queue has been emptied. | 740 * when the resolution queue has been emptied. |
| 747 */ | 741 */ |
| 748 final Queue<DeferredTask> deferredTaskQueue; | 742 final Queue<DeferredTask> deferredTaskQueue; |
| 749 | 743 |
| 750 static const ImpactUseCase IMPACT_USE = const ImpactUseCase('ResolutionEnqueue
r'); | |
| 751 | |
| 752 ImpactUseCase get impactUse => IMPACT_USE; | |
| 753 | |
| 754 ResolutionEnqueuer(Compiler compiler, | 744 ResolutionEnqueuer(Compiler compiler, |
| 755 ItemCompilationContext itemCompilationContextCreator(), | 745 ItemCompilationContext itemCompilationContextCreator(), |
| 756 EnqueuerStrategy strategy) | 746 EnqueuerStrategy strategy) |
| 757 : super('resolution enqueuer', | 747 : super('resolution enqueuer', |
| 758 compiler, | 748 compiler, |
| 759 itemCompilationContextCreator, | 749 itemCompilationContextCreator, |
| 760 strategy), | 750 strategy), |
| 761 processedElements = new Set<AstElement>(), | 751 processedElements = new Set<AstElement>(), |
| 762 queue = new Queue<ResolutionWorkItem>(), | 752 queue = new Queue<ResolutionWorkItem>(), |
| 763 deferredTaskQueue = new Queue<DeferredTask>(); | 753 deferredTaskQueue = new Queue<DeferredTask>(); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 899 class CodegenEnqueuer extends Enqueuer { | 889 class CodegenEnqueuer extends Enqueuer { |
| 900 final Queue<CodegenWorkItem> queue; | 890 final Queue<CodegenWorkItem> queue; |
| 901 final Map<Element, js.Expression> generatedCode = <Element, js.Expression>{}; | 891 final Map<Element, js.Expression> generatedCode = <Element, js.Expression>{}; |
| 902 | 892 |
| 903 final Set<Element> newlyEnqueuedElements; | 893 final Set<Element> newlyEnqueuedElements; |
| 904 | 894 |
| 905 final Set<DynamicUse> newlySeenSelectors; | 895 final Set<DynamicUse> newlySeenSelectors; |
| 906 | 896 |
| 907 bool enabledNoSuchMethod = false; | 897 bool enabledNoSuchMethod = false; |
| 908 | 898 |
| 909 static const ImpactUseCase IMPACT_USE = const ImpactUseCase('CodegenEnqueuer')
; | |
| 910 | |
| 911 ImpactUseCase get impactUse => IMPACT_USE; | |
| 912 | |
| 913 CodegenEnqueuer(Compiler compiler, | 899 CodegenEnqueuer(Compiler compiler, |
| 914 ItemCompilationContext itemCompilationContextCreator(), | 900 ItemCompilationContext itemCompilationContextCreator(), |
| 915 EnqueuerStrategy strategy) | 901 EnqueuerStrategy strategy) |
| 916 : queue = new Queue<CodegenWorkItem>(), | 902 : queue = new Queue<CodegenWorkItem>(), |
| 917 newlyEnqueuedElements = compiler.cacheStrategy.newSet(), | 903 newlyEnqueuedElements = compiler.cacheStrategy.newSet(), |
| 918 newlySeenSelectors = compiler.cacheStrategy.newSet(), | 904 newlySeenSelectors = compiler.cacheStrategy.newSet(), |
| 919 super('codegen enqueuer', compiler, itemCompilationContextCreator, | 905 super('codegen enqueuer', compiler, itemCompilationContextCreator, |
| 920 strategy); | 906 strategy); |
| 921 | 907 |
| 922 bool isProcessed(Element member) => | 908 bool isProcessed(Element member) => |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1046 @override | 1032 @override |
| 1047 void processStaticUse(Enqueuer enqueuer, StaticUse staticUse) { | 1033 void processStaticUse(Enqueuer enqueuer, StaticUse staticUse) { |
| 1048 enqueuer.registerStaticUseInternal(staticUse); | 1034 enqueuer.registerStaticUseInternal(staticUse); |
| 1049 } | 1035 } |
| 1050 | 1036 |
| 1051 @override | 1037 @override |
| 1052 void processDynamicUse(Enqueuer enqueuer, DynamicUse dynamicUse) { | 1038 void processDynamicUse(Enqueuer enqueuer, DynamicUse dynamicUse) { |
| 1053 enqueuer.handleUnseenSelectorInternal(dynamicUse); | 1039 enqueuer.handleUnseenSelectorInternal(dynamicUse); |
| 1054 } | 1040 } |
| 1055 } | 1041 } |
| 1056 | |
| 1057 class _EnqueuerImpactVisitor implements WorldImpactVisitor { | |
| 1058 final Enqueuer enqueuer; | |
| 1059 | |
| 1060 _EnqueuerImpactVisitor(this.enqueuer); | |
| 1061 | |
| 1062 @override | |
| 1063 void visitDynamicUse(DynamicUse dynamicUse) { | |
| 1064 enqueuer.registerDynamicUse(dynamicUse); | |
| 1065 } | |
| 1066 | |
| 1067 @override | |
| 1068 void visitStaticUse(StaticUse staticUse) { | |
| 1069 enqueuer.registerStaticUse(staticUse); | |
| 1070 } | |
| 1071 | |
| 1072 @override | |
| 1073 void visitTypeUse(TypeUse typeUse) { | |
| 1074 enqueuer.registerTypeUse(typeUse); | |
| 1075 } | |
| 1076 } | |
| OLD | NEW |