Skip to content

AST: Remove owning addressors #20476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/ABI/Mangling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ Entities
ACCESSOR ::= 'p' // pseudo accessor referring to the storage itself

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

decl-name ::= identifier
Expand Down
2 changes: 0 additions & 2 deletions include/swift/AST/ASTMangler.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ class ASTMangler : public Mangler {
bool isDestroyer, SymbolKind SKind);

std::string mangleAccessorEntity(AccessorKind kind,
AddressorKind addressorKind,
const AbstractStorageDecl *decl,
bool isStatic,
SymbolKind SKind);
Expand Down Expand Up @@ -162,7 +161,6 @@ class ASTMangler : public Mangler {
std::string mangleDeclAsUSR(const ValueDecl *Decl, StringRef USRPrefix);

std::string mangleAccessorEntityAsUSR(AccessorKind kind,
AddressorKind addressorKind,
const AbstractStorageDecl *decl,
StringRef USRPrefix);

Expand Down
41 changes: 14 additions & 27 deletions include/swift/AST/AccessorKinds.def
Original file line number Diff line number Diff line change
Expand Up @@ -73,36 +73,31 @@
#define COROUTINE_ACCESSOR(ID, KEYWORD) OPAQUE_ACCESSOR(ID, KEYWORD)
#endif

/// ANY_ADDRESSOR(ACCESSOR_ID, ADDRESSOR_ID, KEYWORD)
/// ANY_ADDRESSOR(ID, KEYWORD)
/// The given keyword corresponds to an addressor of the given kind.
///
/// Defaults to ACCESSOR_KEYWORD(KEYWORD) if that is defined; otherwise
/// defaults to nothing.
/// Defaults to SINGLETON_ACCESSOR(ID, KEYWORD).
#ifndef ANY_ADDRESSOR
#if defined(ACCESSOR_KEYWORD)
#define ANY_ADDRESSOR(ACCESSOR_ID, ADDRESSOR_ID, KEYWORD) \
ACCESSOR_KEYWORD(KEYWORD)
#else
#define ANY_ADDRESSOR(ACCESSOR_ID, ADDRESSOR_ID, KEYWORD)
#endif
#define ANY_ADDRESSOR(ID, KEYWORD) \
SINGLETON_ACCESSOR(ID, KEYWORD)
#endif

/// IMMUTABLE_ADDRESSOR(ADDRESSOR_ID, KEYWORD)
/// IMMUTABLE_ADDRESSOR(ID, KEYWORD)
/// The given keyword corresponds to an immutable addressor of the given kind.
///
/// DEfaults to ANY_ADDRESSOR(Address, ADDRESSOR_ID, KEYWORD).
/// DEfaults to ANY_ADDRESSOR(ID, KEYWORD).
#ifndef IMMUTABLE_ADDRESSOR
#define IMMUTABLE_ADDRESSOR(ADDRESSOR_ID, KEYWORD) \
ANY_ADDRESSOR(Address, ADDRESSOR_ID, KEYWORD)
#define IMMUTABLE_ADDRESSOR(ID, KEYWORD) \
ANY_ADDRESSOR(ID, KEYWORD)
#endif

/// MUTABLE_ADDRESSOR(ADDRESSOR_ID, KEYWORD)
/// MUTABLE_ADDRESSOR(ID, KEYWORD)
/// The given keyword corresponds to a mutable addressor of the given kind.
///
/// DEfaults to ANY_ADDRESSOR(MutableAddress, ADDRESSOR_ID, KEYWORD).
/// DEfaults to ANY_ADDRESSOR(ID, KEYWORD).
#ifndef MUTABLE_ADDRESSOR
#define MUTABLE_ADDRESSOR(ADDRESSOR_ID, KEYWORD) \
ANY_ADDRESSOR(MutableAddress, ADDRESSOR_ID, KEYWORD)
#define MUTABLE_ADDRESSOR(ID, KEYWORD) \
ANY_ADDRESSOR(ID, KEYWORD)
#endif

// Suppress entries for accessors which can't be written in source code.
Expand Down Expand Up @@ -167,11 +162,7 @@ OBSERVING_ACCESSOR(DidSet, didSet)
/// Addressors are a way of proving more efficient access to storage
/// when it is already stored in memory (but not as a stored member
/// of the type).
ACCESSOR(Address)

IMMUTABLE_ADDRESSOR(Unsafe, unsafeAddress)
IMMUTABLE_ADDRESSOR(Owning, addressWithOwner)
IMMUTABLE_ADDRESSOR(NativeOwning, addressWithNativeOwner)
IMMUTABLE_ADDRESSOR(Address, unsafeAddress)

/// This is a mutableAddress-family accessor: a function that is
/// called when the storage is modified and which works by returning
Expand All @@ -181,11 +172,7 @@ IMMUTABLE_ADDRESSOR(NativeOwning, addressWithNativeOwner)
/// Addressors are a way of proving more efficient access to storage
/// when it is already stored in memory (but not as a stored member
/// of the type).
ACCESSOR(MutableAddress)

MUTABLE_ADDRESSOR(Unsafe, unsafeMutableAddress)
MUTABLE_ADDRESSOR(Owning, mutableAddressWithOwner)
MUTABLE_ADDRESSOR(NativeOwning, mutableAddressWithNativeOwner)
MUTABLE_ADDRESSOR(MutableAddress, unsafeMutableAddress)

#ifdef LAST_ACCESSOR
LAST_ACCESSOR(MutableAddress)
Expand Down
18 changes: 3 additions & 15 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,9 @@ class alignas(1 << DeclAlignInBits) Decl {
SelfAccess : 2
);

SWIFT_INLINE_BITFIELD(AccessorDecl, FuncDecl, 4+3,
SWIFT_INLINE_BITFIELD(AccessorDecl, FuncDecl, 4,
/// The kind of accessor this is.
AccessorKind : 4,

/// The kind of addressor this is.
AddressorKind : 3
AccessorKind : 4
);

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

AccessorDecl(SourceLoc declLoc, SourceLoc accessorKeywordLoc,
AccessorKind accessorKind, AddressorKind addressorKind,
AbstractStorageDecl *storage,
AccessorKind accessorKind, AbstractStorageDecl *storage,
SourceLoc staticLoc, StaticSpellingKind staticSpelling,
bool throws, SourceLoc throwsLoc,
unsigned numParameterLists, GenericParamList *genericParams,
Expand All @@ -5707,14 +5703,12 @@ class AccessorDecl final : public FuncDecl {
AccessorKeywordLoc(accessorKeywordLoc),
Storage(storage) {
Bits.AccessorDecl.AccessorKind = unsigned(accessorKind);
Bits.AccessorDecl.AddressorKind = unsigned(addressorKind);
}

static AccessorDecl *createImpl(ASTContext &ctx,
SourceLoc declLoc,
SourceLoc accessorKeywordLoc,
AccessorKind accessorKind,
AddressorKind addressorKind,
AbstractStorageDecl *storage,
SourceLoc staticLoc,
StaticSpellingKind staticSpelling,
Expand All @@ -5728,7 +5722,6 @@ class AccessorDecl final : public FuncDecl {
SourceLoc declLoc,
SourceLoc accessorKeywordLoc,
AccessorKind accessorKind,
AddressorKind addressorKind,
AbstractStorageDecl *storage,
SourceLoc staticLoc,
StaticSpellingKind staticSpelling,
Expand All @@ -5739,7 +5732,6 @@ class AccessorDecl final : public FuncDecl {
static AccessorDecl *create(ASTContext &ctx, SourceLoc declLoc,
SourceLoc accessorKeywordLoc,
AccessorKind accessorKind,
AddressorKind addressorKind,
AbstractStorageDecl *storage,
SourceLoc staticLoc,
StaticSpellingKind staticSpelling,
Expand All @@ -5759,10 +5751,6 @@ class AccessorDecl final : public FuncDecl {
return AccessorKind(Bits.AccessorDecl.AccessorKind);
}

AddressorKind getAddressorKind() const {
return AddressorKind(Bits.AccessorDecl.AddressorKind);
}

bool isGetter() const { return getAccessorKind() == AccessorKind::Get; }
bool isSetter() const { return getAccessorKind() == AccessorKind::Set; }
bool isAnyAddressor() const {
Expand Down
14 changes: 0 additions & 14 deletions include/swift/AST/StorageImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,6 @@ static inline IntRange<AccessorKind> allAccessorKinds() {
AccessorKind(NumAccessorKinds));
}

/// The safety semantics of this addressor.
enum class AddressorKind : uint8_t {
/// \brief This is not an addressor.
NotAddressor,
/// \brief This is an unsafe addressor; it simply returns an address.
Unsafe,
/// \brief This is an owning addressor; it returns an AnyObject
/// which should be released when the caller is done with the object.
Owning,
/// \brief This is an owning addressor; it returns a Builtin.NativeObject
/// which should be released when the caller is done with the object.
NativeOwning,
};

/// Whether an access to storage is for reading, writing, or both.
enum class AccessKind : uint8_t {
/// The access is just to read the current value.
Expand Down
10 changes: 1 addition & 9 deletions include/swift/Serialization/ModuleFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
/// describe what change you made. The content of this comment isn't important;
/// it just ensures a conflict if two people change the module format.
/// Don't worry about adhering to the 80-column limit for this line.
const uint16_t SWIFTMODULE_VERSION_MINOR = 464; // Last change: simplify GenericParamLists
const uint16_t SWIFTMODULE_VERSION_MINOR = 465; // Last change: Remove owning addressors

using DeclIDField = BCFixed<31>;

Expand Down Expand Up @@ -287,13 +287,6 @@ enum MetatypeRepresentation : uint8_t {
};
using MetatypeRepresentationField = BCFixed<2>;

// These IDs must \em not be renumbered or reordered without incrementing
// the module version.
enum class AddressorKind : uint8_t {
NotAddressor, Unsafe, Owning, NativeOwning
};
using AddressorKindField = BCFixed<3>;

// These IDs must \em not be renumbered or reordered without incrementing
// the module version.
enum class SelfAccessKind : uint8_t {
Expand Down Expand Up @@ -1082,7 +1075,6 @@ namespace decls_block {
DeclIDField, // overridden function
DeclIDField, // AccessorStorageDecl
AccessorKindField, // accessor kind
AddressorKindField, // addressor kind
AccessLevelField, // access level
BCFixed<1>, // requires a new vtable slot
BCFixed<1>, // default argument resilience expansion
Expand Down
2 changes: 0 additions & 2 deletions lib/AST/ASTDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,6 @@ static StringRef getAccessorKindString(AccessorKind value) {
#define SINGLETON_ACCESSOR(ID, KEYWORD) \
case AccessorKind::ID: return #KEYWORD;
#include "swift/AST/AccessorKinds.def"
case AccessorKind::Address: return "address";
case AccessorKind::MutableAddress: return "mutableAddress";
}

llvm_unreachable("Unhandled AccessorKind in switch.");
Expand Down
38 changes: 6 additions & 32 deletions lib/AST/ASTMangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@
using namespace swift;
using namespace swift::Mangle;

static StringRef getCodeForAccessorKind(AccessorKind kind,
AddressorKind addressorKind) {
static StringRef getCodeForAccessorKind(AccessorKind kind) {
switch (kind) {
case AccessorKind::Get:
return "g";
Expand All @@ -62,29 +61,9 @@ static StringRef getCodeForAccessorKind(AccessorKind kind,
return "M";
case AccessorKind::Address:
// 'l' is for location. 'A' was taken.
switch (addressorKind) {
case AddressorKind::NotAddressor:
llvm_unreachable("bad combo");
case AddressorKind::Unsafe:
return "lu";
case AddressorKind::Owning:
return "lO";
case AddressorKind::NativeOwning:
return "lo";
}
llvm_unreachable("bad addressor kind");
return "lu";
case AccessorKind::MutableAddress:
switch (addressorKind) {
case AddressorKind::NotAddressor:
llvm_unreachable("bad combo");
case AddressorKind::Unsafe:
return "au";
case AddressorKind::Owning:
return "aO";
case AddressorKind::NativeOwning:
return "ao";
}
llvm_unreachable("bad addressor kind");
return "au";
}
llvm_unreachable("bad accessor kind");
}
Expand Down Expand Up @@ -139,13 +118,11 @@ std::string ASTMangler::mangleIVarInitDestroyEntity(const ClassDecl *decl,
}

std::string ASTMangler::mangleAccessorEntity(AccessorKind kind,
AddressorKind addressorKind,
const AbstractStorageDecl *decl,
bool isStatic,
SymbolKind SKind) {
beginMangling();
appendAccessorEntity(getCodeForAccessorKind(kind, addressorKind), decl,
isStatic);
appendAccessorEntity(getCodeForAccessorKind(kind), decl, isStatic);
appendSymbolKind(SKind);
return finalize();
}
Expand Down Expand Up @@ -513,14 +490,12 @@ std::string ASTMangler::mangleDeclAsUSR(const ValueDecl *Decl,
}

std::string ASTMangler::mangleAccessorEntityAsUSR(AccessorKind kind,
AddressorKind addressorKind,
const AbstractStorageDecl *decl,
StringRef USRPrefix) {
beginManglingWithoutPrefix();
llvm::SaveAndRestore<bool> allowUnnamedRAII(AllowNamelessEntities, true);
Buffer << USRPrefix;
appendAccessorEntity(getCodeForAccessorKind(kind, addressorKind), decl,
/*isStatic*/ false);
appendAccessorEntity(getCodeForAccessorKind(kind), decl, /*isStatic*/ false);
// We have a custom prefix, so finalize() won't verify for us. Do it manually.
verify(Storage.str().drop_front(USRPrefix.size()));
return finalize();
Expand Down Expand Up @@ -2224,8 +2199,7 @@ void ASTMangler::appendEntity(const ValueDecl *decl) {
// declaration.
if (auto accessor = dyn_cast<AccessorDecl>(decl)) {
return appendAccessorEntity(
getCodeForAccessorKind(accessor->getAccessorKind(),
accessor->getAddressorKind()),
getCodeForAccessorKind(accessor->getAccessorKind()),
accessor->getStorage(), accessor->isStatic());
}

Expand Down
20 changes: 0 additions & 20 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1595,26 +1595,6 @@ static StringRef getAccessorLabel(AccessorDecl *accessor) {
case AccessorKind::ID: return #KEYWORD;
#define ACCESSOR(ID)
#include "swift/AST/AccessorKinds.def"

case AccessorKind::Address:
switch (accessor->getAddressorKind()) {
case AddressorKind::NotAddressor: llvm_unreachable("bad combination");
#define IMMUTABLE_ADDRESSOR(ID, KEYWORD) \
case AddressorKind::ID: return #KEYWORD;
#define ACCESSOR(ID)
#include "swift/AST/AccessorKinds.def"
}
llvm_unreachable("bad addressor kind");

case AccessorKind::MutableAddress:
switch (accessor->getAddressorKind()) {
case AddressorKind::NotAddressor: llvm_unreachable("bad combination");
#define MUTABLE_ADDRESSOR(ID, KEYWORD) \
case AddressorKind::ID: return #KEYWORD;
#define ACCESSOR(ID)
#include "swift/AST/AccessorKinds.def"
}
llvm_unreachable("bad addressor kind");
}
llvm_unreachable("bad accessor kind");
}
Expand Down
22 changes: 0 additions & 22 deletions lib/AST/ASTVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3172,28 +3172,6 @@ class Verifier : public ASTWalker {
abort();
}

switch (FD->getAccessorKind()) {
case AccessorKind::Get:
case AccessorKind::Set:
case AccessorKind::WillSet:
case AccessorKind::DidSet:
case AccessorKind::Read:
case AccessorKind::Modify:
if (FD->getAddressorKind() != AddressorKind::NotAddressor) {
Out << "non-addressor accessor has an addressor kind\n";
abort();
}
break;

case AccessorKind::Address:
case AccessorKind::MutableAddress:
if (FD->getAddressorKind() == AddressorKind::NotAddressor) {
Out << "addressor does not have an addressor kind\n";
abort();
}
break;
}

verifyCheckedBase(FD);
}

Expand Down
Loading