Skip to content

Commit 07bb038

Browse files
committed
[AST] Use class names for type attribute kind enum
Align with DeclAttrKind.
1 parent 55e565d commit 07bb038

22 files changed

+211
-206
lines changed

include/swift/APIDigester/ModuleAnalyzerNodes.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,9 @@ class SDKNodeTypeNominal : public SDKNodeType {
492492
class SDKNodeTypeFunc : public SDKNodeType {
493493
public:
494494
SDKNodeTypeFunc(SDKNodeInitInfo Info);
495-
bool isEscaping() const { return hasTypeAttribute(TypeAttrKind::TAK_noescape); }
495+
bool isEscaping() const {
496+
return hasTypeAttribute(TypeAttrKind::TAK_NoEscape);
497+
}
496498
static bool classof(const SDKNode *N);
497499
void diagnose(SDKNode *Right) override;
498500
};

include/swift/AST/ASTBridging.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1440,9 +1440,9 @@ void BridgedStmt_dump(BridgedStmt statement);
14401440

14411441
// Bridged type attribute kinds, which mirror TypeAttrKind exactly.
14421442
enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedTypeAttrKind {
1443-
#define TYPE_ATTR(SPELLING, _) BridgedTypeAttrKind_##SPELLING,
1443+
#define TYPE_ATTR(_, CLASS) BridgedTypeAttrKind##CLASS,
14441444
#include "swift/AST/Attr.def"
1445-
BridgedTypeAttrKind_None,
1445+
BridgedTypeAttrKindNone,
14461446
};
14471447

14481448
SWIFT_NAME("BridgedTypeAttrKind.init(from:)")

include/swift/AST/Attr.h

+8-7
Original file line numberDiff line numberDiff line change
@@ -3041,11 +3041,11 @@ class SimpleTypeAttr : public Base {
30413041
template <TypeAttrKind Kind>
30423042
using SimpleTypeAttrWithArgs = SimpleTypeAttr<Kind, AtTypeAttrWithArgsBase>;
30433043

3044-
#define SIMPLE_TYPE_ATTR(SPELLING, CLASS) \
3045-
using CLASS##TypeAttr = SimpleTypeAttr<TAK_##SPELLING>;
3044+
#define SIMPLE_TYPE_ATTR(SPELLING, CLASS) \
3045+
using CLASS##TypeAttr = SimpleTypeAttr<TAK_##CLASS>;
30463046
#include "swift/AST/Attr.def"
30473047

3048-
class ConventionTypeAttr : public SimpleTypeAttrWithArgs<TAK_convention> {
3048+
class ConventionTypeAttr : public SimpleTypeAttrWithArgs<TAK_Convention> {
30493049
Located<StringRef> Name;
30503050
DeclNameRef WitnessMethodProtocol;
30513051
Located<StringRef> ClangType;
@@ -3075,7 +3075,8 @@ class ConventionTypeAttr : public SimpleTypeAttrWithArgs<TAK_convention> {
30753075
void printImpl(ASTPrinter &printer, const PrintOptions &options) const;
30763076
};
30773077

3078-
class DifferentiableTypeAttr : public SimpleTypeAttrWithArgs<TAK_differentiable> {
3078+
class DifferentiableTypeAttr
3079+
: public SimpleTypeAttrWithArgs<TAK_Differentiable> {
30793080
SourceLoc DifferentiabilityLoc;
30803081
public:
30813082
DifferentiableTypeAttr(SourceLoc atLoc, SourceLoc kwLoc,
@@ -3105,7 +3106,7 @@ class DifferentiableTypeAttr : public SimpleTypeAttrWithArgs<TAK_differentiable>
31053106
};
31063107

31073108
class OpaqueReturnTypeOfTypeAttr
3108-
: public SimpleTypeAttrWithArgs<TAK__opaqueReturnTypeOf> {
3109+
: public SimpleTypeAttrWithArgs<TAK_OpaqueReturnTypeOf> {
31093110
Located<StringRef> MangledName;
31103111
SourceLoc IndexLoc;
31113112
public:
@@ -3124,7 +3125,7 @@ class OpaqueReturnTypeOfTypeAttr
31243125
void printImpl(ASTPrinter &printer, const PrintOptions &options) const;
31253126
};
31263127

3127-
class OpenedTypeAttr : public SimpleTypeAttrWithArgs<TAK_opened> {
3128+
class OpenedTypeAttr : public SimpleTypeAttrWithArgs<TAK_Opened> {
31283129
Located<UUID> ID;
31293130
TypeRepr *ConstraintType;
31303131
public:
@@ -3146,7 +3147,7 @@ class OpenedTypeAttr : public SimpleTypeAttrWithArgs<TAK_opened> {
31463147
void printImpl(ASTPrinter &printer, const PrintOptions &options) const;
31473148
};
31483149

3149-
class PackElementTypeAttr : public SimpleTypeAttrWithArgs<TAK_pack_element> {
3150+
class PackElementTypeAttr : public SimpleTypeAttrWithArgs<TAK_PackElement> {
31503151
Located<UUID> ID;
31513152
public:
31523153
PackElementTypeAttr(SourceLoc atLoc, SourceLoc kwLoc, SourceRange parensRange,

include/swift/AST/AttrKind.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,14 @@ enum DeclAttrKind : unsigned {
139139
enum : unsigned { NumDeclAttrKindBits =
140140
countBitsUsed(static_cast<unsigned>(DeclAttrKind::DAK_Count - 1)) };
141141

142-
// Define enumerators for each type attribute, e.g. TAK_weak.
142+
// Define enumerators for each type attribute, e.g. TAK_Weak.
143143
enum TypeAttrKind {
144-
#define TYPE_ATTR(X, C) TAK_##X,
144+
#define TYPE_ATTR(_, C) TAK_##C,
145145
#include "swift/AST/Attr.def"
146146
};
147147

148148
enum : unsigned {
149-
#define TYPE_ATTR(X, C) _counting_TAK_##X,
149+
#define TYPE_ATTR(_, C) _counting_TAK_##C,
150150
#include "swift/AST/Attr.def"
151151
NumTypeAttrKinds,
152152

lib/APIDigester/ModuleAnalyzerNodes.cpp

+11-7
Original file line numberDiff line numberDiff line change
@@ -708,11 +708,11 @@ SDKNode* SDKNode::constructSDKNode(SDKContext &Ctx,
708708
case KeyKind::KK_typeAttributes: {
709709
auto *Seq = cast<llvm::yaml::SequenceNode>(Pair.getValue());
710710
for (auto &N : *Seq) {
711-
auto Result =
712-
llvm::StringSwitch<llvm::Optional<TypeAttrKind>>(GetScalarString(&N))
713-
#define TYPE_ATTR(X, C) .Case(#X, TAK_##X)
714-
#include "swift/AST/Attr.def"
715-
.Default(llvm::Optional<TypeAttrKind>());
711+
auto Result = llvm::StringSwitch<llvm::Optional<TypeAttrKind>>(
712+
GetScalarString(&N))
713+
#define TYPE_ATTR(X, C) .Case(#X, TAK_##C)
714+
#include "swift/AST/Attr.def"
715+
.Default(llvm::None);
716716

717717
if (!Result)
718718
Ctx.diagnose(&N, diag::sdk_node_unrecognized_type_attr_kind,
@@ -1379,7 +1379,7 @@ SDKNodeInitInfo::SDKNodeInitInfo(SDKContext &Ctx, Type Ty, TypeInitInfo Info) :
13791379
ParamValueOwnership(Info.ValueOwnership),
13801380
HasDefaultArg(Info.hasDefaultArgument) {
13811381
if (isFunctionTypeNoEscape(Ty))
1382-
TypeAttrs.push_back(TypeAttrKind::TAK_noescape);
1382+
TypeAttrs.push_back(TypeAttrKind::TAK_NoEscape);
13831383
// If this is a nominal type, get its Usr.
13841384
if (auto *ND = Ty->getAnyNominal()) {
13851385
Usr = calculateUsr(Ctx, ND);
@@ -2226,14 +2226,18 @@ namespace json {
22262226
template<>
22272227
struct ScalarEnumerationTraits<TypeAttrKind> {
22282228
static void enumeration(Output &out, TypeAttrKind &value) {
2229-
#define TYPE_ATTR(X, C) out.enumCase(value, #X, TypeAttrKind::TAK_##X);
2229+
// NOTE: For historical reasons. TypeAttribute uses the spelling, but
2230+
// DeclAttribute uses the kind name.
2231+
#define TYPE_ATTR(X, C) out.enumCase(value, #X, TypeAttrKind::TAK_##C);
22302232
#include "swift/AST/Attr.def"
22312233
}
22322234
};
22332235

22342236
template<>
22352237
struct ScalarEnumerationTraits<DeclAttrKind> {
22362238
static void enumeration(Output &out, DeclAttrKind &value) {
2239+
// NOTE: For historical reasons. TypeAttribute uses the spelling, but
2240+
// DeclAttribute uses the kind name.
22372241
#define DECL_ATTR(_, Name, ...) out.enumCase(value, #Name, DeclAttrKind::DAK_##Name);
22382242
#include "swift/AST/Attr.def"
22392243
}

lib/AST/ASTBridging.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -1944,22 +1944,22 @@ BridgedYieldStmt BridgedYieldStmt_createParsed(BridgedASTContext cContext,
19441944
BridgedTypeAttrKind BridgedTypeAttrKind_fromString(BridgedStringRef cStr) {
19451945
auto optKind = TypeAttribute::getAttrKindFromString(cStr.unbridged());
19461946
if (!optKind)
1947-
return BridgedTypeAttrKind_None;
1947+
return BridgedTypeAttrKindNone;
19481948
switch (*optKind) {
1949-
#define TYPE_ATTR(SPELLING, _) \
1950-
case TAK_##SPELLING: \
1951-
return BridgedTypeAttrKind_##SPELLING;
1949+
#define TYPE_ATTR(_, CLASS) \
1950+
case TAK_##CLASS: \
1951+
return BridgedTypeAttrKind##CLASS;
19521952
#include "swift/AST/Attr.def"
19531953
}
19541954
}
19551955

19561956
static llvm::Optional<TypeAttrKind> unbridged(BridgedTypeAttrKind kind) {
19571957
switch (kind) {
1958-
#define TYPE_ATTR(SPELLING, _) \
1959-
case BridgedTypeAttrKind_##SPELLING: \
1960-
return TAK_##SPELLING;
1958+
#define TYPE_ATTR(_, CLASS) \
1959+
case BridgedTypeAttrKind##CLASS: \
1960+
return TAK_##CLASS;
19611961
#include "swift/AST/Attr.def"
1962-
case BridgedTypeAttrKind_None:
1962+
case BridgedTypeAttrKindNone:
19631963
return llvm::None;
19641964
}
19651965
llvm_unreachable("unhandled enum value");

lib/AST/ASTPrinter.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -2693,7 +2693,7 @@ void PrintAST::printInherited(const Decl *decl) {
26932693
if (inherited.isUnchecked())
26942694
Printer << "@unchecked ";
26952695
if (inherited.isRetroactive() &&
2696-
!llvm::is_contained(Options.ExcludeAttrList, TAK_retroactive))
2696+
!llvm::is_contained(Options.ExcludeAttrList, TAK_Retroactive))
26972697
Printer << "@retroactive ";
26982698
if (inherited.isPreconcurrency())
26992699
Printer << "@preconcurrency ";
@@ -3690,7 +3690,7 @@ static void suppressingFeatureRetroactiveAttribute(
36903690
PrintOptions &options,
36913691
llvm::function_ref<void()> action) {
36923692
llvm::SaveAndRestore<PrintOptions> originalOptions(options);
3693-
options.ExcludeAttrList.push_back(TAK_retroactive);
3693+
options.ExcludeAttrList.push_back(TAK_Retroactive);
36943694
action();
36953695
}
36963696

@@ -4533,9 +4533,9 @@ static void printParameterFlags(ASTPrinter &printer,
45334533
const ParamDecl *param,
45344534
ParameterTypeFlags flags,
45354535
bool escaping) {
4536-
if (!options.excludeAttrKind(TAK_autoclosure) && flags.isAutoClosure())
4536+
if (!options.excludeAttrKind(TAK_Autoclosure) && flags.isAutoClosure())
45374537
printer.printAttrName("@autoclosure ");
4538-
if (!options.excludeAttrKind(TAK_noDerivative) && flags.isNoDerivative())
4538+
if (!options.excludeAttrKind(TAK_NoDerivative) && flags.isNoDerivative())
45394539
printer.printAttrName("@noDerivative ");
45404540
if (flags.isTransferring())
45414541
printer.printAttrName("@transferring ");
@@ -4570,7 +4570,7 @@ static void printParameterFlags(ASTPrinter &printer,
45704570
if (flags.hasResultDependsOn())
45714571
printer.printKeyword("_resultDependsOn", options, " ");
45724572

4573-
if (!options.excludeAttrKind(TAK_escaping) && escaping)
4573+
if (!options.excludeAttrKind(TAK_Escaping) && escaping)
45744574
printer.printKeyword("@escaping", options, " ");
45754575

45764576
if (flags.isCompileTimeConst())
@@ -5021,7 +5021,7 @@ void PrintAST::printEnumElement(EnumElementDecl *elt) {
50215021

50225022
// @escaping is not valid in enum element position, even though the
50235023
// attribute is implicitly added. Ignore it when printing the parameters.
5024-
Options.ExcludeAttrList.push_back(TAK_escaping);
5024+
Options.ExcludeAttrList.push_back(TAK_Escaping);
50255025
printParameterList(PL, params,
50265026
/*isAPINameByDefault*/true);
50275027
Options.ExcludeAttrList.pop_back();
@@ -6883,7 +6883,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
68836883
if (Options.SkipAttributes)
68846884
return;
68856885

6886-
if (!Options.excludeAttrKind(TAK_differentiable)) {
6886+
if (!Options.excludeAttrKind(TAK_Differentiable)) {
68876887
switch (info.getDifferentiabilityKind()) {
68886888
case DifferentiabilityKind::Normal:
68896889
Printer << "@differentiable ";
@@ -6919,7 +6919,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
69196919
return;
69206920
case PrintOptions::FunctionRepresentationMode::Full:
69216921
case PrintOptions::FunctionRepresentationMode::NameOnly:
6922-
if (Options.excludeAttrKind(TAK_convention) ||
6922+
if (Options.excludeAttrKind(TAK_Convention) ||
69236923
info.getSILRepresentation() == SILFunctionType::Representation::Thick)
69246924
return;
69256925

@@ -6988,7 +6988,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
69886988
if (Options.SkipAttributes)
69896989
return;
69906990

6991-
if (!Options.excludeAttrKind(TAK_differentiable)) {
6991+
if (!Options.excludeAttrKind(TAK_Differentiable)) {
69926992
switch (info.getDifferentiabilityKind()) {
69936993
case DifferentiabilityKind::Normal:
69946994
Printer << "@differentiable ";
@@ -7013,7 +7013,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
70137013
break;
70147014
case PrintOptions::FunctionRepresentationMode::NameOnly:
70157015
case PrintOptions::FunctionRepresentationMode::Full:
7016-
if (Options.excludeAttrKind(TAK_convention) ||
7016+
if (Options.excludeAttrKind(TAK_Convention) ||
70177017
info.getRepresentation() == SILFunctionType::Representation::Thick)
70187018
break;
70197019

lib/AST/Attr.cpp

+22-21
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ StringRef swift::getAccessLevelSpelling(AccessLevel value) {
8383

8484
SourceLoc TypeAttribute::getStartLoc() const {
8585
switch (getKind()) {
86-
#define TYPE_ATTR(SPELLING, CLASS) \
87-
case TAK_ ## SPELLING: \
86+
#define TYPE_ATTR(_, CLASS) \
87+
case TAK_##CLASS: \
8888
return static_cast<const CLASS##TypeAttr *>(this)->getStartLocImpl();
8989
#include "swift/AST/Attr.def"
9090
}
@@ -93,8 +93,8 @@ SourceLoc TypeAttribute::getStartLoc() const {
9393

9494
SourceLoc TypeAttribute::getEndLoc() const {
9595
switch (getKind()) {
96-
#define TYPE_ATTR(SPELLING, CLASS) \
97-
case TAK_ ## SPELLING: \
96+
#define TYPE_ATTR(_, CLASS) \
97+
case TAK_##CLASS: \
9898
return static_cast<const CLASS##TypeAttr *>(this)->getEndLocImpl();
9999
#include "swift/AST/Attr.def"
100100
}
@@ -103,10 +103,10 @@ SourceLoc TypeAttribute::getEndLoc() const {
103103

104104
SourceRange TypeAttribute::getSourceRange() const {
105105
switch (getKind()) {
106-
#define TYPE_ATTR(SPELLING, CLASS) \
107-
case TAK_ ## SPELLING: { \
108-
auto attr = static_cast<const CLASS##TypeAttr *>(this); \
109-
return SourceRange(attr->getStartLocImpl(), attr->getEndLocImpl()); \
106+
#define TYPE_ATTR(_, CLASS) \
107+
case TAK_##CLASS: { \
108+
auto attr = static_cast<const CLASS##TypeAttr *>(this); \
109+
return SourceRange(attr->getStartLocImpl(), attr->getEndLocImpl()); \
110110
}
111111
#include "swift/AST/Attr.def"
112112
}
@@ -119,15 +119,17 @@ SourceRange TypeAttribute::getSourceRange() const {
119119
llvm::Optional<TypeAttrKind>
120120
TypeAttribute::getAttrKindFromString(StringRef Str) {
121121
return llvm::StringSwitch<llvm::Optional<TypeAttrKind>>(Str)
122-
#define TYPE_ATTR(X, C) .Case(#X, TAK_##X)
122+
#define TYPE_ATTR(X, C) .Case(#X, TAK_##C)
123123
#include "swift/AST/Attr.def"
124-
.Default(llvm::Optional<TypeAttrKind>());
124+
.Default(llvm::None);
125125
}
126126

127127
/// Return the name (like "autoclosure") for an attribute ID.
128128
const char *TypeAttribute::getAttrName(TypeAttrKind kind) {
129129
switch (kind) {
130-
#define TYPE_ATTR(X, C) case TAK_##X: return #X;
130+
#define TYPE_ATTR(X, C) \
131+
case TAK_##C: \
132+
return #X;
131133
#include "swift/AST/Attr.def"
132134
}
133135
llvm_unreachable("unknown type attribute kind");
@@ -142,11 +144,11 @@ TypeAttribute *TypeAttribute::createSimple(const ASTContext &context,
142144
// The simple cases should all be doing the exact same thing, and we
143145
// can reasonably hope that the optimizer will unify them so that this
144146
// function doesn't actually need a switch.
145-
#define TYPE_ATTR(SPELLING, CLASS) \
146-
case TAK_##SPELLING: \
147+
#define TYPE_ATTR(SPELLING, CLASS) \
148+
case TAK_##CLASS: \
147149
llvm_unreachable("not a simple attribute");
148-
#define SIMPLE_TYPE_ATTR(SPELLING, CLASS) \
149-
case TAK_##SPELLING: \
150+
#define SIMPLE_TYPE_ATTR(SPELLING, CLASS) \
151+
case TAK_##CLASS: \
150152
return new (context) CLASS##TypeAttr(atLoc, attrLoc);
151153
#include "swift/AST/Attr.def"
152154
}
@@ -162,17 +164,16 @@ void TypeAttribute::dump() const {
162164
void TypeAttribute::print(ASTPrinter &printer,
163165
const PrintOptions &options) const {
164166
switch (getKind()) {
165-
#define TYPE_ATTR(SPELLING, CLASS)
166-
#define SIMPLE_TYPE_ATTR(SPELLING, CLASS) \
167-
case TAK_ ## SPELLING:
167+
#define TYPE_ATTR(_, CLASS)
168+
#define SIMPLE_TYPE_ATTR(_, CLASS) case TAK_##CLASS:
168169
#include "swift/AST/Attr.def"
169170
printer.printSimpleAttr(getAttrName(getKind()), /*needAt*/ true);
170171
return;
171172

172-
#define TYPE_ATTR(SPELLING, CLASS) \
173-
case TAK_ ## SPELLING: \
173+
#define TYPE_ATTR(_, CLASS) \
174+
case TAK_##CLASS: \
174175
return cast<CLASS##TypeAttr>(this)->printImpl(printer, options);
175-
#define SIMPLE_TYPE_ATTR(SPELLING, C)
176+
#define SIMPLE_TYPE_ATTR(_, C)
176177
#include "swift/AST/Attr.def"
177178
}
178179
llvm_unreachable("bad kind");

lib/AST/Decl.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1553,9 +1553,9 @@ InheritedEntry::InheritedEntry(const TypeLoc &typeLoc)
15531553
: InheritedEntry(typeLoc, /*isUnchecked=*/false, /*isRetroactive=*/false,
15541554
/*isPreconcurrency=*/false) {
15551555
if (auto typeRepr = typeLoc.getTypeRepr()) {
1556-
IsUnchecked = typeRepr->findAttrLoc(TAK_unchecked).isValid();
1557-
IsRetroactive = typeRepr->findAttrLoc(TAK_retroactive).isValid();
1558-
IsPreconcurrency = typeRepr->findAttrLoc(TAK_preconcurrency).isValid();
1556+
IsUnchecked = typeRepr->findAttrLoc(TAK_Unchecked).isValid();
1557+
IsRetroactive = typeRepr->findAttrLoc(TAK_Retroactive).isValid();
1558+
IsPreconcurrency = typeRepr->findAttrLoc(TAK_Preconcurrency).isValid();
15591559
}
15601560
}
15611561

lib/AST/NameLookup.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -3692,8 +3692,8 @@ void swift::getDirectlyInheritedNominalTypeDecls(
36923692
auto inheritedTypes = InheritedTypes(decl);
36933693
if (TypeRepr *typeRepr = inheritedTypes.getTypeRepr(i)) {
36943694
loc = typeRepr->getLoc();
3695-
uncheckedLoc = typeRepr->findAttrLoc(TAK_unchecked);
3696-
preconcurrencyLoc = typeRepr->findAttrLoc(TAK_preconcurrency);
3695+
uncheckedLoc = typeRepr->findAttrLoc(TAK_Unchecked);
3696+
preconcurrencyLoc = typeRepr->findAttrLoc(TAK_Preconcurrency);
36973697
}
36983698

36993699
// Form the result.

lib/AST/TypeRepr.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,9 @@ ReferenceOwnership AttributedTypeRepr::getSILOwnership() const {
222222
auto typeAttr = attr.dyn_cast<TypeAttribute*>();
223223
if (!typeAttr) continue;
224224
switch (typeAttr->getKind()) {
225-
#define REF_STORAGE(Name, name, ...) \
226-
case TAK_sil_##name: return ReferenceOwnership::Name;
225+
#define REF_STORAGE(Name, name, ...) \
226+
case TAK_SIL##Name: \
227+
return ReferenceOwnership::Name;
227228
#include "swift/AST/ReferenceStorage.def"
228229
default: continue;
229230
}

0 commit comments

Comments
 (0)