OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 'package:kernel/ast.dart' as ir; | 5 import 'package:kernel/ast.dart' as ir; |
6 | 6 |
7 import '../closure.dart'; | 7 import '../closure.dart'; |
8 import '../compiler.dart'; | 8 import '../compiler.dart'; |
9 import '../elements/elements.dart'; | 9 import '../elements/elements.dart'; |
10 import '../elements/entities.dart'; | 10 import '../elements/entities.dart'; |
(...skipping 12 matching lines...) Expand all Loading... |
23 /// Calling [run] will start the work of visiting the body of the code to | 23 /// Calling [run] will start the work of visiting the body of the code to |
24 /// construct a set of inference-nodes that abstractly represent what the code | 24 /// construct a set of inference-nodes that abstractly represent what the code |
25 /// is doing. | 25 /// is doing. |
26 class KernelTypeGraphBuilder extends ir.Visitor<TypeInformation> { | 26 class KernelTypeGraphBuilder extends ir.Visitor<TypeInformation> { |
27 final Compiler compiler; | 27 final Compiler compiler; |
28 final MemberElement originalElement; | 28 final MemberElement originalElement; |
29 // TODO(efortuna): Remove this. | 29 // TODO(efortuna): Remove this. |
30 final MemberElement outermostElement; | 30 final MemberElement outermostElement; |
31 final ir.Node analyzedNode; | 31 final ir.Node analyzedNode; |
32 final ResolvedAst resolvedAst; | 32 final ResolvedAst resolvedAst; |
33 final TypeSystem types; | 33 // TODO(johnniwinther): This should be TypeSystem<ir.Node>. |
| 34 final TypeSystem<ast.Node> types; |
34 LocalsHandler locals; | 35 LocalsHandler locals; |
35 final InferrerEngine inferrer; | 36 final InferrerEngine inferrer; |
36 SideEffects sideEffects = new SideEffects.empty(); | 37 SideEffects sideEffects = new SideEffects.empty(); |
37 int loopLevel = 0; | 38 int loopLevel = 0; |
38 bool get inLoop => loopLevel > 0; | 39 bool get inLoop => loopLevel > 0; |
39 | 40 |
40 final Set<Entity> capturedVariables = new Set<Entity>(); | 41 final Set<Entity> capturedVariables = new Set<Entity>(); |
41 | 42 |
42 final KernelAstAdapter astAdapter; | 43 final KernelAstAdapter astAdapter; |
43 | 44 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 @override | 148 @override |
148 TypeInformation visitListLiteral(ir.ListLiteral listLiteral) { | 149 TypeInformation visitListLiteral(ir.ListLiteral listLiteral) { |
149 // We only set the type once. We don't need to re-visit the children | 150 // We only set the type once. We don't need to re-visit the children |
150 // when re-analyzing the node. | 151 // when re-analyzing the node. |
151 return inferrer.concreteKernelTypes.putIfAbsent(listLiteral, () { | 152 return inferrer.concreteKernelTypes.putIfAbsent(listLiteral, () { |
152 TypeInformation elementType; | 153 TypeInformation elementType; |
153 int length = 0; | 154 int length = 0; |
154 for (ir.Expression element in listLiteral.expressions) { | 155 for (ir.Expression element in listLiteral.expressions) { |
155 TypeInformation type = element.accept(this); | 156 TypeInformation type = element.accept(this); |
156 elementType = elementType == null | 157 elementType = elementType == null |
157 ? types.allocatePhi(null, null, type) | 158 ? types.allocatePhi(null, null, type, isTry: false) |
158 : types.addPhiInput(null, elementType, type); | 159 : types.addPhiInput(null, elementType, type); |
159 length++; | 160 length++; |
160 } | 161 } |
161 elementType = elementType == null | 162 elementType = elementType == null |
162 ? types.nonNullEmpty() | 163 ? types.nonNullEmpty() |
163 : types.simplifyPhi(null, null, elementType); | 164 : types.simplifyPhi(null, null, elementType); |
164 TypeInformation containerType = | 165 TypeInformation containerType = |
165 listLiteral.isConst ? types.constListType : types.growableListType; | 166 listLiteral.isConst ? types.constListType : types.growableListType; |
166 // TODO(efortuna): Change signature of allocateList and the rest of | 167 // TODO(efortuna): Change signature of allocateList and the rest of |
167 // type_system to deal with Kernel elements. | 168 // type_system to deal with Kernel elements. |
168 return types.allocateList(containerType, astAdapter.getNode(listLiteral), | 169 return types.allocateList(containerType, astAdapter.getNode(listLiteral), |
169 outermostElement, elementType, length); | 170 outermostElement, elementType, length); |
170 }); | 171 }); |
171 } | 172 } |
172 } | 173 } |
OLD | NEW |