| 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 part of dart2js; | 5 part of dart2js; |
| 6 | 6 |
| 7 typedef ItemCompilationContext ItemCompilationContextCreator(); | 7 typedef ItemCompilationContext ItemCompilationContextCreator(); |
| 8 | 8 |
| 9 class EnqueueTask extends CompilerTask { | 9 class EnqueueTask extends CompilerTask { |
| 10 final ResolutionEnqueuer resolution; | 10 final ResolutionEnqueuer resolution; |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 // All field initializers must be resolved as they could | 155 // All field initializers must be resolved as they could |
| 156 // have an observable side-effect (and cannot be tree-shaken | 156 // have an observable side-effect (and cannot be tree-shaken |
| 157 // away). | 157 // away). |
| 158 addToWorkList(member); | 158 addToWorkList(member); |
| 159 return; | 159 return; |
| 160 } | 160 } |
| 161 } else if (member.kind == ElementKind.FUNCTION) { | 161 } else if (member.kind == ElementKind.FUNCTION) { |
| 162 FunctionElement function = member; | 162 FunctionElement function = member; |
| 163 function.computeSignature(compiler); | 163 function.computeSignature(compiler); |
| 164 if (function.name == Compiler.NO_SUCH_METHOD) { | 164 if (function.name == Compiler.NO_SUCH_METHOD) { |
| 165 enableNoSuchMethod(function); | 165 registerNoSuchMethod(function); |
| 166 } | 166 } |
| 167 if (function.name == Compiler.CALL_OPERATOR_NAME && | 167 if (function.name == Compiler.CALL_OPERATOR_NAME && |
| 168 !cls.typeVariables.isEmpty) { | 168 !cls.typeVariables.isEmpty) { |
| 169 registerCallMethodWithFreeTypeVariables( | 169 registerCallMethodWithFreeTypeVariables( |
| 170 function, compiler.globalDependencies); | 170 function, compiler.globalDependencies); |
| 171 } | 171 } |
| 172 // If there is a property access with the same name as a method we | 172 // If there is a property access with the same name as a method we |
| 173 // need to emit the method. | 173 // need to emit the method. |
| 174 if (universe.hasInvokedGetter(function, compiler.world)) { | 174 if (universe.hasInvokedGetter(function, compiler.world)) { |
| 175 registerClosurizedMember(function, compiler.globalDependencies); | 175 registerClosurizedMember(function, compiler.globalDependencies); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 205 return; | 205 return; |
| 206 } | 206 } |
| 207 } | 207 } |
| 208 | 208 |
| 209 // The element is not yet used. Add it to the list of instance | 209 // The element is not yet used. Add it to the list of instance |
| 210 // members to still be processed. | 210 // members to still be processed. |
| 211 instanceMembersByName.putIfAbsent(memberName, () => new Set<Element>()) | 211 instanceMembersByName.putIfAbsent(memberName, () => new Set<Element>()) |
| 212 .add(member); | 212 .add(member); |
| 213 } | 213 } |
| 214 | 214 |
| 215 void enableNoSuchMethod(Element element) {} | 215 void registerNoSuchMethod(Element noSuchMethod); |
| 216 |
| 216 void enableIsolateSupport() {} | 217 void enableIsolateSupport() {} |
| 217 | 218 |
| 218 void processInstantiatedClass(ClassElement cls) { | 219 void processInstantiatedClass(ClassElement cls) { |
| 219 task.measure(() { | 220 task.measure(() { |
| 220 if (_processedClasses.contains(cls)) return; | 221 if (_processedClasses.contains(cls)) return; |
| 221 // The class must be resolved to compute the set of all | 222 // The class must be resolved to compute the set of all |
| 222 // supertypes. | 223 // supertypes. |
| 223 cls.ensureResolved(compiler); | 224 cls.ensureResolved(compiler); |
| 224 | 225 |
| 225 void processClass(ClassElement cls) { | 226 void processClass(ClassElement cls) { |
| (...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 729 // TODO(ahe): Record precise dependency here. | 730 // TODO(ahe): Record precise dependency here. |
| 730 compiler.backend.registerRuntimeType(this, compiler.globalDependencies); | 731 compiler.backend.registerRuntimeType(this, compiler.globalDependencies); |
| 731 } else if (element == compiler.functionApplyMethod) { | 732 } else if (element == compiler.functionApplyMethod) { |
| 732 compiler.enabledFunctionApply = true; | 733 compiler.enabledFunctionApply = true; |
| 733 } | 734 } |
| 734 | 735 |
| 735 nativeEnqueuer.registerElement(element); | 736 nativeEnqueuer.registerElement(element); |
| 736 return true; | 737 return true; |
| 737 } | 738 } |
| 738 | 739 |
| 740 void registerNoSuchMethod(Element element) { |
| 741 compiler.backend.registerNoSuchMethod(element); |
| 742 } |
| 743 |
| 739 void enableIsolateSupport() { | 744 void enableIsolateSupport() { |
| 740 compiler.hasIsolateSupport = true; | 745 compiler.hasIsolateSupport = true; |
| 741 compiler.backend.enableIsolateSupport(this); | 746 compiler.backend.enableIsolateSupport(this); |
| 742 } | 747 } |
| 743 | 748 |
| 744 void enableNoSuchMethod(Element element) { | |
| 745 if (compiler.enabledNoSuchMethod) return; | |
| 746 if (compiler.backend.isDefaultNoSuchMethodImplementation(element)) return; | |
| 747 | |
| 748 compiler.enabledNoSuchMethod = true; | |
| 749 compiler.backend.enableNoSuchMethod(element, this); | |
| 750 } | |
| 751 | |
| 752 /** | 749 /** |
| 753 * Adds an action to the deferred task queue. | 750 * Adds an action to the deferred task queue. |
| 754 * | 751 * |
| 755 * The action is performed the next time the resolution queue has been | 752 * The action is performed the next time the resolution queue has been |
| 756 * emptied. | 753 * emptied. |
| 757 * | 754 * |
| 758 * The queue is processed in FIFO order. | 755 * The queue is processed in FIFO order. |
| 759 */ | 756 */ |
| 760 void addDeferredAction(Element element, DeferredAction action) { | 757 void addDeferredAction(Element element, DeferredAction action) { |
| 761 if (queueIsClosed) { | 758 if (queueIsClosed) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 799 /// [Enqueuer] which is specific to code generation. | 796 /// [Enqueuer] which is specific to code generation. |
| 800 class CodegenEnqueuer extends Enqueuer { | 797 class CodegenEnqueuer extends Enqueuer { |
| 801 final Queue<CodegenWorkItem> queue; | 798 final Queue<CodegenWorkItem> queue; |
| 802 final Map<Element, js.Expression> generatedCode = | 799 final Map<Element, js.Expression> generatedCode = |
| 803 new Map<Element, js.Expression>(); | 800 new Map<Element, js.Expression>(); |
| 804 | 801 |
| 805 final Set<Element> newlyEnqueuedElements; | 802 final Set<Element> newlyEnqueuedElements; |
| 806 | 803 |
| 807 final Set<Selector> newlySeenSelectors; | 804 final Set<Selector> newlySeenSelectors; |
| 808 | 805 |
| 806 bool enabledNoSuchMethod = false; |
| 807 |
| 809 CodegenEnqueuer(Compiler compiler, | 808 CodegenEnqueuer(Compiler compiler, |
| 810 ItemCompilationContext itemCompilationContextCreator()) | 809 ItemCompilationContext itemCompilationContextCreator()) |
| 811 : queue = new Queue<CodegenWorkItem>(), | 810 : queue = new Queue<CodegenWorkItem>(), |
| 812 newlyEnqueuedElements = compiler.cacheStrategy.newSet(), | 811 newlyEnqueuedElements = compiler.cacheStrategy.newSet(), |
| 813 newlySeenSelectors = compiler.cacheStrategy.newSet(), | 812 newlySeenSelectors = compiler.cacheStrategy.newSet(), |
| 814 super('codegen enqueuer', compiler, itemCompilationContextCreator); | 813 super('codegen enqueuer', compiler, itemCompilationContextCreator); |
| 815 | 814 |
| 816 bool isProcessed(Element member) => | 815 bool isProcessed(Element member) => |
| 817 member.isAbstract || generatedCode.containsKey(member); | 816 member.isAbstract || generatedCode.containsKey(member); |
| 818 | 817 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 848 if (queueIsClosed) { | 847 if (queueIsClosed) { |
| 849 throw new SpannableAssertionFailure(element, | 848 throw new SpannableAssertionFailure(element, |
| 850 "Codegen work list is closed. Trying to add $element"); | 849 "Codegen work list is closed. Trying to add $element"); |
| 851 } | 850 } |
| 852 CodegenWorkItem workItem = new CodegenWorkItem( | 851 CodegenWorkItem workItem = new CodegenWorkItem( |
| 853 element, itemCompilationContextCreator()); | 852 element, itemCompilationContextCreator()); |
| 854 queue.add(workItem); | 853 queue.add(workItem); |
| 855 return true; | 854 return true; |
| 856 } | 855 } |
| 857 | 856 |
| 857 void registerNoSuchMethod(Element element) { |
| 858 if (!enabledNoSuchMethod && compiler.backend.enabledNoSuchMethod) { |
| 859 compiler.backend.enableNoSuchMethod(this); |
| 860 enabledNoSuchMethod = true; |
| 861 } |
| 862 } |
| 863 |
| 858 void _logSpecificSummary(log(message)) { | 864 void _logSpecificSummary(log(message)) { |
| 859 log('Compiled ${generatedCode.length} methods.'); | 865 log('Compiled ${generatedCode.length} methods.'); |
| 860 } | 866 } |
| 861 | 867 |
| 862 void forgetElement(Element element) { | 868 void forgetElement(Element element) { |
| 863 super.forgetElement(element); | 869 super.forgetElement(element); |
| 864 generatedCode.remove(element); | 870 generatedCode.remove(element); |
| 865 if (element is MemberElement) { | 871 if (element is MemberElement) { |
| 866 for (Element closure in element.nestedClosures) { | 872 for (Element closure in element.nestedClosures) { |
| 867 generatedCode.remove(closure); | 873 generatedCode.remove(closure); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 899 void processWorkItem(void f(WorkItem work), WorkItem work) { | 905 void processWorkItem(void f(WorkItem work), WorkItem work) { |
| 900 f(work); | 906 f(work); |
| 901 } | 907 } |
| 902 } | 908 } |
| 903 | 909 |
| 904 void removeFromSet(Map<String, Set<Element>> map, Element element) { | 910 void removeFromSet(Map<String, Set<Element>> map, Element element) { |
| 905 Set<Element> set = map[element.name]; | 911 Set<Element> set = map[element.name]; |
| 906 if (set == null) return; | 912 if (set == null) return; |
| 907 set.remove(element); | 913 set.remove(element); |
| 908 } | 914 } |
| OLD | NEW |