| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 import '../compiler.dart' show Compiler; | 5 import '../compiler.dart' show Compiler; |
| 6 import '../constants/values.dart'; | 6 import '../constants/values.dart'; |
| 7 import '../dart_types.dart'; | 7 import '../dart_types.dart'; |
| 8 import '../elements/elements.dart'; | 8 import '../elements/elements.dart'; |
| 9 import '../enqueue.dart' show Enqueuer; | 9 import '../enqueue.dart' show Enqueuer; |
| 10 import '../universe/use.dart' show StaticUse; | 10 import '../universe/use.dart' show StaticUse; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 codegenJoin = new CustomElementsAnalysisJoin(backend) { | 64 codegenJoin = new CustomElementsAnalysisJoin(backend) { |
| 65 // TODO(sra): Remove this work-around. We should mark allClassesSelected in | 65 // TODO(sra): Remove this work-around. We should mark allClassesSelected in |
| 66 // both joins only when we see a construct generating an unknown [Type] but | 66 // both joins only when we see a construct generating an unknown [Type] but |
| 67 // we can't currently recognize all cases. In particular, the work-around | 67 // we can't currently recognize all cases. In particular, the work-around |
| 68 // for the unimplemented `ClassMirror.reflectedType` is not recognizable. | 68 // for the unimplemented `ClassMirror.reflectedType` is not recognizable. |
| 69 // TODO(12607): Match on [ClassMirror.reflectedType] | 69 // TODO(12607): Match on [ClassMirror.reflectedType] |
| 70 resolutionJoin.allClassesSelected = true; | 70 resolutionJoin.allClassesSelected = true; |
| 71 codegenJoin.allClassesSelected = true; | 71 codegenJoin.allClassesSelected = true; |
| 72 } | 72 } |
| 73 | 73 |
| 74 CustomElementsAnalysisJoin joinFor(Enqueuer enqueuer) => | 74 CustomElementsAnalysisJoin joinFor({bool forResolution}) => |
| 75 enqueuer.isResolutionQueue ? resolutionJoin : codegenJoin; | 75 forResolution ? resolutionJoin : codegenJoin; |
| 76 | 76 |
| 77 void registerInstantiatedClass(ClassElement classElement, Enqueuer enqueuer) { | 77 void registerInstantiatedClass(ClassElement classElement, |
| 78 {bool forResolution}) { |
| 78 classElement.ensureResolved(compiler.resolution); | 79 classElement.ensureResolved(compiler.resolution); |
| 79 if (!backend.isNativeOrExtendsNative(classElement)) return; | 80 if (!backend.isNativeOrExtendsNative(classElement)) return; |
| 80 if (classElement.isMixinApplication) return; | 81 if (classElement.isMixinApplication) return; |
| 81 if (classElement.isAbstract) return; | 82 if (classElement.isAbstract) return; |
| 82 // JsInterop classes are opaque interfaces without a concrete | 83 // JsInterop classes are opaque interfaces without a concrete |
| 83 // implementation. | 84 // implementation. |
| 84 if (backend.isJsInterop(classElement)) return; | 85 if (backend.isJsInterop(classElement)) return; |
| 85 joinFor(enqueuer).instantiatedClasses.add(classElement); | 86 joinFor(forResolution: forResolution).instantiatedClasses.add(classElement); |
| 86 } | 87 } |
| 87 | 88 |
| 88 void registerTypeLiteral(DartType type) { | 89 void registerTypeLiteral(DartType type) { |
| 89 if (type.isInterfaceType) { | 90 if (type.isInterfaceType) { |
| 90 // TODO(sra): If we had a flow query from the type literal expression to | 91 // TODO(sra): If we had a flow query from the type literal expression to |
| 91 // the Type argument of the metadata lookup, we could tell if this type | 92 // the Type argument of the metadata lookup, we could tell if this type |
| 92 // literal is really a demand for the metadata. | 93 // literal is really a demand for the metadata. |
| 93 resolutionJoin.selectedClasses.add(type.element); | 94 resolutionJoin.selectedClasses.add(type.element); |
| 94 } else if (type.isTypeVariable) { | 95 } else if (type.isTypeVariable) { |
| 95 // This is a type parameter of a parameterized class. | 96 // This is a type parameter of a parameterized class. |
| 96 // TODO(sra): Is there a way to determine which types are bound to the | 97 // TODO(sra): Is there a way to determine which types are bound to the |
| 97 // parameter? | 98 // parameter? |
| 98 resolutionJoin.allClassesSelected = true; | 99 resolutionJoin.allClassesSelected = true; |
| 99 } | 100 } |
| 100 } | 101 } |
| 101 | 102 |
| 102 void registerTypeConstant(Element element) { | 103 void registerTypeConstant(Element element) { |
| 103 assert(element.isClass); | 104 assert(element.isClass); |
| 104 codegenJoin.selectedClasses.add(element); | 105 codegenJoin.selectedClasses.add(element); |
| 105 } | 106 } |
| 106 | 107 |
| 107 void registerStaticUse(Element element, Enqueuer enqueuer) { | 108 void registerStaticUse(Element element, {bool forResolution}) { |
| 108 assert(element != null); | 109 assert(element != null); |
| 109 if (!fetchedTableAccessorMethod) { | 110 if (!fetchedTableAccessorMethod) { |
| 110 fetchedTableAccessorMethod = true; | 111 fetchedTableAccessorMethod = true; |
| 111 tableAccessorMethod = backend.helpers.findIndexForNativeSubclassType; | 112 tableAccessorMethod = backend.helpers.findIndexForNativeSubclassType; |
| 112 } | 113 } |
| 113 if (element == tableAccessorMethod) { | 114 if (element == tableAccessorMethod) { |
| 114 joinFor(enqueuer).demanded = true; | 115 joinFor(forResolution: forResolution).demanded = true; |
| 115 } | 116 } |
| 116 } | 117 } |
| 117 | 118 |
| 118 void onQueueEmpty(Enqueuer enqueuer) { | 119 /// Computes the [WorldImpact] of the classes registered since last flush. |
| 119 joinFor(enqueuer).flush(enqueuer); | 120 WorldImpact flush({bool forResolution}) { |
| 121 return joinFor(forResolution: forResolution).flush(); |
| 120 } | 122 } |
| 121 | 123 |
| 122 bool get needsTable => codegenJoin.demanded; | 124 bool get needsTable => codegenJoin.demanded; |
| 123 | 125 |
| 124 bool needsClass(ClassElement classElement) => | 126 bool needsClass(ClassElement classElement) => |
| 125 codegenJoin.activeClasses.contains(classElement); | 127 codegenJoin.activeClasses.contains(classElement); |
| 126 | 128 |
| 127 List<Element> constructors(ClassElement classElement) => | 129 List<Element> constructors(ClassElement classElement) => |
| 128 codegenJoin.computeEscapingConstructors(classElement); | 130 codegenJoin.computeEscapingConstructors(classElement); |
| 129 } | 131 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 145 bool allClassesSelected = false; | 147 bool allClassesSelected = false; |
| 146 | 148 |
| 147 // Did we see a demand for the data? | 149 // Did we see a demand for the data? |
| 148 bool demanded = false; | 150 bool demanded = false; |
| 149 | 151 |
| 150 // ClassesOutput: classes requiring metadata. | 152 // ClassesOutput: classes requiring metadata. |
| 151 final activeClasses = new Set<ClassElement>(); | 153 final activeClasses = new Set<ClassElement>(); |
| 152 | 154 |
| 153 CustomElementsAnalysisJoin(this.backend); | 155 CustomElementsAnalysisJoin(this.backend); |
| 154 | 156 |
| 155 void flush(Enqueuer enqueuer) { | 157 WorldImpact flush() { |
| 156 if (!demanded) return; | 158 if (!demanded) return const WorldImpact(); |
| 157 var newActiveClasses = new Set<ClassElement>(); | 159 var newActiveClasses = new Set<ClassElement>(); |
| 158 for (ClassElement classElement in instantiatedClasses) { | 160 for (ClassElement classElement in instantiatedClasses) { |
| 159 bool isNative = backend.isNative(classElement); | 161 bool isNative = backend.isNative(classElement); |
| 160 bool isExtension = | 162 bool isExtension = |
| 161 !isNative && backend.isNativeOrExtendsNative(classElement); | 163 !isNative && backend.isNativeOrExtendsNative(classElement); |
| 162 // Generate table entries for native classes that are explicitly named and | 164 // Generate table entries for native classes that are explicitly named and |
| 163 // extensions that fix our criteria. | 165 // extensions that fix our criteria. |
| 164 if ((isNative && selectedClasses.contains(classElement)) || | 166 if ((isNative && selectedClasses.contains(classElement)) || |
| 165 (isExtension && | 167 (isExtension && |
| 166 (allClassesSelected || selectedClasses.contains(classElement)))) { | 168 (allClassesSelected || selectedClasses.contains(classElement)))) { |
| 167 newActiveClasses.add(classElement); | 169 newActiveClasses.add(classElement); |
| 168 Iterable<ConstructorElement> escapingConstructors = | 170 Iterable<ConstructorElement> escapingConstructors = |
| 169 computeEscapingConstructors(classElement); | 171 computeEscapingConstructors(classElement); |
| 170 for (ConstructorElement constructor in escapingConstructors) { | 172 for (ConstructorElement constructor in escapingConstructors) { |
| 171 enqueuer.registerStaticUse(new StaticUse.foreignUse(constructor)); | 173 impactBuilder |
| 174 .registerStaticUse(new StaticUse.foreignUse(constructor)); |
| 172 } | 175 } |
| 173 escapingConstructors | 176 escapingConstructors |
| 174 .forEach(compiler.globalDependencies.registerDependency); | 177 .forEach(compiler.globalDependencies.registerDependency); |
| 175 // Force the generaton of the type constant that is the key to an entry | 178 // Force the generaton of the type constant that is the key to an entry |
| 176 // in the generated table. | 179 // in the generated table. |
| 177 ConstantValue constant = makeTypeConstant(classElement); | 180 ConstantValue constant = makeTypeConstant(classElement); |
| 178 backend.computeImpactForCompileTimeConstant( | 181 backend.computeImpactForCompileTimeConstant( |
| 179 constant, impactBuilder, false); | 182 constant, impactBuilder, false); |
| 180 backend.addCompileTimeConstantForEmission(constant); | 183 backend.addCompileTimeConstantForEmission(constant); |
| 181 } | 184 } |
| 182 } | 185 } |
| 183 activeClasses.addAll(newActiveClasses); | 186 activeClasses.addAll(newActiveClasses); |
| 184 instantiatedClasses.removeAll(newActiveClasses); | 187 instantiatedClasses.removeAll(newActiveClasses); |
| 185 enqueuer.applyImpact(null, impactBuilder.flush()); | 188 return impactBuilder.flush(); |
| 186 } | 189 } |
| 187 | 190 |
| 188 TypeConstantValue makeTypeConstant(ClassElement element) { | 191 TypeConstantValue makeTypeConstant(ClassElement element) { |
| 189 DartType elementType = element.rawType; | 192 DartType elementType = element.rawType; |
| 190 return backend.constantSystem.createType(compiler, elementType); | 193 return backend.constantSystem.createType(compiler, elementType); |
| 191 } | 194 } |
| 192 | 195 |
| 193 List<ConstructorElement> computeEscapingConstructors( | 196 List<ConstructorElement> computeEscapingConstructors( |
| 194 ClassElement classElement) { | 197 ClassElement classElement) { |
| 195 List<ConstructorElement> result = <ConstructorElement>[]; | 198 List<ConstructorElement> result = <ConstructorElement>[]; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 208 result.add(member); | 211 result.add(member); |
| 209 } | 212 } |
| 210 } | 213 } |
| 211 } | 214 } |
| 212 | 215 |
| 213 classElement.forEachMember(selectGenerativeConstructors, | 216 classElement.forEachMember(selectGenerativeConstructors, |
| 214 includeBackendMembers: false, includeSuperAndInjectedMembers: false); | 217 includeBackendMembers: false, includeSuperAndInjectedMembers: false); |
| 215 return result; | 218 return result; |
| 216 } | 219 } |
| 217 } | 220 } |
| OLD | NEW |