| 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 compiler.src.inferrer.type_graph_nodes; | 5 library compiler.src.inferrer.type_graph_nodes; |
| 6 | 6 |
| 7 import 'dart:collection' show IterableBase; | 7 import 'dart:collection' show IterableBase; |
| 8 | 8 |
| 9 import '../common.dart'; | 9 import '../common.dart'; |
| 10 import '../common/names.dart' show Identifiers; | 10 import '../common/names.dart' show Identifiers; |
| (...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 * A node representing parameters: | 579 * A node representing parameters: |
| 580 * | 580 * |
| 581 * - Parameters | 581 * - Parameters |
| 582 * - Initializing formals | 582 * - Initializing formals |
| 583 * | 583 * |
| 584 * These should never be created directly but instead are constructed by | 584 * These should never be created directly but instead are constructed by |
| 585 * the [ElementTypeInformation] factory. | 585 * the [ElementTypeInformation] factory. |
| 586 */ | 586 */ |
| 587 class ParameterTypeInformation extends ElementTypeInformation { | 587 class ParameterTypeInformation extends ElementTypeInformation { |
| 588 ParameterElement get _parameter => super._element; | 588 ParameterElement get _parameter => super._element; |
| 589 final FunctionElement _declaration; | |
| 590 final MethodElement _method; | 589 final MethodElement _method; |
| 590 bool _isInstanceMemberParameter; |
| 591 bool _isClosureParameter; |
| 592 bool _isTearOffClosureParameter = false; |
| 591 | 593 |
| 592 ParameterTypeInformation.localFunction(MemberTypeInformation context, | 594 ParameterTypeInformation.localFunction( |
| 593 ParameterElement parameter, this._declaration, this._method) | 595 MemberTypeInformation context, ParameterElement parameter, this._method) |
| 594 : super._internal(context, parameter); | 596 : _isInstanceMemberParameter = false, |
| 597 _isClosureParameter = true, |
| 598 super._internal(context, parameter); |
| 595 | 599 |
| 596 ParameterTypeInformation.static( | 600 ParameterTypeInformation.static( |
| 597 MemberTypeInformation context, ParameterElement parameter, this._method) | 601 MemberTypeInformation context, ParameterElement parameter, this._method) |
| 598 : this._declaration = _method, | 602 : _isInstanceMemberParameter = false, |
| 603 _isClosureParameter = false, |
| 599 super._internal(context, parameter); | 604 super._internal(context, parameter); |
| 600 | 605 |
| 601 ParameterTypeInformation.instanceMember( | 606 ParameterTypeInformation.instanceMember( |
| 602 MemberTypeInformation context, | 607 MemberTypeInformation context, |
| 603 ParameterElement parameter, | 608 ParameterElement parameter, |
| 604 this._method, | 609 this._method, |
| 605 ParameterAssignments assignments) | 610 ParameterAssignments assignments) |
| 606 : this._declaration = _method, | 611 : _isInstanceMemberParameter = true, |
| 612 _isClosureParameter = false, |
| 607 super._withAssignments(context, parameter, assignments); | 613 super._withAssignments(context, parameter, assignments); |
| 608 | 614 |
| 609 MethodElement get method => _method; | 615 MethodElement get method => _method; |
| 610 | 616 |
| 611 Local get parameter => _parameter; | 617 Local get parameter => _parameter; |
| 612 | 618 |
| 613 String get debugName => '$parameter'; | 619 String get debugName => '$parameter'; |
| 614 | 620 |
| 615 bool isTearOffClosureParameter = false; | |
| 616 | |
| 617 void tagAsTearOffClosureParameter(InferrerEngine inferrer) { | 621 void tagAsTearOffClosureParameter(InferrerEngine inferrer) { |
| 618 assert(_parameter.isRegularParameter); | 622 assert(_parameter.isRegularParameter); |
| 619 isTearOffClosureParameter = true; | 623 _isTearOffClosureParameter = true; |
| 620 // We have to add a flow-edge for the default value (if it exists), as we | 624 // We have to add a flow-edge for the default value (if it exists), as we |
| 621 // might not see all call-sites and thus miss the use of it. | 625 // might not see all call-sites and thus miss the use of it. |
| 622 TypeInformation defaultType = | 626 TypeInformation defaultType = |
| 623 inferrer.getDefaultTypeOfParameter(_parameter); | 627 inferrer.getDefaultTypeOfParameter(_parameter); |
| 624 if (defaultType != null) defaultType.addUser(this); | 628 if (defaultType != null) defaultType.addUser(this); |
| 625 } | 629 } |
| 626 | 630 |
| 627 // TODO(herhut): Cleanup into one conditional. | 631 // TODO(herhut): Cleanup into one conditional. |
| 628 TypeMask handleSpecialCases(InferrerEngine inferrer) { | 632 TypeMask handleSpecialCases(InferrerEngine inferrer) { |
| 629 if (!inferrer.backend.canFunctionParametersBeUsedForGlobalOptimizations( | 633 if (!inferrer.backend.canFunctionParametersBeUsedForGlobalOptimizations( |
| 630 _method, inferrer.closedWorld) || | 634 _method, inferrer.closedWorld) || |
| 631 inferrer.assumeDynamic(_method)) { | 635 inferrer.assumeDynamic(_method)) { |
| 632 // Do not infer types for parameters that have a corresponding annotation | 636 // Do not infer types for parameters that have a corresponding annotation |
| 633 // or that are assigned by synthesized calls. | 637 // or that are assigned by synthesized calls. |
| 634 giveUp(inferrer); | 638 giveUp(inferrer); |
| 635 return safeType(inferrer); | 639 return safeType(inferrer); |
| 636 } | 640 } |
| 637 | 641 |
| 638 // The below do not apply to parameters of constructors, so skip | 642 // The below do not apply to parameters of constructors, so skip |
| 639 // initializing formals. | 643 // initializing formals. |
| 640 if (_parameter.isInitializingFormal) return null; | 644 if (_parameter.isInitializingFormal) return null; |
| 641 | 645 |
| 642 if ((isTearOffClosureParameter || _declaration.isLocal) && | 646 if ((_isTearOffClosureParameter || _isClosureParameter) && |
| 643 disableInferenceForClosures) { | 647 disableInferenceForClosures) { |
| 644 // Do not infer types for parameters of closures. We do not | 648 // Do not infer types for parameters of closures. We do not |
| 645 // clear the assignments in case the closure is successfully | 649 // clear the assignments in case the closure is successfully |
| 646 // traced. | 650 // traced. |
| 647 giveUp(inferrer, clearAssignments: false); | 651 giveUp(inferrer, clearAssignments: false); |
| 648 return safeType(inferrer); | 652 return safeType(inferrer); |
| 649 } | 653 } |
| 650 if (_declaration.isInstanceMember && | 654 if (_isInstanceMemberParameter && |
| 651 (_declaration.name == Identifiers.noSuchMethod_ || | 655 (_method.name == Identifiers.noSuchMethod_ || |
| 652 (_declaration.name == Identifiers.call && | 656 (_method.name == Identifiers.call && |
| 653 disableInferenceForClosures))) { | 657 disableInferenceForClosures))) { |
| 654 // Do not infer types for parameters of [noSuchMethod] and | 658 // Do not infer types for parameters of [noSuchMethod] and |
| 655 // [call] instance methods. | 659 // [call] instance methods. |
| 656 giveUp(inferrer); | 660 giveUp(inferrer); |
| 657 return safeType(inferrer); | 661 return safeType(inferrer); |
| 658 } | 662 } |
| 659 if (inferrer.closedWorldRefiner | 663 if (inferrer.closedWorldRefiner |
| 660 .getCurrentlyKnownMightBePassedToApply(_method)) { | 664 .getCurrentlyKnownMightBePassedToApply(_method)) { |
| 661 giveUp(inferrer); | 665 giveUp(inferrer); |
| 662 return safeType(inferrer); | 666 return safeType(inferrer); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 inferrer.types.computeTypeMask(assignments), inferrer); | 698 inferrer.types.computeTypeMask(assignments), inferrer); |
| 695 } | 699 } |
| 696 | 700 |
| 697 TypeMask safeType(InferrerEngine inferrer) { | 701 TypeMask safeType(InferrerEngine inferrer) { |
| 698 return potentiallyNarrowType(super.safeType(inferrer), inferrer); | 702 return potentiallyNarrowType(super.safeType(inferrer), inferrer); |
| 699 } | 703 } |
| 700 | 704 |
| 701 bool hasStableType(InferrerEngine inferrer) { | 705 bool hasStableType(InferrerEngine inferrer) { |
| 702 // The number of assignments of parameters of instance methods is | 706 // The number of assignments of parameters of instance methods is |
| 703 // not stable. Therefore such a parameter cannot be stable. | 707 // not stable. Therefore such a parameter cannot be stable. |
| 704 if (_declaration.isInstanceMember) { | 708 if (_isInstanceMemberParameter) { |
| 705 return false; | 709 return false; |
| 706 } | 710 } |
| 707 return super.hasStableType(inferrer); | 711 return super.hasStableType(inferrer); |
| 708 } | 712 } |
| 709 | 713 |
| 710 accept(TypeInformationVisitor visitor) { | 714 accept(TypeInformationVisitor visitor) { |
| 711 return visitor.visitParameterTypeInformation(this); | 715 return visitor.visitParameterTypeInformation(this); |
| 712 } | 716 } |
| 713 | 717 |
| 714 String toString() => 'ParameterElement $_parameter $type'; | 718 String toString() => 'ParameterElement $_parameter $type'; |
| (...skipping 1082 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1797 // TODO(ngeoffray): Narrow to bound. | 1801 // TODO(ngeoffray): Narrow to bound. |
| 1798 return type; | 1802 return type; |
| 1799 } else { | 1803 } else { |
| 1800 ResolutionInterfaceType interfaceType = annotation; | 1804 ResolutionInterfaceType interfaceType = annotation; |
| 1801 otherType = new TypeMask.nonNullSubtype(interfaceType.element, closedWorld); | 1805 otherType = new TypeMask.nonNullSubtype(interfaceType.element, closedWorld); |
| 1802 } | 1806 } |
| 1803 if (isNullable) otherType = otherType.nullable(); | 1807 if (isNullable) otherType = otherType.nullable(); |
| 1804 if (type == null) return otherType; | 1808 if (type == null) return otherType; |
| 1805 return type.intersection(otherType, closedWorld); | 1809 return type.intersection(otherType, closedWorld); |
| 1806 } | 1810 } |
| OLD | NEW |