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 type_graph_inferrer; | 5 library type_graph_inferrer; |
6 | 6 |
7 import 'dart:collection' show Queue, IterableBase; | 7 import 'dart:collection' show Queue, IterableBase; |
8 import '../dart_types.dart' show DartType, InterfaceType, TypeKind; | 8 import '../dart_types.dart' show DartType, InterfaceType, TypeKind; |
9 import '../elements/elements.dart'; | 9 import '../elements/elements.dart'; |
10 import '../tree/tree.dart' show LiteralList, Node; | 10 import '../tree/tree.dart' show LiteralList, Node; |
11 import '../types/types.dart' show TypeMask, ContainerTypeMask, TypesInferrer; | 11 import '../types/types.dart' show TypeMask, ContainerTypeMask, TypesInferrer; |
12 import '../universe/universe.dart' show Selector, TypedSelector, SideEffects; | 12 import '../universe/universe.dart' show Selector, TypedSelector, SideEffects; |
13 import '../dart2jslib.dart' show Compiler, TreeElementMapping; | 13 import '../dart2jslib.dart' show Compiler, TreeElementMapping; |
14 import 'inferrer_visitor.dart' show TypeSystem, ArgumentsTypes; | 14 import 'inferrer_visitor.dart' show TypeSystem, ArgumentsTypes; |
15 import '../native_handler.dart' as native; | 15 import '../native_handler.dart' as native; |
16 import '../util/util.dart' show Spannable, Setlet; | 16 import '../util/util.dart' show Spannable, Setlet; |
17 import 'simple_types_inferrer.dart'; | 17 import 'simple_types_inferrer.dart'; |
| 18 import 'ir_type_inferrer.dart'; |
18 import '../dart2jslib.dart' show invariant; | 19 import '../dart2jslib.dart' show invariant; |
19 | 20 |
20 part 'type_graph_nodes.dart'; | 21 part 'type_graph_nodes.dart'; |
21 part 'container_tracer.dart'; | 22 part 'container_tracer.dart'; |
22 | 23 |
23 /** | 24 /** |
24 * A set of selector names that [List] implements, that we know return | 25 * A set of selector names that [List] implements, that we know return |
25 * their element type. | 26 * their element type. |
26 */ | 27 */ |
27 Set<Selector> returnsElementTypeSet = new Set<Selector>.from( | 28 Set<Selector> returnsElementTypeSet = new Set<Selector>.from( |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 compiler.log('Inferred $overallRefineCount types.'); | 466 compiler.log('Inferred $overallRefineCount types.'); |
466 | 467 |
467 processLoopInformation(); | 468 processLoopInformation(); |
468 } | 469 } |
469 | 470 |
470 void analyze(Element element) { | 471 void analyze(Element element) { |
471 element = element.implementation; | 472 element = element.implementation; |
472 if (analyzedElements.contains(element)) return; | 473 if (analyzedElements.contains(element)) return; |
473 analyzedElements.add(element); | 474 analyzedElements.add(element); |
474 | 475 |
475 SimpleTypeInferrerVisitor visitor = | 476 var visitor; |
476 new SimpleTypeInferrerVisitor(element, compiler, this); | 477 if (compiler.irBuilder.hasIr(element)) { |
| 478 visitor = new IrTypeInferrerVisitor(compiler, element, this); |
| 479 } else { |
| 480 visitor = new SimpleTypeInferrerVisitor(element, compiler, this); |
| 481 } |
477 TypeInformation type; | 482 TypeInformation type; |
478 compiler.withCurrentElement(element, () { | 483 compiler.withCurrentElement(element, () { |
479 type = visitor.run(); | 484 type = visitor.run(); |
480 }); | 485 }); |
481 addedInGraph++; | 486 addedInGraph++; |
482 | 487 |
483 if (element.isField()) { | 488 if (element.isField()) { |
484 Node node = element.parseNode(compiler); | 489 Node node = element.parseNode(compiler); |
485 if (element.modifiers.isFinal() || element.modifiers.isConst()) { | 490 if (element.modifiers.isFinal() || element.modifiers.isConst()) { |
486 // If [element] is final and has an initializer, we record | 491 // If [element] is final and has an initializer, we record |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 } | 682 } |
678 | 683 |
679 bool recordType(Element element, TypeInformation type) { | 684 bool recordType(Element element, TypeInformation type) { |
680 types.getInferredTypeOf(element).addAssignment(type); | 685 types.getInferredTypeOf(element).addAssignment(type); |
681 return false; | 686 return false; |
682 } | 687 } |
683 | 688 |
684 void recordReturnType(Element element, TypeInformation type) { | 689 void recordReturnType(Element element, TypeInformation type) { |
685 TypeInformation info = types.getInferredTypeOf(element); | 690 TypeInformation info = types.getInferredTypeOf(element); |
686 if (element.name == '==') { | 691 if (element.name == '==') { |
| 692 // Even if x.== doesn't return a bool, 'x == null' evaluates to 'false'. |
687 info.addAssignment(types.boolType); | 693 info.addAssignment(types.boolType); |
688 } | 694 } |
689 // TODO(ngeoffray): Clean up. We do these checks because | 695 // TODO(ngeoffray): Clean up. We do these checks because |
690 // [SimpleTypesInferrer] deals with two different inferrers. | 696 // [SimpleTypesInferrer] deals with two different inferrers. |
691 if (type == null) return; | 697 if (type == null) return; |
692 if (info.assignments.isEmpty) info.addAssignment(type); | 698 if (info.assignments.isEmpty) info.addAssignment(type); |
693 } | 699 } |
694 | 700 |
695 TypeInformation addReturnTypeFor(Element element, | 701 TypeInformation addReturnTypeFor(Element element, |
696 TypeInformation unused, | 702 TypeInformation unused, |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
934 count += set.length; | 940 count += set.length; |
935 if (count > 1) return false; | 941 if (count > 1) return false; |
936 } | 942 } |
937 return count == 1; | 943 return count == 1; |
938 } | 944 } |
939 | 945 |
940 void clear() { | 946 void clear() { |
941 inferrer.clear(); | 947 inferrer.clear(); |
942 } | 948 } |
943 } | 949 } |
OLD | NEW |