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