| 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 registerNoSuchMethod(function); | 165 enableNoSuchMethod(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 registerNoSuchMethod(Element noSuchMethod); | 215 void enableNoSuchMethod(Element element) {} |
| 216 | |
| 217 void enableIsolateSupport() {} | 216 void enableIsolateSupport() {} |
| 218 | 217 |
| 219 void processInstantiatedClass(ClassElement cls) { | 218 void processInstantiatedClass(ClassElement cls) { |
| 220 task.measure(() { | 219 task.measure(() { |
| 221 if (_processedClasses.contains(cls)) return; | 220 if (_processedClasses.contains(cls)) return; |
| 222 // The class must be resolved to compute the set of all | 221 // The class must be resolved to compute the set of all |
| 223 // supertypes. | 222 // supertypes. |
| 224 cls.ensureResolved(compiler); | 223 cls.ensureResolved(compiler); |
| 225 | 224 |
| 226 void processClass(ClassElement cls) { | 225 void processClass(ClassElement cls) { |
| (...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 // TODO(ahe): Record precise dependency here. | 729 // TODO(ahe): Record precise dependency here. |
| 731 compiler.backend.registerRuntimeType(this, compiler.globalDependencies); | 730 compiler.backend.registerRuntimeType(this, compiler.globalDependencies); |
| 732 } else if (element == compiler.functionApplyMethod) { | 731 } else if (element == compiler.functionApplyMethod) { |
| 733 compiler.enabledFunctionApply = true; | 732 compiler.enabledFunctionApply = true; |
| 734 } | 733 } |
| 735 | 734 |
| 736 nativeEnqueuer.registerElement(element); | 735 nativeEnqueuer.registerElement(element); |
| 737 return true; | 736 return true; |
| 738 } | 737 } |
| 739 | 738 |
| 740 void registerNoSuchMethod(Element element) { | |
| 741 compiler.backend.registerNoSuchMethod(element); | |
| 742 } | |
| 743 | |
| 744 void enableIsolateSupport() { | 739 void enableIsolateSupport() { |
| 745 compiler.hasIsolateSupport = true; | 740 compiler.hasIsolateSupport = true; |
| 746 compiler.backend.enableIsolateSupport(this); | 741 compiler.backend.enableIsolateSupport(this); |
| 747 } | 742 } |
| 748 | 743 |
| 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 |
| 749 /** | 752 /** |
| 750 * Adds an action to the deferred task queue. | 753 * Adds an action to the deferred task queue. |
| 751 * | 754 * |
| 752 * The action is performed the next time the resolution queue has been | 755 * The action is performed the next time the resolution queue has been |
| 753 * emptied. | 756 * emptied. |
| 754 * | 757 * |
| 755 * The queue is processed in FIFO order. | 758 * The queue is processed in FIFO order. |
| 756 */ | 759 */ |
| 757 void addDeferredAction(Element element, DeferredAction action) { | 760 void addDeferredAction(Element element, DeferredAction action) { |
| 758 if (queueIsClosed) { | 761 if (queueIsClosed) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 /// [Enqueuer] which is specific to code generation. | 799 /// [Enqueuer] which is specific to code generation. |
| 797 class CodegenEnqueuer extends Enqueuer { | 800 class CodegenEnqueuer extends Enqueuer { |
| 798 final Queue<CodegenWorkItem> queue; | 801 final Queue<CodegenWorkItem> queue; |
| 799 final Map<Element, js.Expression> generatedCode = | 802 final Map<Element, js.Expression> generatedCode = |
| 800 new Map<Element, js.Expression>(); | 803 new Map<Element, js.Expression>(); |
| 801 | 804 |
| 802 final Set<Element> newlyEnqueuedElements; | 805 final Set<Element> newlyEnqueuedElements; |
| 803 | 806 |
| 804 final Set<Selector> newlySeenSelectors; | 807 final Set<Selector> newlySeenSelectors; |
| 805 | 808 |
| 806 bool enabledNoSuchMethod = false; | |
| 807 | |
| 808 CodegenEnqueuer(Compiler compiler, | 809 CodegenEnqueuer(Compiler compiler, |
| 809 ItemCompilationContext itemCompilationContextCreator()) | 810 ItemCompilationContext itemCompilationContextCreator()) |
| 810 : queue = new Queue<CodegenWorkItem>(), | 811 : queue = new Queue<CodegenWorkItem>(), |
| 811 newlyEnqueuedElements = compiler.cacheStrategy.newSet(), | 812 newlyEnqueuedElements = compiler.cacheStrategy.newSet(), |
| 812 newlySeenSelectors = compiler.cacheStrategy.newSet(), | 813 newlySeenSelectors = compiler.cacheStrategy.newSet(), |
| 813 super('codegen enqueuer', compiler, itemCompilationContextCreator); | 814 super('codegen enqueuer', compiler, itemCompilationContextCreator); |
| 814 | 815 |
| 815 bool isProcessed(Element member) => | 816 bool isProcessed(Element member) => |
| 816 member.isAbstract || generatedCode.containsKey(member); | 817 member.isAbstract || generatedCode.containsKey(member); |
| 817 | 818 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 847 if (queueIsClosed) { | 848 if (queueIsClosed) { |
| 848 throw new SpannableAssertionFailure(element, | 849 throw new SpannableAssertionFailure(element, |
| 849 "Codegen work list is closed. Trying to add $element"); | 850 "Codegen work list is closed. Trying to add $element"); |
| 850 } | 851 } |
| 851 CodegenWorkItem workItem = new CodegenWorkItem( | 852 CodegenWorkItem workItem = new CodegenWorkItem( |
| 852 element, itemCompilationContextCreator()); | 853 element, itemCompilationContextCreator()); |
| 853 queue.add(workItem); | 854 queue.add(workItem); |
| 854 return true; | 855 return true; |
| 855 } | 856 } |
| 856 | 857 |
| 857 void registerNoSuchMethod(Element element) { | |
| 858 if (!enabledNoSuchMethod && compiler.backend.enabledNoSuchMethod) { | |
| 859 compiler.backend.enableNoSuchMethod(this); | |
| 860 enabledNoSuchMethod = true; | |
| 861 } | |
| 862 } | |
| 863 | |
| 864 void _logSpecificSummary(log(message)) { | 858 void _logSpecificSummary(log(message)) { |
| 865 log('Compiled ${generatedCode.length} methods.'); | 859 log('Compiled ${generatedCode.length} methods.'); |
| 866 } | 860 } |
| 867 | 861 |
| 868 void forgetElement(Element element) { | 862 void forgetElement(Element element) { |
| 869 super.forgetElement(element); | 863 super.forgetElement(element); |
| 870 generatedCode.remove(element); | 864 generatedCode.remove(element); |
| 871 if (element is MemberElement) { | 865 if (element is MemberElement) { |
| 872 for (Element closure in element.nestedClosures) { | 866 for (Element closure in element.nestedClosures) { |
| 873 generatedCode.remove(closure); | 867 generatedCode.remove(closure); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 905 void processWorkItem(void f(WorkItem work), WorkItem work) { | 899 void processWorkItem(void f(WorkItem work), WorkItem work) { |
| 906 f(work); | 900 f(work); |
| 907 } | 901 } |
| 908 } | 902 } |
| 909 | 903 |
| 910 void removeFromSet(Map<String, Set<Element>> map, Element element) { | 904 void removeFromSet(Map<String, Set<Element>> map, Element element) { |
| 911 Set<Element> set = map[element.name]; | 905 Set<Element> set = map[element.name]; |
| 912 if (set == null) return; | 906 if (set == null) return; |
| 913 set.remove(element); | 907 set.remove(element); |
| 914 } | 908 } |
| OLD | NEW |