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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 | 4 |
5 import 'package:front_end/src/base/instrumentation.dart'; | 5 import 'package:front_end/src/base/instrumentation.dart'; |
6 import 'package:front_end/src/dependency_walker.dart' as dependencyWalker; | 6 import 'package:front_end/src/dependency_walker.dart' as dependencyWalker; |
7 import 'package:front_end/src/fasta/errors.dart'; | 7 import 'package:front_end/src/fasta/errors.dart'; |
8 import 'package:front_end/src/fasta/kernel/kernel_shadow_ast.dart'; | 8 import 'package:front_end/src/fasta/kernel/kernel_shadow_ast.dart'; |
9 import 'package:front_end/src/fasta/type_inference/type_inference_listener.dart'
; | 9 import 'package:front_end/src/fasta/type_inference/type_inference_listener.dart'
; |
10 import 'package:front_end/src/fasta/type_inference/type_inferrer.dart'; | 10 import 'package:front_end/src/fasta/type_inference/type_inferrer.dart'; |
11 import 'package:front_end/src/fasta/type_inference/type_schema_environment.dart'
; | 11 import 'package:front_end/src/fasta/type_inference/type_schema_environment.dart'
; |
12 import 'package:kernel/ast.dart' | 12 import 'package:kernel/ast.dart' |
13 show | 13 show |
14 Class, | 14 Class, |
15 DartType, | 15 DartType, |
16 DynamicType, | 16 DynamicType, |
17 Field, | 17 Field, |
18 FunctionType, | 18 FunctionType, |
19 InterfaceType, | 19 InterfaceType, |
| 20 Location, |
20 Member, | 21 Member, |
21 Procedure, | 22 Procedure, |
22 TypeParameter, | 23 TypeParameter, |
23 TypeParameterType; | 24 TypeParameterType; |
24 import 'package:kernel/class_hierarchy.dart'; | 25 import 'package:kernel/class_hierarchy.dart'; |
25 import 'package:kernel/core_types.dart'; | 26 import 'package:kernel/core_types.dart'; |
26 import 'package:kernel/type_algebra.dart'; | 27 import 'package:kernel/type_algebra.dart'; |
27 | 28 |
| 29 import '../errors.dart' show Crash; |
| 30 |
| 31 import '../messages.dart' show getLocationFromNode; |
| 32 |
28 /// Data structure for tracking dependencies among fields, getters, and setters | 33 /// Data structure for tracking dependencies among fields, getters, and setters |
29 /// that require type inference. | 34 /// that require type inference. |
30 /// | 35 /// |
31 /// TODO(paulberry): see if it's possible to make this class more lightweight | 36 /// TODO(paulberry): see if it's possible to make this class more lightweight |
32 /// by changing the API so that the walker is passed to computeDependencies(). | 37 /// by changing the API so that the walker is passed to computeDependencies(). |
33 /// (This should allow us to drop the _typeInferenceEngine field). | 38 /// (This should allow us to drop the _typeInferenceEngine field). |
34 class AccessorNode extends dependencyWalker.Node<AccessorNode> { | 39 class AccessorNode extends dependencyWalker.Node<AccessorNode> { |
35 final TypeInferenceEngineImpl _typeInferenceEngine; | 40 final TypeInferenceEngineImpl _typeInferenceEngine; |
36 | 41 |
37 final KernelMember member; | 42 final KernelMember member; |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 } | 277 } |
273 for (var accessorNode in accessorNodes) { | 278 for (var accessorNode in accessorNodes) { |
274 if (fusedTopLevelInference) { | 279 if (fusedTopLevelInference) { |
275 assert(expandedTopLevelInference); | 280 assert(expandedTopLevelInference); |
276 inferAccessorFused(accessorNode, null); | 281 inferAccessorFused(accessorNode, null); |
277 } else { | 282 } else { |
278 if (accessorNode.isEvaluated) continue; | 283 if (accessorNode.isEvaluated) continue; |
279 new _AccessorWalker().walk(accessorNode); | 284 new _AccessorWalker().walk(accessorNode); |
280 } | 285 } |
281 } | 286 } |
282 for (var formal in initializingFormals) { | 287 for (KernelVariableDeclaration formal in initializingFormals) { |
283 formal.type = _inferInitializingFormalType(formal); | 288 try { |
| 289 formal.type = _inferInitializingFormalType(formal); |
| 290 } catch (e, s) { |
| 291 Location location = getLocationFromNode(formal); |
| 292 if (location == null) { |
| 293 rethrow; |
| 294 } else { |
| 295 throw new Crash(Uri.parse(location.file), formal.fileOffset, e, s); |
| 296 } |
| 297 } |
284 } | 298 } |
285 } | 299 } |
286 | 300 |
287 /// Retrieve the [TypeInferrer] for the given [member], which was created by | 301 /// Retrieve the [TypeInferrer] for the given [member], which was created by |
288 /// a previous call to [createTopLevelTypeInferrer]. | 302 /// a previous call to [createTopLevelTypeInferrer]. |
289 TypeInferrerImpl getMemberTypeInferrer(KernelMember member); | 303 TypeInferrerImpl getMemberTypeInferrer(KernelMember member); |
290 | 304 |
291 /// Performs type inference on the given [accessorNode]. | 305 /// Performs type inference on the given [accessorNode]. |
292 void inferAccessor(AccessorNode accessorNode) { | 306 void inferAccessor(AccessorNode accessorNode) { |
293 assert(accessorNode.state == InferenceState.NotInferredYet); | 307 assert(accessorNode.state == InferenceState.NotInferredYet); |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 } | 630 } |
617 | 631 |
618 @override | 632 @override |
619 void evaluateScc(List<AccessorNode> scc) { | 633 void evaluateScc(List<AccessorNode> scc) { |
620 // Mark every accessor as part of a circularity. | 634 // Mark every accessor as part of a circularity. |
621 for (var f in scc) { | 635 for (var f in scc) { |
622 f._typeInferenceEngine.inferAccessorCircular(f); | 636 f._typeInferenceEngine.inferAccessorCircular(f); |
623 } | 637 } |
624 } | 638 } |
625 } | 639 } |
OLD | NEW |