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 '../common/backend_api.dart'; | |
6 import '../common/resolution.dart'; | 5 import '../common/resolution.dart'; |
7 import '../common_elements.dart'; | 6 import '../common_elements.dart'; |
8 import '../constants/constant_system.dart'; | 7 import '../constants/constant_system.dart'; |
9 import '../constants/values.dart'; | 8 import '../constants/values.dart'; |
10 import '../elements/elements.dart'; | 9 import '../elements/elements.dart'; |
11 import '../elements/entities.dart'; | 10 import '../elements/entities.dart'; |
12 import '../elements/resolution_types.dart'; | 11 import '../elements/resolution_types.dart'; |
13 import '../universe/call_structure.dart'; | 12 import '../universe/call_structure.dart'; |
14 import '../universe/use.dart' show ConstantUse, StaticUse; | 13 import '../universe/use.dart' show ConstantUse, StaticUse; |
15 import '../universe/world_impact.dart' | 14 import '../universe/world_impact.dart' |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 WorldImpact flush() => join.flush(); | 85 WorldImpact flush() => join.flush(); |
87 } | 86 } |
88 | 87 |
89 class CustomElementsResolutionAnalysis extends CustomElementsAnalysisBase { | 88 class CustomElementsResolutionAnalysis extends CustomElementsAnalysisBase { |
90 final CustomElementsAnalysisJoin join; | 89 final CustomElementsAnalysisJoin join; |
91 | 90 |
92 CustomElementsResolutionAnalysis( | 91 CustomElementsResolutionAnalysis( |
93 Resolution resolution, | 92 Resolution resolution, |
94 ConstantSystem constantSystem, | 93 ConstantSystem constantSystem, |
95 CommonElements commonElements, | 94 CommonElements commonElements, |
96 BackendClasses backendClasses, | |
97 NativeBasicData nativeData, | 95 NativeBasicData nativeData, |
98 BackendUsageBuilder backendUsageBuilder) | 96 BackendUsageBuilder backendUsageBuilder) |
99 : join = new CustomElementsAnalysisJoin(resolution, constantSystem, | 97 : join = new CustomElementsAnalysisJoin( |
100 commonElements, backendClasses, nativeData, | 98 resolution, constantSystem, commonElements, nativeData, |
101 backendUsageBuilder: backendUsageBuilder), | 99 backendUsageBuilder: backendUsageBuilder), |
102 super(resolution, commonElements, nativeData) { | 100 super(resolution, commonElements, nativeData) { |
103 // TODO(sra): Remove this work-around. We should mark allClassesSelected in | 101 // TODO(sra): Remove this work-around. We should mark allClassesSelected in |
104 // both joins only when we see a construct generating an unknown [Type] but | 102 // both joins only when we see a construct generating an unknown [Type] but |
105 // we can't currently recognize all cases. In particular, the work-around | 103 // we can't currently recognize all cases. In particular, the work-around |
106 // for the unimplemented `ClassMirror.reflectedType` is not recognizable. | 104 // for the unimplemented `ClassMirror.reflectedType` is not recognizable. |
107 // TODO(12607): Match on [ClassMirror.reflectedType] | 105 // TODO(12607): Match on [ClassMirror.reflectedType] |
108 join.allClassesSelected = true; | 106 join.allClassesSelected = true; |
109 } | 107 } |
110 | 108 |
(...skipping 12 matching lines...) Expand all Loading... |
123 } | 121 } |
124 } | 122 } |
125 | 123 |
126 class CustomElementsCodegenAnalysis extends CustomElementsAnalysisBase { | 124 class CustomElementsCodegenAnalysis extends CustomElementsAnalysisBase { |
127 final CustomElementsAnalysisJoin join; | 125 final CustomElementsAnalysisJoin join; |
128 | 126 |
129 CustomElementsCodegenAnalysis( | 127 CustomElementsCodegenAnalysis( |
130 Resolution resolution, | 128 Resolution resolution, |
131 ConstantSystem constantSystem, | 129 ConstantSystem constantSystem, |
132 CommonElements commonElements, | 130 CommonElements commonElements, |
133 BackendClasses backendClasses, | |
134 NativeBasicData nativeData) | 131 NativeBasicData nativeData) |
135 : join = new CustomElementsAnalysisJoin(resolution, constantSystem, | 132 : join = new CustomElementsAnalysisJoin( |
136 commonElements, backendClasses, nativeData), | 133 resolution, constantSystem, commonElements, nativeData), |
137 super(resolution, commonElements, nativeData) { | 134 super(resolution, commonElements, nativeData) { |
138 // TODO(sra): Remove this work-around. We should mark allClassesSelected in | 135 // TODO(sra): Remove this work-around. We should mark allClassesSelected in |
139 // both joins only when we see a construct generating an unknown [Type] but | 136 // both joins only when we see a construct generating an unknown [Type] but |
140 // we can't currently recognize all cases. In particular, the work-around | 137 // we can't currently recognize all cases. In particular, the work-around |
141 // for the unimplemented `ClassMirror.reflectedType` is not recognizable. | 138 // for the unimplemented `ClassMirror.reflectedType` is not recognizable. |
142 // TODO(12607): Match on [ClassMirror.reflectedType] | 139 // TODO(12607): Match on [ClassMirror.reflectedType] |
143 join.allClassesSelected = true; | 140 join.allClassesSelected = true; |
144 } | 141 } |
145 | 142 |
146 void registerTypeConstant(ClassElement element) { | 143 void registerTypeConstant(ClassElement element) { |
147 assert(element.isClass); | 144 assert(element.isClass); |
148 join.selectedClasses.add(element); | 145 join.selectedClasses.add(element); |
149 } | 146 } |
150 | 147 |
151 bool get needsTable => join.demanded; | 148 bool get needsTable => join.demanded; |
152 | 149 |
153 bool needsClass(ClassElement classElement) => | 150 bool needsClass(ClassElement classElement) => |
154 join.activeClasses.contains(classElement); | 151 join.activeClasses.contains(classElement); |
155 | 152 |
156 List<ConstructorElement> constructors(ClassElement classElement) => | 153 List<ConstructorElement> constructors(ClassElement classElement) => |
157 join.computeEscapingConstructors(classElement); | 154 join.computeEscapingConstructors(classElement); |
158 } | 155 } |
159 | 156 |
160 class CustomElementsAnalysisJoin { | 157 class CustomElementsAnalysisJoin { |
161 final Resolution _resolution; | 158 final Resolution _resolution; |
162 final ConstantSystem _constantSystem; | 159 final ConstantSystem _constantSystem; |
163 final CommonElements _commonElements; | 160 final CommonElements _commonElements; |
164 final BackendClasses _backendClasses; | |
165 final NativeBasicData _nativeData; | 161 final NativeBasicData _nativeData; |
166 final BackendUsageBuilder _backendUsageBuilder; | 162 final BackendUsageBuilder _backendUsageBuilder; |
167 | 163 |
168 final bool forResolution; | 164 final bool forResolution; |
169 | 165 |
170 final StagedWorldImpactBuilder impactBuilder = new StagedWorldImpactBuilder(); | 166 final StagedWorldImpactBuilder impactBuilder = new StagedWorldImpactBuilder(); |
171 | 167 |
172 // Classes that are candidates for needing constructors. Classes are moved to | 168 // Classes that are candidates for needing constructors. Classes are moved to |
173 // [activeClasses] when we know they need constructors. | 169 // [activeClasses] when we know they need constructors. |
174 final instantiatedClasses = new Set<ClassElement>(); | 170 final instantiatedClasses = new Set<ClassElement>(); |
175 | 171 |
176 // Classes explicitly named. | 172 // Classes explicitly named. |
177 final selectedClasses = new Set<ClassElement>(); | 173 final selectedClasses = new Set<ClassElement>(); |
178 | 174 |
179 // True if we must conservatively include all extension classes. | 175 // True if we must conservatively include all extension classes. |
180 bool allClassesSelected = false; | 176 bool allClassesSelected = false; |
181 | 177 |
182 // Did we see a demand for the data? | 178 // Did we see a demand for the data? |
183 bool demanded = false; | 179 bool demanded = false; |
184 | 180 |
185 // ClassesOutput: classes requiring metadata. | 181 // ClassesOutput: classes requiring metadata. |
186 final activeClasses = new Set<ClassElement>(); | 182 final activeClasses = new Set<ClassElement>(); |
187 | 183 |
188 CustomElementsAnalysisJoin(this._resolution, this._constantSystem, | 184 CustomElementsAnalysisJoin(this._resolution, this._constantSystem, |
189 this._commonElements, this._backendClasses, this._nativeData, | 185 this._commonElements, this._nativeData, |
190 {BackendUsageBuilder backendUsageBuilder}) | 186 {BackendUsageBuilder backendUsageBuilder}) |
191 : this._backendUsageBuilder = backendUsageBuilder, | 187 : this._backendUsageBuilder = backendUsageBuilder, |
192 this.forResolution = backendUsageBuilder != null; | 188 this.forResolution = backendUsageBuilder != null; |
193 | 189 |
194 WorldImpact flush() { | 190 WorldImpact flush() { |
195 if (!demanded) return const WorldImpact(); | 191 if (!demanded) return const WorldImpact(); |
196 var newActiveClasses = new Set<ClassElement>(); | 192 var newActiveClasses = new Set<ClassElement>(); |
197 for (ClassElement classElement in instantiatedClasses) { | 193 for (ClassElement classElement in instantiatedClasses) { |
198 bool isNative = _nativeData.isNativeClass(classElement); | 194 bool isNative = _nativeData.isNativeClass(classElement); |
199 bool isExtension = | 195 bool isExtension = |
(...skipping 21 matching lines...) Expand all Loading... |
221 .registerConstantUse(new ConstantUse.customElements(constant)); | 217 .registerConstantUse(new ConstantUse.customElements(constant)); |
222 } | 218 } |
223 } | 219 } |
224 activeClasses.addAll(newActiveClasses); | 220 activeClasses.addAll(newActiveClasses); |
225 instantiatedClasses.removeAll(newActiveClasses); | 221 instantiatedClasses.removeAll(newActiveClasses); |
226 return impactBuilder.flush(); | 222 return impactBuilder.flush(); |
227 } | 223 } |
228 | 224 |
229 TypeConstantValue _makeTypeConstant(ClassElement element) { | 225 TypeConstantValue _makeTypeConstant(ClassElement element) { |
230 ResolutionDartType elementType = element.rawType; | 226 ResolutionDartType elementType = element.rawType; |
231 return _constantSystem.createType( | 227 return _constantSystem.createType(_commonElements, elementType); |
232 _commonElements, _backendClasses, elementType); | |
233 } | 228 } |
234 | 229 |
235 List<ConstructorElement> computeEscapingConstructors( | 230 List<ConstructorElement> computeEscapingConstructors( |
236 ClassElement classElement) { | 231 ClassElement classElement) { |
237 List<ConstructorElement> result = <ConstructorElement>[]; | 232 List<ConstructorElement> result = <ConstructorElement>[]; |
238 // Only classes that extend native classes have constructors in the table. | 233 // Only classes that extend native classes have constructors in the table. |
239 // We could refine this to classes that extend Element, but that would break | 234 // We could refine this to classes that extend Element, but that would break |
240 // the tests and there is no sane reason to subclass other native classes. | 235 // the tests and there is no sane reason to subclass other native classes. |
241 if (_nativeData.isNativeClass(classElement)) return result; | 236 if (_nativeData.isNativeClass(classElement)) return result; |
242 | 237 |
243 void selectGenerativeConstructors(ClassElement enclosing, Element member) { | 238 void selectGenerativeConstructors(ClassElement enclosing, Element member) { |
244 if (member.isGenerativeConstructor) { | 239 if (member.isGenerativeConstructor) { |
245 // Ignore constructors that cannot be called with zero arguments. | 240 // Ignore constructors that cannot be called with zero arguments. |
246 ConstructorElement constructor = member; | 241 ConstructorElement constructor = member; |
247 constructor.computeType(_resolution); | 242 constructor.computeType(_resolution); |
248 FunctionSignature parameters = constructor.functionSignature; | 243 FunctionSignature parameters = constructor.functionSignature; |
249 if (parameters.requiredParameterCount == 0) { | 244 if (parameters.requiredParameterCount == 0) { |
250 result.add(member); | 245 result.add(member); |
251 } | 246 } |
252 } | 247 } |
253 } | 248 } |
254 | 249 |
255 classElement.forEachMember(selectGenerativeConstructors, | 250 classElement.forEachMember(selectGenerativeConstructors, |
256 includeBackendMembers: false, includeSuperAndInjectedMembers: false); | 251 includeBackendMembers: false, includeSuperAndInjectedMembers: false); |
257 return result; | 252 return result; |
258 } | 253 } |
259 } | 254 } |
OLD | NEW |