@@ -136,6 +136,11 @@ enum : unsigned {
136136 InheritActorContextModifier::Last_InheritActorContextKind))
137137};
138138
139+ enum : unsigned {
140+ NumNonexhaustiveModeBits = countBitsUsed (
141+ static_cast <unsigned >(NonexhaustiveMode::Last_NonexhaustiveMode))
142+ };
143+
139144enum : unsigned { NumDeclAttrKindBits = countBitsUsed (NumDeclAttrKinds - 1 ) };
140145
141146enum : unsigned { NumTypeAttrKindBits = countBitsUsed (NumTypeAttrKinds - 1 ) };
@@ -277,6 +282,10 @@ class DeclAttribute : public AttributeBase {
277282 SWIFT_INLINE_BITFIELD (LifetimeAttr, DeclAttribute, 1 ,
278283 isUnderscored : 1
279284 );
285+
286+ SWIFT_INLINE_BITFIELD (NonexhaustiveAttr, DeclAttribute, NumNonexhaustiveModeBits,
287+ mode : NumNonexhaustiveModeBits
288+ );
280289 } Bits;
281290 // clang-format on
282291
@@ -2925,7 +2934,7 @@ class BackDeployedAttr : public DeclAttribute {
29252934 : DeclAttribute(DeclAttrKind::BackDeployed, AtLoc, Range, Implicit),
29262935 Platform (Platform), Version(Version) {}
29272936
2928- // / The platform the symbol is available for back deployment on .
2937+ // / The platform the decl is available for back deployment in .
29292938 const PlatformKind Platform;
29302939
29312940 // / The earliest platform version that may use the back deployed implementation.
@@ -2934,6 +2943,12 @@ class BackDeployedAttr : public DeclAttribute {
29342943 // / Returns true if this attribute is active given the current platform.
29352944 bool isActivePlatform (const ASTContext &ctx, bool forTargetVariant) const ;
29362945
2946+ // / Returns the `AvailabilityDomain` that the decl is available for back
2947+ // / deployment in.
2948+ AvailabilityDomain getAvailabilityDomain () const {
2949+ return AvailabilityDomain::forPlatform (Platform);
2950+ }
2951+
29372952 static bool classof (const DeclAttribute *DA) {
29382953 return DA->getKind () == DeclAttrKind::BackDeployed;
29392954 }
@@ -3500,6 +3515,36 @@ class ABIAttr : public DeclAttribute {
35003515 }
35013516};
35023517
3518+ // / Defines a @nonexhaustive attribute.
3519+ class NonexhaustiveAttr : public DeclAttribute {
3520+ public:
3521+ NonexhaustiveAttr (SourceLoc atLoc, SourceRange range, NonexhaustiveMode mode,
3522+ bool implicit = false )
3523+ : DeclAttribute(DeclAttrKind::Nonexhaustive, atLoc, range, implicit) {
3524+ Bits.NonexhaustiveAttr .mode = unsigned (mode);
3525+ }
3526+
3527+ NonexhaustiveAttr (NonexhaustiveMode mode)
3528+ : NonexhaustiveAttr(SourceLoc(), SourceRange(), mode) {}
3529+
3530+ NonexhaustiveMode getMode () const {
3531+ return NonexhaustiveMode (Bits.NonexhaustiveAttr .mode );
3532+ }
3533+
3534+ static bool classof (const DeclAttribute *DA) {
3535+ return DA->getKind () == DeclAttrKind::Nonexhaustive;
3536+ }
3537+
3538+ NonexhaustiveAttr *clone (ASTContext &ctx) const {
3539+ return new (ctx) NonexhaustiveAttr (AtLoc, Range, getMode (), isImplicit ());
3540+ }
3541+
3542+ bool isEquivalent (const NonexhaustiveAttr *other, Decl *attachedTo) const {
3543+ return getMode () == other->getMode ();
3544+ }
3545+ };
3546+
3547+
35033548// / The kind of unary operator, if any.
35043549enum class UnaryOperatorKind : uint8_t { None, Prefix, Postfix };
35053550
0 commit comments