@@ -1745,6 +1745,70 @@ class ParameterTypeFlags {
1745
1745
uint8_t toRaw () const { return value.toRaw (); }
1746
1746
};
1747
1747
1748
+ class YieldTypeFlags {
1749
+ enum YieldFlags : uint8_t {
1750
+ None = 0 ,
1751
+ InOut = 1 << 1 ,
1752
+ Shared = 1 << 2 ,
1753
+ Owned = 1 << 3 ,
1754
+
1755
+ NumBits = 3
1756
+ };
1757
+ OptionSet<YieldFlags> value;
1758
+
1759
+ static_assert (NumBits < 8 * sizeof (OptionSet<YieldFlags>), " overflowed" );
1760
+
1761
+ YieldTypeFlags (OptionSet<YieldFlags, uint8_t > val) : value(val) {}
1762
+
1763
+ public:
1764
+ YieldTypeFlags () = default ;
1765
+ static YieldTypeFlags fromRaw (uint8_t raw) {
1766
+ return YieldTypeFlags (OptionSet<YieldFlags>(raw));
1767
+ }
1768
+
1769
+ YieldTypeFlags (ValueOwnership ownership)
1770
+ : value((ownership == ValueOwnership::InOut ? InOut : 0 ) |
1771
+ (ownership == ValueOwnership::Shared ? Shared : 0 ) |
1772
+ (ownership == ValueOwnership::Owned ? Owned : 0 )) {}
1773
+
1774
+ bool isInOut () const { return value.contains (InOut); }
1775
+ bool isShared () const { return value.contains (Shared); }
1776
+ bool isOwned () const { return value.contains (Owned); }
1777
+
1778
+ ValueOwnership getValueOwnership () const {
1779
+ if (isInOut ())
1780
+ return ValueOwnership::InOut;
1781
+ else if (isShared ())
1782
+ return ValueOwnership::Shared;
1783
+ else if (isOwned ())
1784
+ return ValueOwnership::Owned;
1785
+
1786
+ return ValueOwnership::Default;
1787
+ }
1788
+
1789
+ YieldTypeFlags withInOut (bool isInout) const {
1790
+ return YieldTypeFlags (isInout ? value | InOut : value - InOut);
1791
+ }
1792
+
1793
+ YieldTypeFlags withShared (bool isShared) const {
1794
+ return YieldTypeFlags (isShared ? value | Shared : value - Shared);
1795
+ }
1796
+
1797
+ YieldTypeFlags withOwned (bool isOwned) const {
1798
+ return YieldTypeFlags (isOwned ? value | Owned : value - Owned);
1799
+ }
1800
+
1801
+ bool operator ==(const YieldTypeFlags &other) const {
1802
+ return value.toRaw () == other.value .toRaw ();
1803
+ }
1804
+
1805
+ bool operator !=(const YieldTypeFlags &other) const {
1806
+ return value.toRaw () != other.value .toRaw ();
1807
+ }
1808
+
1809
+ uint8_t toRaw () const { return value.toRaw (); }
1810
+ };
1811
+
1748
1812
// / ParenType - A paren type is a type that's been written in parentheses.
1749
1813
class ParenType : public SugarType {
1750
1814
friend class ASTContext ;
@@ -2560,7 +2624,7 @@ class AnyFunctionType : public TypeBase {
2560
2624
2561
2625
public:
2562
2626
using Representation = FunctionTypeRepresentation;
2563
-
2627
+
2564
2628
class Param {
2565
2629
public:
2566
2630
explicit Param (const TupleTypeElt &tte);
@@ -2635,6 +2699,50 @@ class AnyFunctionType : public TypeBase {
2635
2699
using CanParamArrayRef =
2636
2700
ArrayRefView<Param,CanParam,CanParam::getFromParam,/* AccessOriginal*/ true >;
2637
2701
2702
+ class CanYield ;
2703
+ class Yield {
2704
+ Type Ty;
2705
+ YieldTypeFlags Flags;
2706
+ public:
2707
+ explicit Yield (Type type, YieldTypeFlags flags)
2708
+ : Ty(type), Flags(flags) {}
2709
+
2710
+ Type getType () const { return Ty; }
2711
+
2712
+ YieldTypeFlags getFlags () const { return Flags; }
2713
+ ValueOwnership getValueOwnership () const {
2714
+ return getFlags ().getValueOwnership ();
2715
+ }
2716
+ bool isInOut () const { return getFlags ().isInOut (); }
2717
+
2718
+ CanYield getCanonical () const ;
2719
+
2720
+ Yield subst (SubstitutionMap subs, SubstOptions options = None) const {
2721
+ return Yield (getType ().subst (subs, options), getFlags ());
2722
+ }
2723
+
2724
+ bool operator ==(const Yield &other) const {
2725
+ return getType ()->isEqual (other.getType ()) &&
2726
+ getFlags () == other.getFlags ();
2727
+ }
2728
+ bool operator !=(const Yield &other) const {
2729
+ return !operator ==(other);
2730
+ }
2731
+ };
2732
+
2733
+ class CanYield : public Yield {
2734
+ public:
2735
+ explicit CanYield (CanType type, YieldTypeFlags flags)
2736
+ : Yield(type, flags) {}
2737
+
2738
+ CanType getType () const { return CanType (Yield::getType ()); }
2739
+
2740
+ CanYield subst (SubstitutionMap subs, SubstOptions options = None) const {
2741
+ return CanYield (getType ().subst (subs, options)->getCanonicalType (),
2742
+ getFlags ());
2743
+ }
2744
+ };
2745
+
2638
2746
// / \brief A class which abstracts out some details necessary for
2639
2747
// / making a call.
2640
2748
class ExtInfo {
@@ -2896,6 +3004,10 @@ BEGIN_CAN_TYPE_WRAPPER(AnyFunctionType, Type)
2896
3004
}
2897
3005
END_CAN_TYPE_WRAPPER (AnyFunctionType, Type)
2898
3006
3007
+ inline AnyFunctionType::CanYield AnyFunctionType::Yield::getCanonical() const {
3008
+ return CanYield (getType ()->getCanonicalType (), getFlags ());
3009
+ }
3010
+
2899
3011
// / FunctionType - A monomorphic function type, specified with an arrow.
2900
3012
// /
2901
3013
// / For example:
0 commit comments