Skip to content

Commit 4bf5a34

Browse files
authored
Merge pull request #71208 from rjmccall/type-attributes
Rework the representation and handling of type attributes
2 parents c98d93d + 41cdfb0 commit 4bf5a34

36 files changed

+3131
-1333
lines changed

Diff for: include/swift/AST/ASTBridging.h

+4-5
Original file line numberDiff line numberDiff line change
@@ -1213,8 +1213,8 @@ enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedTypeAttrKind : size_t {
12131213
SWIFT_NAME("BridgedTypeAttrKind.init(from:)")
12141214
BridgedTypeAttrKind BridgedTypeAttrKind_fromString(BridgedStringRef cStr);
12151215

1216-
SWIFT_NAME("BridgedTypeAttributes.init()")
1217-
BridgedTypeAttributes BridgedTypeAttributes_create(void);
1216+
SWIFT_NAME("BridgedTypeAttributes.init(context:)")
1217+
BridgedTypeAttributes BridgedTypeAttributes_create(BridgedASTContext cContext);
12181218

12191219
SWIFT_NAME("BridgedTypeAttributes.addSimpleAttr(self:kind:atLoc:attrLoc:)")
12201220
void BridgedTypeAttributes_addSimpleAttr(BridgedTypeAttributes cAttributes,
@@ -1259,10 +1259,9 @@ BridgedArrayTypeRepr BridgedArrayTypeRepr_createParsed(
12591259
BridgedSourceLoc cLSquareLoc, BridgedSourceLoc cRSquareLoc);
12601260

12611261
SWIFT_NAME(
1262-
"BridgedAttributedTypeRepr.createParsed(_:base:consumingAttributes:)")
1262+
"BridgedAttributedTypeRepr.createParsed(base:consumingAttributes:)")
12631263
BridgedAttributedTypeRepr
1264-
BridgedAttributedTypeRepr_createParsed(BridgedASTContext cContext,
1265-
BridgedTypeRepr base,
1264+
BridgedAttributedTypeRepr_createParsed(BridgedTypeRepr base,
12661265
BridgedTypeAttributes cAttributes);
12671266

12681267
SWIFT_NAME("BridgedCompositionTypeRepr.createEmpty(_:anyKeywordLoc:)")

Diff for: include/swift/AST/Attr.def

+84-52
Original file line numberDiff line numberDiff line change
@@ -42,68 +42,97 @@
4242
DECL_ATTR_ALIAS(SPELLING, CLASS)
4343
#endif
4444

45+
// A type attribute that is both a simple type attribute and a
46+
// SIL type attribute (see below). Delegates to SIL_TYPE_ATTR if that
47+
// is set and SIMPLE_TYPE_ATTR is not; otherwise delegates to SIMPLE_TYPE_ATTR.
48+
#ifndef SIMPLE_SIL_TYPE_ATTR
49+
#ifdef SIL_TYPE_ATTR
50+
#ifdef SIMPLE_TYPE_ATTR
51+
#error ambiguous delegation, must set SIMPLE_SIL_TYPE_ATTR explicitly
52+
#else
53+
#define SIMPLE_SIL_TYPE_ATTR(SPELLING, CLASS) SIL_TYPE_ATTR(SPELLING, CLASS)
54+
#endif
55+
#else
56+
#define SIMPLE_SIL_TYPE_ATTR(SPELLING, CLASS) SIMPLE_TYPE_ATTR(SPELLING, CLASS)
57+
#endif
58+
#endif
59+
60+
// Any kind of type attribute.
4561
#ifndef TYPE_ATTR
46-
#define TYPE_ATTR(X)
62+
#define TYPE_ATTR(SPELLING, CLASS)
4763
#endif
4864

65+
// A type attribute that is only valid in SIL mode. Usually this means
66+
// that it's only valid in lowered types, but sometimes SIL files
67+
// also allow things in formal types that aren't normally expressible.
68+
#ifndef SIL_TYPE_ATTR
69+
#define SIL_TYPE_ATTR(SPELLING, CLASS) TYPE_ATTR(SPELLING, CLASS)
70+
#endif
71+
72+
// A type attribute that's always just spelled `@identifier` in source.
73+
#ifndef SIMPLE_TYPE_ATTR
74+
#define SIMPLE_TYPE_ATTR(SPELLING, CLASS) TYPE_ATTR(SPELLING, CLASS)
75+
#endif
76+
77+
4978
// Type attributes
50-
TYPE_ATTR(autoclosure)
51-
TYPE_ATTR(convention)
52-
TYPE_ATTR(noescape)
53-
TYPE_ATTR(escaping)
54-
TYPE_ATTR(differentiable)
55-
TYPE_ATTR(noDerivative)
56-
TYPE_ATTR(async)
57-
TYPE_ATTR(Sendable)
58-
TYPE_ATTR(retroactive)
59-
TYPE_ATTR(unchecked)
60-
TYPE_ATTR(preconcurrency)
61-
TYPE_ATTR(_local)
62-
TYPE_ATTR(_noMetadata)
63-
TYPE_ATTR(_opaqueReturnTypeOf)
79+
SIMPLE_TYPE_ATTR(autoclosure, Autoclosure)
80+
TYPE_ATTR(convention, Convention)
81+
SIMPLE_TYPE_ATTR(noescape, NoEscape)
82+
SIMPLE_TYPE_ATTR(escaping, Escaping)
83+
TYPE_ATTR(differentiable, Differentiable)
84+
SIMPLE_TYPE_ATTR(noDerivative, NoDerivative)
85+
SIMPLE_TYPE_ATTR(async, Async)
86+
SIMPLE_TYPE_ATTR(Sendable, Sendable)
87+
SIMPLE_TYPE_ATTR(retroactive, Retroactive)
88+
SIMPLE_TYPE_ATTR(unchecked, Unchecked)
89+
SIMPLE_TYPE_ATTR(preconcurrency, Preconcurrency)
90+
SIMPLE_TYPE_ATTR(_local, Local)
91+
SIMPLE_TYPE_ATTR(_noMetadata, NoMetadata)
92+
TYPE_ATTR(_opaqueReturnTypeOf, OpaqueReturnTypeOf)
6493

6594
// SIL-specific attributes
66-
TYPE_ATTR(block_storage)
67-
TYPE_ATTR(box)
68-
TYPE_ATTR(dynamic_self)
69-
#define REF_STORAGE(Name, name, ...) TYPE_ATTR(sil_##name)
95+
SIMPLE_SIL_TYPE_ATTR(block_storage, BlockStorage)
96+
SIMPLE_SIL_TYPE_ATTR(box, Box)
97+
SIMPLE_SIL_TYPE_ATTR(dynamic_self, DynamicSelf)
98+
#define REF_STORAGE(Name, name, ...) SIMPLE_TYPE_ATTR(sil_##name, SIL##Name)
7099
#include "swift/AST/ReferenceStorage.def"
71-
TYPE_ATTR(error)
72-
TYPE_ATTR(error_indirect)
73-
TYPE_ATTR(error_unowned)
74-
TYPE_ATTR(out)
75-
TYPE_ATTR(direct)
76-
TYPE_ATTR(in)
77-
TYPE_ATTR(inout)
78-
TYPE_ATTR(inout_aliasable)
79-
TYPE_ATTR(in_guaranteed)
80-
TYPE_ATTR(in_constant)
81-
TYPE_ATTR(pack_owned)
82-
TYPE_ATTR(pack_guaranteed)
83-
TYPE_ATTR(pack_inout)
84-
TYPE_ATTR(pack_out)
85-
TYPE_ATTR(owned)
86-
TYPE_ATTR(unowned_inner_pointer)
87-
TYPE_ATTR(guaranteed)
88-
TYPE_ATTR(autoreleased)
89-
TYPE_ATTR(callee_owned)
90-
TYPE_ATTR(callee_guaranteed)
91-
TYPE_ATTR(objc_metatype)
92-
TYPE_ATTR(opened)
93-
TYPE_ATTR(pack_element)
94-
TYPE_ATTR(pseudogeneric)
95-
TYPE_ATTR(unimplementable)
96-
TYPE_ATTR(yields)
97-
TYPE_ATTR(yield_once)
98-
TYPE_ATTR(yield_many)
99-
TYPE_ATTR(captures_generics)
100+
SIMPLE_SIL_TYPE_ATTR(error, Error)
101+
SIMPLE_SIL_TYPE_ATTR(error_indirect, ErrorIndirect)
102+
SIMPLE_SIL_TYPE_ATTR(error_unowned, ErrorUnowned)
103+
SIMPLE_SIL_TYPE_ATTR(out, Out)
104+
SIMPLE_SIL_TYPE_ATTR(direct, Direct)
105+
SIMPLE_SIL_TYPE_ATTR(in, In)
106+
SIMPLE_SIL_TYPE_ATTR(inout, Inout)
107+
SIMPLE_SIL_TYPE_ATTR(inout_aliasable, InoutAliasable)
108+
SIMPLE_SIL_TYPE_ATTR(in_guaranteed, InGuaranteed)
109+
SIMPLE_SIL_TYPE_ATTR(in_constant, InConstant)
110+
SIMPLE_SIL_TYPE_ATTR(pack_owned, PackOwned)
111+
SIMPLE_SIL_TYPE_ATTR(pack_guaranteed, PackGuaranteed)
112+
SIMPLE_SIL_TYPE_ATTR(pack_inout, PackInout)
113+
SIMPLE_SIL_TYPE_ATTR(pack_out, PackOut)
114+
SIMPLE_SIL_TYPE_ATTR(owned, Owned)
115+
SIMPLE_SIL_TYPE_ATTR(unowned_inner_pointer, UnownedInnerPointer)
116+
SIMPLE_SIL_TYPE_ATTR(guaranteed, Guaranteed)
117+
SIMPLE_SIL_TYPE_ATTR(autoreleased, Autoreleased)
118+
SIMPLE_SIL_TYPE_ATTR(callee_owned, CalleeOwned)
119+
SIMPLE_SIL_TYPE_ATTR(callee_guaranteed, CalleeGuaranteed)
120+
SIMPLE_SIL_TYPE_ATTR(objc_metatype, ObjCMetatype)
121+
SIL_TYPE_ATTR(opened, Opened)
122+
SIL_TYPE_ATTR(pack_element, PackElement)
123+
SIMPLE_SIL_TYPE_ATTR(pseudogeneric, Pseudogeneric)
124+
SIMPLE_SIL_TYPE_ATTR(unimplementable, Unimplementable)
125+
SIMPLE_SIL_TYPE_ATTR(yields, Yields)
126+
SIMPLE_SIL_TYPE_ATTR(yield_once, YieldOnce)
127+
SIMPLE_SIL_TYPE_ATTR(yield_many, YieldMany)
128+
SIMPLE_SIL_TYPE_ATTR(captures_generics, CapturesGenerics)
100129
// Used at the SIL level to mark a type as moveOnly.
101-
TYPE_ATTR(moveOnly)
102-
TYPE_ATTR(isolated)
130+
SIMPLE_SIL_TYPE_ATTR(moveOnly, MoveOnly)
131+
SIMPLE_SIL_TYPE_ATTR(isolated, Isolated)
103132

104133
// SIL metatype attributes.
105-
TYPE_ATTR(thin)
106-
TYPE_ATTR(thick)
134+
SIMPLE_SIL_TYPE_ATTR(thin, Thin)
135+
SIMPLE_SIL_TYPE_ATTR(thick, Thick)
107136

108137
// Declaration Attributes and Modifers
109138
DECL_ATTR(_silgen_name, SILGenName,
@@ -548,6 +577,9 @@ SIMPLE_DECL_ATTR(_noObjCBridging, NoObjCBridging,
548577
OnAbstractFunction | OnSubscript | UserInaccessible | ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove,
549578
155)
550579

580+
#undef SIMPLE_SIL_TYPE_ATTR
581+
#undef SIMPLE_TYPE_ATTR
582+
#undef SIL_TYPE_ATTR
551583
#undef TYPE_ATTR
552584
#undef DECL_ATTR_ALIAS
553585
#undef CONTEXTUAL_DECL_ATTR_ALIAS

0 commit comments

Comments
 (0)