| 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 types; | 5 library types; |
| 6 | 6 |
| 7 import '../closure.dart' show SynthesizedCallMethodElementX; | |
| 8 import '../common.dart' show failedAt; | 7 import '../common.dart' show failedAt; |
| 9 import '../common/tasks.dart' show CompilerTask; | 8 import '../common/tasks.dart' show CompilerTask; |
| 10 import '../compiler.dart' show Compiler; | 9 import '../compiler.dart' show Compiler; |
| 11 import '../elements/elements.dart'; | 10 import '../elements/elements.dart'; |
| 12 import '../elements/entities.dart'; | 11 import '../elements/entities.dart'; |
| 13 import '../inferrer/type_graph_inferrer.dart' show TypeGraphInferrer; | 12 import '../inferrer/type_graph_inferrer.dart' show TypeGraphInferrer; |
| 14 import '../inferrer/type_system.dart'; | 13 import '../inferrer/type_system.dart'; |
| 15 import '../tree/tree.dart'; | 14 import '../tree/tree.dart'; |
| 16 import '../universe/selector.dart' show Selector; | 15 import '../universe/selector.dart' show Selector; |
| 17 import '../util/util.dart' show Maplet; | 16 import '../util/util.dart' show Maplet; |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 } | 190 } |
| 192 | 191 |
| 193 void setCurrentTypeMask(ForIn node, TypeMask mask) { | 192 void setCurrentTypeMask(ForIn node, TypeMask mask) { |
| 194 _set(node.inToken, mask); | 193 _set(node.inToken, mask); |
| 195 } | 194 } |
| 196 } | 195 } |
| 197 | 196 |
| 198 /// API to interact with the global type-inference engine. | 197 /// API to interact with the global type-inference engine. |
| 199 abstract class TypesInferrer { | 198 abstract class TypesInferrer { |
| 200 void analyzeMain(FunctionEntity element); | 199 void analyzeMain(FunctionEntity element); |
| 201 | |
| 202 // We are moving away from using LocalFunctionElement to represent closures, | |
| 203 // but plan to use the <closure-class>.callMethod instead as the | |
| 204 // representation. At that point, we should be able to use | |
| 205 // getReturnTypeOfMember(callMethod). | |
| 206 @deprecated | |
| 207 TypeMask getReturnTypeOfLocalFunction(LocalFunctionElement element); | |
| 208 TypeMask getReturnTypeOfMember(MemberElement element); | 200 TypeMask getReturnTypeOfMember(MemberElement element); |
| 209 TypeMask getReturnTypeOfParameter(ParameterElement element); | 201 TypeMask getReturnTypeOfParameter(ParameterElement element); |
| 210 | |
| 211 // We are moving away from using LocalFunctionElement to represent closures, | |
| 212 // but plan to use the <closure-class>.callMethod instead as the | |
| 213 // representation. At that point, we should be able to use | |
| 214 // getTypeOfMember(callMethod). | |
| 215 @deprecated | |
| 216 TypeMask getTypeOfLocalFunction(LocalFunctionElement element); | |
| 217 TypeMask getTypeOfMember(MemberElement element); | 202 TypeMask getTypeOfMember(MemberElement element); |
| 218 TypeMask getTypeOfParameter(ParameterElement element); | 203 TypeMask getTypeOfParameter(ParameterElement element); |
| 219 TypeMask getTypeForNewList(Node node); | 204 TypeMask getTypeForNewList(Node node); |
| 220 TypeMask getTypeOfSelector(Selector selector, TypeMask mask); | 205 TypeMask getTypeOfSelector(Selector selector, TypeMask mask); |
| 221 void clear(); | 206 void clear(); |
| 222 | |
| 223 // We are moving away from using LocalFunctionElement to represent closures, | |
| 224 // but plan to use the <closure-class>.callMethod instead as the | |
| 225 // representation. At that point, we should be able to use | |
| 226 // isMemberCalledOnce(callMethod). | |
| 227 @deprecated | |
| 228 bool isLocalFunctionCalledOnce(LocalFunctionElement element); | |
| 229 bool isMemberCalledOnce(MemberElement element); | 207 bool isMemberCalledOnce(MemberElement element); |
| 230 bool isParameterCalledOnce(ParameterElement element); | 208 bool isParameterCalledOnce(ParameterElement element); |
| 231 bool isFixedArrayCheckedForGrowable(Node node); | 209 bool isFixedArrayCheckedForGrowable(Node node); |
| 232 } | 210 } |
| 233 | 211 |
| 234 /// Results produced by the global type-inference algorithm. | 212 /// Results produced by the global type-inference algorithm. |
| 235 /// | 213 /// |
| 236 /// All queries in this class may contain results that assume whole-program | 214 /// All queries in this class may contain results that assume whole-program |
| 237 /// closed-world semantics. Any [TypeMask] for an element or node that we return | 215 /// closed-world semantics. Any [TypeMask] for an element or node that we return |
| 238 /// was inferred to be a "guaranteed type", that means, it is a type that we | 216 /// was inferred to be a "guaranteed type", that means, it is a type that we |
| (...skipping 11 matching lines...) Expand all Loading... |
| 250 // TODO(sigmund,johnniwinther): compute result objects eagerly and make it an | 228 // TODO(sigmund,johnniwinther): compute result objects eagerly and make it an |
| 251 // error to query for results that don't exist. | 229 // error to query for results that don't exist. |
| 252 GlobalTypeInferenceElementResult resultOfMember(MemberElement member) { | 230 GlobalTypeInferenceElementResult resultOfMember(MemberElement member) { |
| 253 assert( | 231 assert( |
| 254 !member.isGenerativeConstructorBody, | 232 !member.isGenerativeConstructorBody, |
| 255 failedAt( | 233 failedAt( |
| 256 member, | 234 member, |
| 257 "unexpected input: ConstructorBodyElements are created" | 235 "unexpected input: ConstructorBodyElements are created" |
| 258 " after global type inference, no data is avaiable for them.")); | 236 " after global type inference, no data is avaiable for them.")); |
| 259 | 237 |
| 260 // TODO(sigmund): store closure data directly in the closure element and | |
| 261 // not in the context of the enclosing method? | |
| 262 MemberElement key = (member is SynthesizedCallMethodElementX) | |
| 263 ? member.memberContext | |
| 264 : member; | |
| 265 bool isJsInterop = closedWorld.nativeData.isJsInteropMember(member); | 238 bool isJsInterop = closedWorld.nativeData.isJsInteropMember(member); |
| 266 return _memberResults.putIfAbsent( | 239 return _memberResults.putIfAbsent( |
| 267 member, | 240 member, |
| 268 () => new GlobalTypeInferenceMemberResult( | 241 () => new GlobalTypeInferenceMemberResult( |
| 269 member, | 242 member, |
| 270 _inferrer.inferrer.lookupDataOfMember(key), | 243 // We store data in the context of the enclosing method, even |
| 244 // for closure elements. |
| 245 _inferrer.inferrer.lookupDataOfMember(member.memberContext), |
| 271 _inferrer, | 246 _inferrer, |
| 272 isJsInterop, | 247 isJsInterop, |
| 273 dynamicType)); | 248 dynamicType)); |
| 274 } | 249 } |
| 275 | 250 |
| 276 // TODO(sigmund,johnniwinther): compute result objects eagerly and make it an | 251 // TODO(sigmund,johnniwinther): compute result objects eagerly and make it an |
| 277 // error to query for results that don't exist. | 252 // error to query for results that don't exist. |
| 278 GlobalTypeInferenceElementResult resultOfParameter( | 253 GlobalTypeInferenceElementResult resultOfParameter( |
| 279 ParameterElement parameter) { | 254 ParameterElement parameter) { |
| 280 return _parameterResults.putIfAbsent( | 255 return _parameterResults.putIfAbsent( |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 measure(() { | 299 measure(() { |
| 325 typesInferrerInternal ??= | 300 typesInferrerInternal ??= |
| 326 new TypeGraphInferrer(compiler, closedWorld, closedWorldRefiner); | 301 new TypeGraphInferrer(compiler, closedWorld, closedWorldRefiner); |
| 327 typesInferrerInternal.analyzeMain(mainElement); | 302 typesInferrerInternal.analyzeMain(mainElement); |
| 328 typesInferrerInternal.clear(); | 303 typesInferrerInternal.clear(); |
| 329 results = new GlobalTypeInferenceResults(typesInferrerInternal, | 304 results = new GlobalTypeInferenceResults(typesInferrerInternal, |
| 330 closedWorld, typesInferrerInternal.inferrer.types); | 305 closedWorld, typesInferrerInternal.inferrer.types); |
| 331 }); | 306 }); |
| 332 } | 307 } |
| 333 } | 308 } |
| OLD | NEW |