Skip to content

Commit 38d1ca4

Browse files
committed
Add flags to specify @abi behavior of attributes
This PR adds a set of DeclAttr.def flags for specifying how a given attribute interacts with `@abi`, and declares a behavior for each existing attribute. Future attributes will be *required* to declare an `@abi` behavior lest they fail a static assert. Note that the behavior is not actually enforced in this commit—it is merely specified here.
1 parent 862d630 commit 38d1ca4

File tree

3 files changed

+194
-156
lines changed

3 files changed

+194
-156
lines changed

include/swift/AST/Attr.h

+35
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,41 @@ class DeclAttribute : public AttributeBase {
364364

365365
/// The opposite of ABIBreakingToRemove
366366
ABIStableToRemove = 1ull << 15,
367+
368+
/// Attribute should not be used in an \c \@abi attribute. Use for
369+
/// attributes which cannot affect mangled names, even indirectly, and
370+
/// which either don't affect ABI or where ABI-only declarations get their
371+
/// behavior from their API counterpart.
372+
ForbiddenInABIAttr = 1ull << 16,
373+
374+
/// Attribute can be used without restrictions in an \c \@abi attribute.
375+
/// Use for attributes which affect mangled names but otherwise don't alter
376+
/// the ABI, or ones where the \c ABIDeclChecker manually implements
377+
/// special checking logic (e.g. because several different attributes
378+
/// contribute to the same aspect of ABI in some complicated way).
379+
UnconstrainedInABIAttr = 1ull << 17,
380+
381+
/// Attribute can be used in an \c \@abi attribute, but must match
382+
/// equivalent on API decl. Use for attributes which affect both mangled
383+
/// names and other parts of the ABI such that the declaration can only be
384+
/// valid if they match.
385+
EquivalentInABIAttr = 1ull << 18,
386+
387+
/// Attribute can be used in an \c \@abi attribute, but must match
388+
/// equivalent on API decl; if omitted, API decl's attribute will be
389+
/// cloned. Use where you would want to use \c EquivalentInABIAttr but
390+
/// repeating the attribute is judged too burdensome.
391+
InferredInABIAttr = 1ull << 19,
392+
393+
/// Use for attributes which are \em only valid on declarations that cannot
394+
/// have an \c @abi attribute, such as \c ImportDecl .
395+
UnreachableInABIAttr = 1ull << 20,
396+
};
397+
398+
enum : uint64_t {
399+
InABIAttrMask = ForbiddenInABIAttr | UnconstrainedInABIAttr
400+
| EquivalentInABIAttr | InferredInABIAttr
401+
| UnreachableInABIAttr
367402
};
368403

369404
LLVM_READNONE

0 commit comments

Comments
 (0)