Skip to content

Commit f0c4b6a

Browse files
authored
Merge pull request #20476 from slavapestov/remove-owning-addressors
AST: Remove owning addressors
2 parents 94dc4a6 + c7338d0 commit f0c4b6a

29 files changed

+74
-504
lines changed

docs/ABI/Mangling.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@ Entities
289289
ACCESSOR ::= 'p' // pseudo accessor referring to the storage itself
290290

291291
ADDRESSOR-KIND ::= 'u' // unsafe addressor (no owner)
292-
ADDRESSOR-KIND ::= 'O' // owning addressor (non-native owner)
293-
ADDRESSOR-KIND ::= 'o' // owning addressor (native owner)
292+
ADDRESSOR-KIND ::= 'O' // owning addressor (non-native owner), not used anymore
293+
ADDRESSOR-KIND ::= 'o' // owning addressor (native owner), not used anymore
294294
ADDRESSOR-KIND ::= 'p' // pinning addressor (native owner), not used anymore
295295

296296
decl-name ::= identifier

include/swift/AST/ASTMangler.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ class ASTMangler : public Mangler {
9292
bool isDestroyer, SymbolKind SKind);
9393

9494
std::string mangleAccessorEntity(AccessorKind kind,
95-
AddressorKind addressorKind,
9695
const AbstractStorageDecl *decl,
9796
bool isStatic,
9897
SymbolKind SKind);
@@ -162,7 +161,6 @@ class ASTMangler : public Mangler {
162161
std::string mangleDeclAsUSR(const ValueDecl *Decl, StringRef USRPrefix);
163162

164163
std::string mangleAccessorEntityAsUSR(AccessorKind kind,
165-
AddressorKind addressorKind,
166164
const AbstractStorageDecl *decl,
167165
StringRef USRPrefix);
168166

include/swift/AST/AccessorKinds.def

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -73,36 +73,31 @@
7373
#define COROUTINE_ACCESSOR(ID, KEYWORD) OPAQUE_ACCESSOR(ID, KEYWORD)
7474
#endif
7575

76-
/// ANY_ADDRESSOR(ACCESSOR_ID, ADDRESSOR_ID, KEYWORD)
76+
/// ANY_ADDRESSOR(ID, KEYWORD)
7777
/// The given keyword corresponds to an addressor of the given kind.
7878
///
79-
/// Defaults to ACCESSOR_KEYWORD(KEYWORD) if that is defined; otherwise
80-
/// defaults to nothing.
79+
/// Defaults to SINGLETON_ACCESSOR(ID, KEYWORD).
8180
#ifndef ANY_ADDRESSOR
82-
#if defined(ACCESSOR_KEYWORD)
83-
#define ANY_ADDRESSOR(ACCESSOR_ID, ADDRESSOR_ID, KEYWORD) \
84-
ACCESSOR_KEYWORD(KEYWORD)
85-
#else
86-
#define ANY_ADDRESSOR(ACCESSOR_ID, ADDRESSOR_ID, KEYWORD)
87-
#endif
81+
#define ANY_ADDRESSOR(ID, KEYWORD) \
82+
SINGLETON_ACCESSOR(ID, KEYWORD)
8883
#endif
8984

90-
/// IMMUTABLE_ADDRESSOR(ADDRESSOR_ID, KEYWORD)
85+
/// IMMUTABLE_ADDRESSOR(ID, KEYWORD)
9186
/// The given keyword corresponds to an immutable addressor of the given kind.
9287
///
93-
/// DEfaults to ANY_ADDRESSOR(Address, ADDRESSOR_ID, KEYWORD).
88+
/// DEfaults to ANY_ADDRESSOR(ID, KEYWORD).
9489
#ifndef IMMUTABLE_ADDRESSOR
95-
#define IMMUTABLE_ADDRESSOR(ADDRESSOR_ID, KEYWORD) \
96-
ANY_ADDRESSOR(Address, ADDRESSOR_ID, KEYWORD)
90+
#define IMMUTABLE_ADDRESSOR(ID, KEYWORD) \
91+
ANY_ADDRESSOR(ID, KEYWORD)
9792
#endif
9893

99-
/// MUTABLE_ADDRESSOR(ADDRESSOR_ID, KEYWORD)
94+
/// MUTABLE_ADDRESSOR(ID, KEYWORD)
10095
/// The given keyword corresponds to a mutable addressor of the given kind.
10196
///
102-
/// DEfaults to ANY_ADDRESSOR(MutableAddress, ADDRESSOR_ID, KEYWORD).
97+
/// DEfaults to ANY_ADDRESSOR(ID, KEYWORD).
10398
#ifndef MUTABLE_ADDRESSOR
104-
#define MUTABLE_ADDRESSOR(ADDRESSOR_ID, KEYWORD) \
105-
ANY_ADDRESSOR(MutableAddress, ADDRESSOR_ID, KEYWORD)
99+
#define MUTABLE_ADDRESSOR(ID, KEYWORD) \
100+
ANY_ADDRESSOR(ID, KEYWORD)
106101
#endif
107102

108103
// Suppress entries for accessors which can't be written in source code.
@@ -167,11 +162,7 @@ OBSERVING_ACCESSOR(DidSet, didSet)
167162
/// Addressors are a way of proving more efficient access to storage
168163
/// when it is already stored in memory (but not as a stored member
169164
/// of the type).
170-
ACCESSOR(Address)
171-
172-
IMMUTABLE_ADDRESSOR(Unsafe, unsafeAddress)
173-
IMMUTABLE_ADDRESSOR(Owning, addressWithOwner)
174-
IMMUTABLE_ADDRESSOR(NativeOwning, addressWithNativeOwner)
165+
IMMUTABLE_ADDRESSOR(Address, unsafeAddress)
175166

176167
/// This is a mutableAddress-family accessor: a function that is
177168
/// called when the storage is modified and which works by returning
@@ -181,11 +172,7 @@ IMMUTABLE_ADDRESSOR(NativeOwning, addressWithNativeOwner)
181172
/// Addressors are a way of proving more efficient access to storage
182173
/// when it is already stored in memory (but not as a stored member
183174
/// of the type).
184-
ACCESSOR(MutableAddress)
185-
186-
MUTABLE_ADDRESSOR(Unsafe, unsafeMutableAddress)
187-
MUTABLE_ADDRESSOR(Owning, mutableAddressWithOwner)
188-
MUTABLE_ADDRESSOR(NativeOwning, mutableAddressWithNativeOwner)
175+
MUTABLE_ADDRESSOR(MutableAddress, unsafeMutableAddress)
189176

190177
#ifdef LAST_ACCESSOR
191178
LAST_ACCESSOR(MutableAddress)

include/swift/AST/Decl.h

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -431,12 +431,9 @@ class alignas(1 << DeclAlignInBits) Decl {
431431
SelfAccess : 2
432432
);
433433

434-
SWIFT_INLINE_BITFIELD(AccessorDecl, FuncDecl, 4+3,
434+
SWIFT_INLINE_BITFIELD(AccessorDecl, FuncDecl, 4,
435435
/// The kind of accessor this is.
436-
AccessorKind : 4,
437-
438-
/// The kind of addressor this is.
439-
AddressorKind : 3
436+
AccessorKind : 4
440437
);
441438

442439
SWIFT_INLINE_BITFIELD(ConstructorDecl, AbstractFunctionDecl, 3+2+2+1,
@@ -5694,8 +5691,7 @@ class AccessorDecl final : public FuncDecl {
56945691
AbstractStorageDecl *Storage;
56955692

56965693
AccessorDecl(SourceLoc declLoc, SourceLoc accessorKeywordLoc,
5697-
AccessorKind accessorKind, AddressorKind addressorKind,
5698-
AbstractStorageDecl *storage,
5694+
AccessorKind accessorKind, AbstractStorageDecl *storage,
56995695
SourceLoc staticLoc, StaticSpellingKind staticSpelling,
57005696
bool throws, SourceLoc throwsLoc,
57015697
unsigned numParameterLists, GenericParamList *genericParams,
@@ -5707,14 +5703,12 @@ class AccessorDecl final : public FuncDecl {
57075703
AccessorKeywordLoc(accessorKeywordLoc),
57085704
Storage(storage) {
57095705
Bits.AccessorDecl.AccessorKind = unsigned(accessorKind);
5710-
Bits.AccessorDecl.AddressorKind = unsigned(addressorKind);
57115706
}
57125707

57135708
static AccessorDecl *createImpl(ASTContext &ctx,
57145709
SourceLoc declLoc,
57155710
SourceLoc accessorKeywordLoc,
57165711
AccessorKind accessorKind,
5717-
AddressorKind addressorKind,
57185712
AbstractStorageDecl *storage,
57195713
SourceLoc staticLoc,
57205714
StaticSpellingKind staticSpelling,
@@ -5728,7 +5722,6 @@ class AccessorDecl final : public FuncDecl {
57285722
SourceLoc declLoc,
57295723
SourceLoc accessorKeywordLoc,
57305724
AccessorKind accessorKind,
5731-
AddressorKind addressorKind,
57325725
AbstractStorageDecl *storage,
57335726
SourceLoc staticLoc,
57345727
StaticSpellingKind staticSpelling,
@@ -5739,7 +5732,6 @@ class AccessorDecl final : public FuncDecl {
57395732
static AccessorDecl *create(ASTContext &ctx, SourceLoc declLoc,
57405733
SourceLoc accessorKeywordLoc,
57415734
AccessorKind accessorKind,
5742-
AddressorKind addressorKind,
57435735
AbstractStorageDecl *storage,
57445736
SourceLoc staticLoc,
57455737
StaticSpellingKind staticSpelling,
@@ -5759,10 +5751,6 @@ class AccessorDecl final : public FuncDecl {
57595751
return AccessorKind(Bits.AccessorDecl.AccessorKind);
57605752
}
57615753

5762-
AddressorKind getAddressorKind() const {
5763-
return AddressorKind(Bits.AccessorDecl.AddressorKind);
5764-
}
5765-
57665754
bool isGetter() const { return getAccessorKind() == AccessorKind::Get; }
57675755
bool isSetter() const { return getAccessorKind() == AccessorKind::Set; }
57685756
bool isAnyAddressor() const {

include/swift/AST/StorageImpl.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,6 @@ static inline IntRange<AccessorKind> allAccessorKinds() {
5454
AccessorKind(NumAccessorKinds));
5555
}
5656

57-
/// The safety semantics of this addressor.
58-
enum class AddressorKind : uint8_t {
59-
/// \brief This is not an addressor.
60-
NotAddressor,
61-
/// \brief This is an unsafe addressor; it simply returns an address.
62-
Unsafe,
63-
/// \brief This is an owning addressor; it returns an AnyObject
64-
/// which should be released when the caller is done with the object.
65-
Owning,
66-
/// \brief This is an owning addressor; it returns a Builtin.NativeObject
67-
/// which should be released when the caller is done with the object.
68-
NativeOwning,
69-
};
70-
7157
/// Whether an access to storage is for reading, writing, or both.
7258
enum class AccessKind : uint8_t {
7359
/// The access is just to read the current value.

include/swift/Serialization/ModuleFormat.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5252
/// describe what change you made. The content of this comment isn't important;
5353
/// it just ensures a conflict if two people change the module format.
5454
/// Don't worry about adhering to the 80-column limit for this line.
55-
const uint16_t SWIFTMODULE_VERSION_MINOR = 464; // Last change: simplify GenericParamLists
55+
const uint16_t SWIFTMODULE_VERSION_MINOR = 465; // Last change: Remove owning addressors
5656

5757
using DeclIDField = BCFixed<31>;
5858

@@ -287,13 +287,6 @@ enum MetatypeRepresentation : uint8_t {
287287
};
288288
using MetatypeRepresentationField = BCFixed<2>;
289289

290-
// These IDs must \em not be renumbered or reordered without incrementing
291-
// the module version.
292-
enum class AddressorKind : uint8_t {
293-
NotAddressor, Unsafe, Owning, NativeOwning
294-
};
295-
using AddressorKindField = BCFixed<3>;
296-
297290
// These IDs must \em not be renumbered or reordered without incrementing
298291
// the module version.
299292
enum class SelfAccessKind : uint8_t {
@@ -1082,7 +1075,6 @@ namespace decls_block {
10821075
DeclIDField, // overridden function
10831076
DeclIDField, // AccessorStorageDecl
10841077
AccessorKindField, // accessor kind
1085-
AddressorKindField, // addressor kind
10861078
AccessLevelField, // access level
10871079
BCFixed<1>, // requires a new vtable slot
10881080
BCFixed<1>, // default argument resilience expansion

lib/AST/ASTDumper.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,6 @@ static StringRef getAccessorKindString(AccessorKind value) {
316316
#define SINGLETON_ACCESSOR(ID, KEYWORD) \
317317
case AccessorKind::ID: return #KEYWORD;
318318
#include "swift/AST/AccessorKinds.def"
319-
case AccessorKind::Address: return "address";
320-
case AccessorKind::MutableAddress: return "mutableAddress";
321319
}
322320

323321
llvm_unreachable("Unhandled AccessorKind in switch.");

lib/AST/ASTMangler.cpp

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@
4545
using namespace swift;
4646
using namespace swift::Mangle;
4747

48-
static StringRef getCodeForAccessorKind(AccessorKind kind,
49-
AddressorKind addressorKind) {
48+
static StringRef getCodeForAccessorKind(AccessorKind kind) {
5049
switch (kind) {
5150
case AccessorKind::Get:
5251
return "g";
@@ -62,29 +61,9 @@ static StringRef getCodeForAccessorKind(AccessorKind kind,
6261
return "M";
6362
case AccessorKind::Address:
6463
// 'l' is for location. 'A' was taken.
65-
switch (addressorKind) {
66-
case AddressorKind::NotAddressor:
67-
llvm_unreachable("bad combo");
68-
case AddressorKind::Unsafe:
69-
return "lu";
70-
case AddressorKind::Owning:
71-
return "lO";
72-
case AddressorKind::NativeOwning:
73-
return "lo";
74-
}
75-
llvm_unreachable("bad addressor kind");
64+
return "lu";
7665
case AccessorKind::MutableAddress:
77-
switch (addressorKind) {
78-
case AddressorKind::NotAddressor:
79-
llvm_unreachable("bad combo");
80-
case AddressorKind::Unsafe:
81-
return "au";
82-
case AddressorKind::Owning:
83-
return "aO";
84-
case AddressorKind::NativeOwning:
85-
return "ao";
86-
}
87-
llvm_unreachable("bad addressor kind");
66+
return "au";
8867
}
8968
llvm_unreachable("bad accessor kind");
9069
}
@@ -139,13 +118,11 @@ std::string ASTMangler::mangleIVarInitDestroyEntity(const ClassDecl *decl,
139118
}
140119

141120
std::string ASTMangler::mangleAccessorEntity(AccessorKind kind,
142-
AddressorKind addressorKind,
143121
const AbstractStorageDecl *decl,
144122
bool isStatic,
145123
SymbolKind SKind) {
146124
beginMangling();
147-
appendAccessorEntity(getCodeForAccessorKind(kind, addressorKind), decl,
148-
isStatic);
125+
appendAccessorEntity(getCodeForAccessorKind(kind), decl, isStatic);
149126
appendSymbolKind(SKind);
150127
return finalize();
151128
}
@@ -513,14 +490,12 @@ std::string ASTMangler::mangleDeclAsUSR(const ValueDecl *Decl,
513490
}
514491

515492
std::string ASTMangler::mangleAccessorEntityAsUSR(AccessorKind kind,
516-
AddressorKind addressorKind,
517493
const AbstractStorageDecl *decl,
518494
StringRef USRPrefix) {
519495
beginManglingWithoutPrefix();
520496
llvm::SaveAndRestore<bool> allowUnnamedRAII(AllowNamelessEntities, true);
521497
Buffer << USRPrefix;
522-
appendAccessorEntity(getCodeForAccessorKind(kind, addressorKind), decl,
523-
/*isStatic*/ false);
498+
appendAccessorEntity(getCodeForAccessorKind(kind), decl, /*isStatic*/ false);
524499
// We have a custom prefix, so finalize() won't verify for us. Do it manually.
525500
verify(Storage.str().drop_front(USRPrefix.size()));
526501
return finalize();
@@ -2224,8 +2199,7 @@ void ASTMangler::appendEntity(const ValueDecl *decl) {
22242199
// declaration.
22252200
if (auto accessor = dyn_cast<AccessorDecl>(decl)) {
22262201
return appendAccessorEntity(
2227-
getCodeForAccessorKind(accessor->getAccessorKind(),
2228-
accessor->getAddressorKind()),
2202+
getCodeForAccessorKind(accessor->getAccessorKind()),
22292203
accessor->getStorage(), accessor->isStatic());
22302204
}
22312205

lib/AST/ASTPrinter.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,26 +1595,6 @@ static StringRef getAccessorLabel(AccessorDecl *accessor) {
15951595
case AccessorKind::ID: return #KEYWORD;
15961596
#define ACCESSOR(ID)
15971597
#include "swift/AST/AccessorKinds.def"
1598-
1599-
case AccessorKind::Address:
1600-
switch (accessor->getAddressorKind()) {
1601-
case AddressorKind::NotAddressor: llvm_unreachable("bad combination");
1602-
#define IMMUTABLE_ADDRESSOR(ID, KEYWORD) \
1603-
case AddressorKind::ID: return #KEYWORD;
1604-
#define ACCESSOR(ID)
1605-
#include "swift/AST/AccessorKinds.def"
1606-
}
1607-
llvm_unreachable("bad addressor kind");
1608-
1609-
case AccessorKind::MutableAddress:
1610-
switch (accessor->getAddressorKind()) {
1611-
case AddressorKind::NotAddressor: llvm_unreachable("bad combination");
1612-
#define MUTABLE_ADDRESSOR(ID, KEYWORD) \
1613-
case AddressorKind::ID: return #KEYWORD;
1614-
#define ACCESSOR(ID)
1615-
#include "swift/AST/AccessorKinds.def"
1616-
}
1617-
llvm_unreachable("bad addressor kind");
16181598
}
16191599
llvm_unreachable("bad accessor kind");
16201600
}

lib/AST/ASTVerifier.cpp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3172,28 +3172,6 @@ class Verifier : public ASTWalker {
31723172
abort();
31733173
}
31743174

3175-
switch (FD->getAccessorKind()) {
3176-
case AccessorKind::Get:
3177-
case AccessorKind::Set:
3178-
case AccessorKind::WillSet:
3179-
case AccessorKind::DidSet:
3180-
case AccessorKind::Read:
3181-
case AccessorKind::Modify:
3182-
if (FD->getAddressorKind() != AddressorKind::NotAddressor) {
3183-
Out << "non-addressor accessor has an addressor kind\n";
3184-
abort();
3185-
}
3186-
break;
3187-
3188-
case AccessorKind::Address:
3189-
case AccessorKind::MutableAddress:
3190-
if (FD->getAddressorKind() == AddressorKind::NotAddressor) {
3191-
Out << "addressor does not have an addressor kind\n";
3192-
abort();
3193-
}
3194-
break;
3195-
}
3196-
31973175
verifyCheckedBase(FD);
31983176
}
31993177

0 commit comments

Comments
 (0)