Skip to content

Commit 3e9923f

Browse files
committed
ASTBridging: Bridge swift::AccessorKind directly
1 parent b334c8e commit 3e9923f

23 files changed

+128
-121
lines changed

include/swift/AST/ASTBridging.h

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2022 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2022 - 2025 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -19,6 +19,8 @@
1919
// Pure bridging mode does not permit including any C++/llvm/swift headers.
2020
// See also the comments for `BRIDGING_MODE` in the top-level CMakeLists.txt file.
2121
//
22+
23+
#include "swift/AST/AccessorKind.h"
2224
#include "swift/AST/DiagnosticKind.h"
2325
#include "swift/Basic/BasicBridging.h"
2426

@@ -524,13 +526,6 @@ struct BridgedPatternBindingEntry {
524526
BridgedNullablePatternBindingInitializer initContext;
525527
};
526528

527-
enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedAccessorKind {
528-
#define ACCESSOR(ID) BridgedAccessorKind##ID,
529-
#include "swift/AST/AccessorKinds.def"
530-
};
531-
532-
swift::AccessorKind unbridged(BridgedAccessorKind kind);
533-
534529
//===----------------------------------------------------------------------===//
535530
// MARK: Diagnostic Engine
536531
//===----------------------------------------------------------------------===//
@@ -971,7 +966,7 @@ BridgedDerivativeAttr BridgedDerivativeAttr_createParsed(
971966
BridgedASTContext cContext, BridgedSourceLoc cAtLoc,
972967
BridgedSourceRange cRange, BridgedNullableTypeRepr cBaseType,
973968
BridgedDeclNameRef cOriginalName, BridgedDeclNameLoc cOriginalNameLoc,
974-
BridgedAccessorKind cAccessorKind, BridgedArrayRef cParams);
969+
swift::AccessorKind AccessorKind, BridgedArrayRef cParams);
975970

976971
SWIFT_NAME("BridgedDerivativeAttr.createParsed(_:atLoc:range:baseType:"
977972
"originalName:originalNameLoc:params:)")
@@ -1450,7 +1445,7 @@ SWIFT_NAME("BridgedAccessorDecl.createParsed(_:declContext:kind:storage:"
14501445
"throwsSpecifierLoc:thrownType:)")
14511446
BridgedAccessorDecl BridgedAccessorDecl_createParsed(
14521447
BridgedASTContext cContext, BridgedDeclContext cDeclContext,
1453-
BridgedAccessorKind cKind, BridgedAbstractStorageDecl cStorage,
1448+
swift::AccessorKind Kind, BridgedAbstractStorageDecl cStorage,
14541449
BridgedSourceLoc cDeclLoc, BridgedSourceLoc cAccessorKeywordLoc,
14551450
BridgedNullableParameterList cParamList, BridgedSourceLoc cAsyncLoc,
14561451
BridgedSourceLoc cThrowsLoc, BridgedNullableTypeRepr cThrownType);

include/swift/AST/AccessorKind.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//===-- AST/AccessorKind.h --------------------------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2025 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef SWIFT_AST_ACCESSOR_KIND_H
14+
#define SWIFT_AST_ACCESSOR_KIND_H
15+
16+
/// This header is included in a bridging header. Be *very* careful with what
17+
/// you include here! See include caveats in `ASTBridging.h`.
18+
#include "swift/Basic/SwiftBridging.h"
19+
20+
namespace swift {
21+
22+
// Note that the values of these enums line up with %select values in
23+
// diagnostics.
24+
enum class ENUM_EXTENSIBILITY_ATTR(closed) AccessorKind {
25+
#define ACCESSOR(ID, KEYWORD) ID SWIFT_NAME(#KEYWORD),
26+
#define LAST_ACCESSOR(ID) Last = ID
27+
#include "swift/AST/AccessorKinds.def"
28+
#undef ACCESSOR
29+
#undef LAST_ACCESSOR
30+
};
31+
32+
} // namespace swift
33+
34+
#endif // SWIFT_AST_ACCESSOR_KIND_H

include/swift/AST/AccessorKinds.def

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -20,22 +20,22 @@
2020
#error must define either ACCESSOR or ACCESSOR_KEYWORD
2121
#endif
2222

23-
/// ACCESSOR(ID)
23+
/// ACCESSOR(ID, KEYWORD)
2424
/// There is an accessor with the enumerator value AccessorKind::ID.
2525
#if !defined(ACCESSOR) && defined(ACCESSOR_KEYWORD)
26-
#define ACCESSOR(ID)
26+
#define ACCESSOR(ID, KEYWORD)
2727
#endif
2828

