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 library simple_types_inferrer; | 5 library simple_types_inferrer; |
6 | 6 |
7 import '../closure.dart' show ClosureClassMap; | 7 import '../closure.dart' show ClosureClassMap; |
8 import '../common.dart'; | 8 import '../common.dart'; |
9 import '../common/names.dart' show Identifiers, Selectors; | 9 import '../common/names.dart' show Identifiers, Selectors; |
10 import '../compiler.dart' show Compiler; | 10 import '../compiler.dart' show Compiler; |
11 import '../constants/values.dart' show ConstantValue, IntConstantValue; | 11 import '../constants/values.dart' show ConstantValue, IntConstantValue; |
12 import '../core_types.dart' show CoreClasses, CoreTypes; | 12 import '../core_types.dart' show CoreClasses, CoreTypes; |
13 import '../dart_types.dart' show DartType; | 13 import '../dart_types.dart' show DartType; |
14 import '../elements/elements.dart'; | 14 import '../elements/elements.dart'; |
15 import '../js_backend/backend_helpers.dart'; | 15 import '../js_backend/backend_helpers.dart'; |
16 import '../js_backend/js_backend.dart' as js; | 16 import '../js_backend/js_backend.dart' as js; |
17 import '../native/native.dart' as native; | 17 import '../native/native.dart' as native; |
18 import '../resolution/operators.dart' as op; | 18 import '../resolution/operators.dart' as op; |
19 import '../resolution/tree_elements.dart' show TreeElements; | |
20 import '../tree/tree.dart' as ast; | 19 import '../tree/tree.dart' as ast; |
21 import '../types/types.dart' show TypeMask, GlobalTypeInferenceElementData; | 20 import '../types/types.dart' show TypeMask, GlobalTypeInferenceElementData; |
22 import '../universe/call_structure.dart' show CallStructure; | 21 import '../universe/call_structure.dart' show CallStructure; |
23 import '../universe/selector.dart' show Selector; | 22 import '../universe/selector.dart' show Selector; |
24 import '../universe/side_effects.dart' show SideEffects; | 23 import '../universe/side_effects.dart' show SideEffects; |
25 import '../util/util.dart' show Link, Setlet; | 24 import '../util/util.dart' show Link, Setlet; |
26 import '../world.dart' show ClosedWorld; | 25 import '../world.dart' show ClosedWorld, ClosedWorldRefiner; |
27 import 'inferrer_visitor.dart'; | 26 import 'inferrer_visitor.dart'; |
28 | 27 |
29 /** | 28 /** |
30 * Common super class used by [SimpleTypeInferrerVisitor] to propagate | 29 * Common super class used by [SimpleTypeInferrerVisitor] to propagate |
31 * type information about visited nodes, as well as to request type | 30 * type information about visited nodes, as well as to request type |
32 * information of elements. | 31 * information of elements. |
33 */ | 32 */ |
34 abstract class InferrerEngine<T, V extends TypeSystem> | 33 abstract class InferrerEngine<T, V extends TypeSystem> |
35 implements MinimalInferrerEngine<T> { | 34 implements MinimalInferrerEngine<T> { |
36 final Compiler compiler; | 35 final Compiler compiler; |
37 final ClosedWorld closedWorld; | 36 final ClosedWorld closedWorld; |
| 37 final ClosedWorldRefiner closedWorldRefiner; |
38 final V types; | 38 final V types; |
39 final Map<ast.Node, T> concreteTypes = new Map<ast.Node, T>(); | 39 final Map<ast.Node, T> concreteTypes = new Map<ast.Node, T>(); |
40 final Set<Element> generativeConstructorsExposingThis = new Set<Element>(); | 40 final Set<Element> generativeConstructorsExposingThis = new Set<Element>(); |
41 | 41 |
42 /// Data computed internally within elements, like the type-mask of a send a | 42 /// Data computed internally within elements, like the type-mask of a send a |
43 /// list allocation, or a for-in loop. | 43 /// list allocation, or a for-in loop. |
44 final Map<Element, GlobalTypeInferenceElementData> inTreeData = | 44 final Map<Element, GlobalTypeInferenceElementData> inTreeData = |
45 new Map<Element, GlobalTypeInferenceElementData>(); | 45 new Map<Element, GlobalTypeInferenceElementData>(); |
46 | 46 |
47 InferrerEngine(Compiler compiler, this.types) | 47 InferrerEngine( |
48 : this.compiler = compiler, | 48 this.compiler, this.closedWorld, this.closedWorldRefiner, this.types); |
49 this.closedWorld = compiler.closedWorld; | |
50 | 49 |
51 CoreClasses get coreClasses => compiler.coreClasses; | 50 CoreClasses get coreClasses => compiler.coreClasses; |
52 | 51 |
53 CoreTypes get coreTypes => compiler.coreTypes; | 52 CoreTypes get coreTypes => compiler.coreTypes; |
54 | 53 |
55 /** | 54 /** |
56 * Records the default type of parameter [parameter]. | 55 * Records the default type of parameter [parameter]. |
57 */ | 56 */ |
58 void setDefaultTypeOfParameter(ParameterElement parameter, T type); | 57 void setDefaultTypeOfParameter(ParameterElement parameter, T type); |
59 | 58 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 sideEffects.setDependsOnStaticPropertyStore(); | 211 sideEffects.setDependsOnStaticPropertyStore(); |
213 } else { | 212 } else { |
214 sideEffects.setAllSideEffects(); | 213 sideEffects.setAllSideEffects(); |
215 sideEffects.setDependsOnSomething(); | 214 sideEffects.setDependsOnSomething(); |
216 } | 215 } |
217 } | 216 } |
218 } else if (callee.isGetter && !selector.isGetter) { | 217 } else if (callee.isGetter && !selector.isGetter) { |
219 sideEffects.setAllSideEffects(); | 218 sideEffects.setAllSideEffects(); |
220 sideEffects.setDependsOnSomething(); | 219 sideEffects.setDependsOnSomething(); |
221 } else { | 220 } else { |
222 sideEffects | 221 sideEffects.add(closedWorldRefiner.getCurrentlyKnownSideEffects(callee)); |
223 .add(compiler.inferenceWorld.getCurrentlyKnownSideEffects(callee)); | |
224 } | 222 } |
225 } | 223 } |
226 | 224 |
227 /** | 225 /** |
228 * Returns the type for [nativeBehavior]. See documentation on | 226 * Returns the type for [nativeBehavior]. See documentation on |
229 * [native.NativeBehavior]. | 227 * [native.NativeBehavior]. |
230 */ | 228 */ |
231 T typeOfNativeBehavior(native.NativeBehavior nativeBehavior) { | 229 T typeOfNativeBehavior(native.NativeBehavior nativeBehavior) { |
232 if (nativeBehavior == null) return types.dynamicType; | 230 if (nativeBehavior == null) return types.dynamicType; |
233 List typesReturned = nativeBehavior.typesReturned; | 231 List typesReturned = nativeBehavior.typesReturned; |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 analyzedElement, returnType, types.asyncFutureType); | 532 analyzedElement, returnType, types.asyncFutureType); |
535 break; | 533 break; |
536 | 534 |
537 case AsyncMarker.ASYNC_STAR: | 535 case AsyncMarker.ASYNC_STAR: |
538 returnType = inferrer.addReturnTypeFor( | 536 returnType = inferrer.addReturnTypeFor( |
539 analyzedElement, returnType, types.asyncStarStreamType); | 537 analyzedElement, returnType, types.asyncStarStreamType); |
540 break; | 538 break; |
541 } | 539 } |
542 } | 540 } |
543 | 541 |
544 compiler.inferenceWorld.registerSideEffects(analyzedElement, sideEffects); | 542 inferrer.closedWorldRefiner |
| 543 .registerSideEffects(analyzedElement, sideEffects); |
545 assert(breaksFor.isEmpty); | 544 assert(breaksFor.isEmpty); |
546 assert(continuesFor.isEmpty); | 545 assert(continuesFor.isEmpty); |
547 return returnType; | 546 return returnType; |
548 } | 547 } |
549 | 548 |
550 T visitFunctionExpression(ast.FunctionExpression node) { | 549 T visitFunctionExpression(ast.FunctionExpression node) { |
551 // We loose track of [this] in closures (see issue 20840). To be on | 550 // We loose track of [this] in closures (see issue 20840). To be on |
552 // the safe side, we mark [this] as exposed here. We could do better by | 551 // the safe side, we mark [this] as exposed here. We could do better by |
553 // analyzing the closure. | 552 // analyzing the closure. |
554 // TODO(herhut): Analyze whether closure exposes this. | 553 // TODO(herhut): Analyze whether closure exposes this. |
(...skipping 1695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2250 Selector moveNextSelector = Selectors.moveNext; | 2249 Selector moveNextSelector = Selectors.moveNext; |
2251 TypeMask moveNextMask = inTreeData.typeOfIteratorMoveNext(node); | 2250 TypeMask moveNextMask = inTreeData.typeOfIteratorMoveNext(node); |
2252 | 2251 |
2253 T iteratorType = handleDynamicSend(node, iteratorSelector, iteratorMask, | 2252 T iteratorType = handleDynamicSend(node, iteratorSelector, iteratorMask, |
2254 expressionType, new ArgumentsTypes<T>.empty()); | 2253 expressionType, new ArgumentsTypes<T>.empty()); |
2255 | 2254 |
2256 return handleForInLoop(node, iteratorType, currentSelector, currentMask, | 2255 return handleForInLoop(node, iteratorType, currentSelector, currentMask, |
2257 moveNextSelector, moveNextMask); | 2256 moveNextSelector, moveNextMask); |
2258 } | 2257 } |
2259 } | 2258 } |
OLD | NEW |