2929
/// SINGLETON_ACCESSOR(ID, KEYWORD)
3030
/// The given accessor has only one matching accessor keyword.
3131
///
32-
/// Defaults to ACCESSOR(ID) or ACCESSOR_KEYWORD(KEYWORD), depending on which
33-
/// is defined.
32+
/// Defaults to ACCESSOR(ID, KEYWORD) or ACCESSOR_KEYWORD(KEYWORD), depending
33+
/// on which is defined.
3434
#ifndef SINGLETON_ACCESSOR
3535
#if defined(ACCESSOR_KEYWORD)
3636
#define SINGLETON_ACCESSOR(ID, KEYWORD) ACCESSOR_KEYWORD(KEYWORD)
3737
#else
38-
#define SINGLETON_ACCESSOR(ID, KEYWORD) ACCESSOR(ID)
38+
#define SINGLETON_ACCESSOR(ID, KEYWORD) ACCESSOR(ID, KEYWORD)
3939
#endif
4040
#endif
4141

include/swift/AST/Decl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -8629,7 +8629,7 @@ class AccessorDecl final : public FuncDecl {
86298629
switch (getAccessorKind()) {
86308630
#define OBSERVING_ACCESSOR(ID, KEYWORD) \
86318631
case AccessorKind::ID: return true;
8632-
#define ACCESSOR(ID) \
8632+
#define ACCESSOR(ID, KEYWORD) \
86338633
case AccessorKind::ID: return false;
86348634
#include "swift/AST/AccessorKinds.def"
86358635
}
@@ -8652,7 +8652,7 @@ class AccessorDecl final : public FuncDecl {
86528652
switch (getAccessorKind()) {
86538653
#define COROUTINE_ACCESSOR(ID, KEYWORD) \
86548654
case AccessorKind::ID: return true;
8655-
#define ACCESSOR(ID) \
8655+
#define ACCESSOR(ID, KEYWORD) \
86568656
case AccessorKind::ID: return false;
86578657
#include "swift/AST/AccessorKinds.def"
86588658
}

include/swift/AST/StorageImpl.h

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -18,6 +18,7 @@
1818
#ifndef SWIFT_STORAGEIMPL_H
1919
#define SWIFT_STORAGEIMPL_H
2020

21+
#include "swift/AST/AccessorKind.h"
2122
#include "swift/Basic/Range.h"
2223
#include "llvm/ADT/StringRef.h"
2324

@@ -47,16 +48,6 @@ enum class OpaqueReadOwnership : uint8_t {
4748
OwnedOrBorrowed
4849
};
4950

50-
// Note that the values of these enums line up with %select values in
51-
// diagnostics.
52-
enum class AccessorKind {
53-
#define ACCESSOR(ID) ID,
54-
#define LAST_ACCESSOR(ID) Last = ID
55-
#include "swift/AST/AccessorKinds.def"
56-
#undef ACCESSOR
57-
#undef LAST_ACCESSOR
58-
};
59-
6051
inline bool requiresFeatureCoroutineAccessors(AccessorKind kind) {
6152
switch (kind) {
6253
case AccessorKind::Read2:
@@ -144,7 +135,7 @@ static inline IntRange<AccessorKind> allAccessorKinds() {
144135
static inline llvm::StringRef accessorKindName(AccessorKind ak) {
145136
switch(ak) {
146137

147-
#define ACCESSOR(ID) ID
138+
#define ACCESSOR(ID, KEYWORD) ID
148139
#define SINGLETON_ACCESSOR(ID, KEYWORD) \
149140
case AccessorKind::ID: \
150141
return #KEYWORD;

lib/APIDigester/ModuleAnalyzerNodes.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ SDKNode* SDKNode::constructSDKNode(SDKContext &Ctx,
752752
AccessorKind unknownKind = (AccessorKind)((uint8_t)(AccessorKind::Last) + 1);
753753
Info.AccKind = llvm::StringSwitch<AccessorKind>(
754754
GetScalarString(Pair.getValue()))
755-
#define ACCESSOR(ID)
755+
#define ACCESSOR(ID, KEYWORD)
756756
#define SINGLETON_ACCESSOR(ID, KEYWORD) .Case(#KEYWORD, AccessorKind::ID)
757757
#include "swift/AST/AccessorKinds.def"
758758
.Default(unknownKind);
@@ -1165,8 +1165,9 @@ static StringRef getSimpleName(ValueDecl *VD) {
11651165
}
11661166
if (auto *AD = dyn_cast<AccessorDecl>(VD)) {
11671167
switch(AD->getAccessorKind()) {
1168-
#define ACCESSOR(ID) \
1169-
case AccessorKind::ID: return #ID;
1168+
#define ACCESSOR(ID, KEYWORD) \
1169+
case AccessorKind::ID: \
1170+
return #ID;
11701171
#include "swift/AST/AccessorKinds.def"
11711172
}
11721173
}
@@ -2267,7 +2268,7 @@ struct ScalarEnumerationTraits<DeclKind> {
22672268
template<>
22682269
struct ScalarEnumerationTraits<AccessorKind> {
22692270
static void enumeration(Output &out, AccessorKind &value) {
2270-
#define ACCESSOR(ID)
2271+
#define ACCESSOR(ID, KEYWORD)
22712272
#define SINGLETON_ACCESSOR(ID, KEYWORD) \
22722273
out.enumCase(value, #KEYWORD, AccessorKind::ID);
22732274
#include "swift/AST/AccessorKinds.def"

lib/AST/ASTDumper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -6748,7 +6748,7 @@ void GenericEnvironment::dump() const {
67486748

67496749
StringRef swift::getAccessorKindString(AccessorKind value) {
67506750
switch (value) {
6751-
#define ACCESSOR(ID)
6751+
#define ACCESSOR(ID, KEYWORD)
67526752
#define SINGLETON_ACCESSOR(ID, KEYWORD) \
67536753
case AccessorKind::ID: return #KEYWORD;
67546754
#include "swift/AST/AccessorKinds.def"

lib/AST/Bridging/DeclAttributeBridging.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2022-2024 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2022-2025 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -267,10 +267,7 @@ BridgedDerivativeAttr BridgedDerivativeAttr_createParsedImpl(
267267
BridgedASTContext cContext, BridgedSourceLoc cAtLoc,
268268
BridgedSourceRange cRange, BridgedNullableTypeRepr cBaseType,
269269
BridgedDeclNameRef cOriginalName, BridgedDeclNameLoc cOriginalNameLoc,
270-
std::optional<BridgedAccessorKind> cAccessorKind, BridgedArrayRef cParams) {
271-
std::optional<AccessorKind> accessorKind;
272-
if (cAccessorKind)
273-
accessorKind = unbridged(*cAccessorKind);
270+
std::optional<swift::AccessorKind> AccessorKind, BridgedArrayRef cParams) {
274271
SmallVector<ParsedAutoDiffParameter, 2> params;
275272
for (auto &elem : cParams.unbridged<BridgedParsedAutoDiffParameter>())
276273
params.push_back(elem.unbridged());
@@ -280,18 +277,18 @@ BridgedDerivativeAttr BridgedDerivativeAttr_createParsedImpl(
280277
cRange.unbridged(), cBaseType.unbridged(),
281278
DeclNameRefWithLoc{cOriginalName.unbridged(),
282279
cOriginalNameLoc.unbridged(),
283-
accessorKind},
280+
AccessorKind},
284281
params);
285282
}
286283

287284
BridgedDerivativeAttr BridgedDerivativeAttr_createParsed(
288285
BridgedASTContext cContext, BridgedSourceLoc cAtLoc,
289286
BridgedSourceRange cRange, BridgedNullableTypeRepr cBaseType,
290287
BridgedDeclNameRef cOriginalName, BridgedDeclNameLoc cOriginalNameLoc,
291-
BridgedAccessorKind cAccessorKind, BridgedArrayRef cParams) {
288+
swift::AccessorKind AccessorKind, BridgedArrayRef cParams) {
292289
return BridgedDerivativeAttr_createParsedImpl(
293290
cContext, cAtLoc, cRange, cBaseType, cOriginalName, cOriginalNameLoc,
294-
cAccessorKind, cParams);
291+
AccessorKind, cParams);
295292
}
296293

297294
BridgedDerivativeAttr BridgedDerivativeAttr_createParsed(

lib/AST/Bridging/DeclBridging.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2022-2024 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2022-2025 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -129,10 +129,6 @@ static StaticSpellingKind unbridged(BridgedStaticSpelling kind) {
129129
return static_cast<StaticSpellingKind>(kind);
130130
}
131131

132-
AccessorKind unbridged(BridgedAccessorKind kind) {
133-
return static_cast<AccessorKind>(kind);
134-
}
135-
136132
void BridgedDecl_attachParsedAttrs(BridgedDecl decl,
137133
BridgedDeclAttributes attrs) {
138134
decl.unbridged()->attachParsedAttrs(attrs.unbridged());
@@ -148,15 +144,15 @@ void BridgedDecl_forEachDeclToHoist(BridgedDecl cDecl,
148144

149145
BridgedAccessorDecl BridgedAccessorDecl_createParsed(
150146
BridgedASTContext cContext, BridgedDeclContext cDeclContext,
151-
BridgedAccessorKind cKind, BridgedAbstractStorageDecl cStorage,
147+
swift::AccessorKind Kind, BridgedAbstractStorageDecl cStorage,
152148
BridgedSourceLoc cDeclLoc, BridgedSourceLoc cAccessorKeywordLoc,
153149
BridgedNullableParameterList cParamList, BridgedSourceLoc cAsyncLoc,
154150
BridgedSourceLoc cThrowsLoc, BridgedNullableTypeRepr cThrownType) {
155151
return AccessorDecl::createParsed(
156-
cContext.unbridged(), unbridged(cKind), cStorage.unbridged(),
157-
cDeclLoc.unbridged(), cAccessorKeywordLoc.unbridged(),
158-
cParamList.unbridged(), cAsyncLoc.unbridged(), cThrowsLoc.unbridged(),
159-
cThrownType.unbridged(), cDeclContext.unbridged());
152+
cContext.unbridged(), Kind, cStorage.unbridged(), cDeclLoc.unbridged(),
153+
cAccessorKeywordLoc.unbridged(), cParamList.unbridged(),
154+
cAsyncLoc.unbridged(), cThrowsLoc.unbridged(), cThrownType.unbridged(),
155+
cDeclContext.unbridged());
160156
}
161157

162158
static VarDecl::Introducer unbridged(BridgedVarDeclIntroducer introducer) {

lib/AST/Decl.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -3379,8 +3379,7 @@ bool AbstractStorageDecl::requiresOpaqueAccessor(AccessorKind kind) const {
33793379

33803380
// Other accessors are never part of the opaque-accessors set.
33813381
#define OPAQUE_ACCESSOR(ID, KEYWORD)
3382-
#define ACCESSOR(ID) \
3383-
case AccessorKind::ID:
3382+
#define ACCESSOR(ID, KEYWORD) case AccessorKind::ID:
33843383
#include "swift/AST/AccessorKinds.def"
33853384
return false;
33863385
}
@@ -7623,7 +7622,7 @@ void AbstractStorageDecl::setAccessors(SourceLoc lbraceLoc,
76237622
// Compute the number of opaque accessors.
76247623
const size_t NumOpaqueAccessors =
76257624
0
7626-
#define ACCESSOR(ID)
7625+
#define ACCESSOR(ID, KEYWORD)
76277626
#define OPAQUE_ACCESSOR(ID, KEYWORD) \
76287627
+ 1
76297628
#include "swift/AST/AccessorKinds.def"
@@ -7646,14 +7645,14 @@ AbstractStorageDecl::AccessorRecord::create(ASTContext &ctx,
76467645
// Make sure that we have enough space to add implicit opaque accessors later.
76477646
size_t numMissingOpaque = NumOpaqueAccessors;
76487647
{
7649-
#define ACCESSOR(ID)
7648+
#define ACCESSOR(ID, KEYWORD)
76507649
#define OPAQUE_ACCESSOR(ID, KEYWORD) \
76517650
bool has##ID = false;
76527651
#include "swift/AST/AccessorKinds.def"
76537652
for (auto accessor : accessors) {
76547653
switch (accessor->getAccessorKind()) {
7655-
#define ACCESSOR(ID) \
7656-
case AccessorKind::ID: \
7654+
#define ACCESSOR(ID, KEYWORD) \
7655+
case AccessorKind::ID: \
76577656
continue;
76587657
#define OPAQUE_ACCESSOR(ID, KEYWORD) \
76597658
case AccessorKind::ID: \
@@ -12214,10 +12213,10 @@ StringRef swift::getAccessorLabel(AccessorKind kind) {
1221412213
switch (kind) {
1221512214
#define SINGLETON_ACCESSOR(ID, KEYWORD) \
1221612215
case AccessorKind::ID: return #KEYWORD;
12217-
#define ACCESSOR(ID)
12218-
#include "swift/AST/AccessorKinds.def"
12219-
}
12220-
llvm_unreachable("bad accessor kind");
12216+
#define ACCESSOR(ID, KEYWORD)
12217+
#include "swift/AST/AccessorKinds.def"
12218+
}
12219+
llvm_unreachable("bad accessor kind");
1222112220
}
1222212221

1222312222
void swift::simple_display(llvm::raw_ostream &out, AccessorKind kind) {

0 commit comments

Comments
 (0)