Skip to content

Commit b94c536

Browse files
committed
[NFC] Rename 'Ownership' to 'ReferenceOwnership'.
There's really two forms of ownership: references and values. Renaming to make way for better distinguishing of the two.
1 parent 11a6aae commit b94c536

26 files changed

+238
-196
lines changed

include/swift/AST/Attr.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,9 @@ DECL_ATTR(__raw_doc_comment, RawDocComment, OnAnyDecl |
214214
NotSerialized | RejectByParser, /* Not serialized */48)
215215

216216
// Also handles unowned and unowned(weak).
217-
DECL_ATTR(weak, Ownership, OnVar | OnParam | DeclModifier | NotSerialized,
217+
DECL_ATTR(weak, ReferenceOwnership, OnVar | OnParam | DeclModifier | NotSerialized,
218218
/* Not serialized */49)
219-
DECL_ATTR_ALIAS(unowned, Ownership)
219+
DECL_ATTR_ALIAS(unowned, ReferenceOwnership)
220220

221221
DECL_ATTR(effects, Effects, OnFunc | OnConstructor | OnDestructor |
222222
UserInaccessible, 50)

include/swift/AST/Attr.h

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,18 @@ class TypeAttributes {
105105

106106
bool hasConvention() const { return convention.hasValue(); }
107107
StringRef getConvention() const { return *convention; }
108-
109-
bool hasOwnership() const { return getOwnership() != Ownership::Strong; }
110-
Ownership getOwnership() const {
111-
if (has(TAK_sil_weak)) return Ownership::Weak;
112-
if (has(TAK_sil_unowned)) return Ownership::Unowned;
113-
if (has(TAK_sil_unmanaged)) return Ownership::Unmanaged;
114-
return Ownership::Strong;
108+
109+
bool hasOwnership() const {
110+
return getOwnership() != ReferenceOwnership::Strong;
111+
}
112+
ReferenceOwnership getOwnership() const {
113+
if (has(TAK_sil_weak))
114+
return ReferenceOwnership::Weak;
115+
if (has(TAK_sil_unowned))
116+
return ReferenceOwnership::Unowned;
117+
if (has(TAK_sil_unmanaged))
118+
return ReferenceOwnership::Unmanaged;
119+
return ReferenceOwnership::Strong;
115120
}
116121

117122
void clearOwnership() {
@@ -965,24 +970,27 @@ class EffectsAttr : public DeclAttribute {
965970

966971

967972
/// Represents weak/unowned/unowned(unsafe) decl modifiers.
968-
class OwnershipAttr : public DeclAttribute {
969-
const Ownership ownership;
973+
class ReferenceOwnershipAttr : public DeclAttribute {
974+
const ReferenceOwnership ownership;
975+
970976
public:
971-
OwnershipAttr(SourceRange range, Ownership kind)
972-
: DeclAttribute(DAK_Ownership, range.Start, range, /*Implicit=*/false),
973-
ownership(kind) {}
977+
ReferenceOwnershipAttr(SourceRange range, ReferenceOwnership kind)
978+
: DeclAttribute(DAK_ReferenceOwnership, range.Start, range,
979+
/*Implicit=*/false),
980+
ownership(kind) {}
974981

975-
OwnershipAttr(Ownership kind) : OwnershipAttr(SourceRange(), kind) {}
982+
ReferenceOwnershipAttr(ReferenceOwnership kind)
983+
: ReferenceOwnershipAttr(SourceRange(), kind) {}
976984

977-
Ownership get() const { return ownership; }
985+
ReferenceOwnership get() const { return ownership; }
978986

979987
/// Returns a copy of this attribute without any source information.
980-
OwnershipAttr *clone(ASTContext &context) const {
981-
return new (context) OwnershipAttr(get());
988+
ReferenceOwnershipAttr *clone(ASTContext &context) const {
989+
return new (context) ReferenceOwnershipAttr(get());
982990
}
983991

984992
static bool classof(const DeclAttribute *DA) {
985-
return DA->getKind() == DAK_Ownership;
993+
return DA->getKind() == DAK_ReferenceOwnership;
986994
}
987995
};
988996

include/swift/AST/DiagnosticsSema.def

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,7 +1913,7 @@ ERROR(override_argument_name_mismatch,none,
19131913
ERROR(override_ownership_mismatch,none,
19141914
"cannot override %select{strong|weak|unowned|unowned(unsafe)}0 property "
19151915
"with %select{strong|weak|unowned|unowned(unsafe)}1 property",
1916-
(/*Ownership*/unsigned, /*Ownership*/unsigned))
1916+
(/*ReferenceOwnership*/unsigned, /*ReferenceOwnership*/unsigned))
19171917
ERROR(override_dynamic_self_mismatch,none,
19181918
"cannot override a Self return type with a non-Self return type",
19191919
())
@@ -3150,22 +3150,22 @@ ERROR(implicitly_unwrapped_optional_in_illegal_position,none,
31503150
ERROR(invalid_ownership_type,none,
31513151
"'%select{strong|weak|unowned|unowned}0' may only be applied to "
31523152
"class and class-bound protocol types, not %1",
3153-
(/*Ownership*/unsigned, Type))
3153+
(/*ReferenceOwnership*/unsigned, Type))
31543154
ERROR(invalid_ownership_protocol_type,none,
31553155
"'%select{strong|weak|unowned|unowned}0' must not be applied to "
31563156
"non-class-bound %1; consider adding a protocol conformance that has a class bound",
3157-
(/*Ownership*/unsigned, Type))
3157+
(/*ReferenceOwnership*/unsigned, Type))
31583158
ERROR(invalid_weak_ownership_not_optional,none,
31593159
"'weak' variable should have optional type %0", (Type))
31603160
ERROR(invalid_weak_let,none,
31613161
"'weak' must be a mutable variable, because it may change at runtime", ())
31623162
ERROR(ownership_invalid_in_protocols,none,
31633163
"'%select{strong|weak|unowned|unowned}0' cannot be applied to a property declaration in a protocol",
3164-
(/*Ownership*/unsigned))
3164+
(/*ReferenceOwnership*/unsigned))
31653165
WARNING(ownership_invalid_in_protocols_compat_warning,none,
31663166
"'%select{strong|weak|unowned|unowned}0' should not be applied to a property declaration "
31673167
"in a protocol and will be disallowed in future versions",
3168-
(/*Ownership*/unsigned))
3168+
(/*ReferenceOwnership*/unsigned))
31693169

31703170
// required
31713171
ERROR(required_initializer_nonclass,none,

include/swift/AST/Ownership.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace swift {
2626
/// Different kinds of reference ownership supported by Swift.
2727
// This enum is used in diagnostics. If you add a case here, the diagnostics
2828
// must be updated as well.
29-
enum class Ownership : uint8_t {
29+
enum class ReferenceOwnership : uint8_t {
3030
/// \brief a strong reference (the default semantics)
3131
Strong,
3232

@@ -39,7 +39,7 @@ enum class Ownership : uint8_t {
3939
/// \brief an 'unowned(unsafe)' reference
4040
Unmanaged,
4141
};
42-
42+
4343
} // end namespace swift
4444

4545
#endif

include/swift/AST/Types.h

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4752,15 +4752,18 @@ class ReferenceStorageType : public TypeBase {
47524752
private:
47534753
Type Referent;
47544754
public:
4755-
static ReferenceStorageType *get(Type referent, Ownership ownership,
4755+
static ReferenceStorageType *get(Type referent, ReferenceOwnership ownership,
47564756
const ASTContext &C);
47574757

47584758
Type getReferentType() const { return Referent; }
4759-
Ownership getOwnership() const {
4759+
ReferenceOwnership getOwnership() const {
47604760
switch (getKind()) {
4761-
case TypeKind::WeakStorage: return Ownership::Weak;
4762-
case TypeKind::UnownedStorage: return Ownership::Unowned;
4763-
case TypeKind::UnmanagedStorage: return Ownership::Unmanaged;
4761+
case TypeKind::WeakStorage:
4762+
return ReferenceOwnership::Weak;
4763+
case TypeKind::UnownedStorage:
4764+
return ReferenceOwnership::Unowned;
4765+
case TypeKind::UnmanagedStorage:
4766+
return ReferenceOwnership::Unmanaged;
47644767
default: llvm_unreachable("Unhandled reference storage type");
47654768
}
47664769
}
@@ -4772,10 +4775,10 @@ class ReferenceStorageType : public TypeBase {
47724775
}
47734776
};
47744777
BEGIN_CAN_TYPE_WRAPPER(ReferenceStorageType, Type)
4775-
static CanReferenceStorageType get(CanType referent, Ownership ownership) {
4776-
return CanReferenceStorageType(ReferenceStorageType::get(referent,
4777-
ownership,
4778-
referent->getASTContext()));
4778+
static CanReferenceStorageType get(CanType referent,
4779+
ReferenceOwnership ownership) {
4780+
return CanReferenceStorageType(ReferenceStorageType::get(
4781+
referent, ownership, referent->getASTContext()));
47794782
}
47804783
PROXY_CAN_TYPE_SIMPLE_GETTER(getReferentType)
47814784
END_CAN_TYPE_WRAPPER(ReferenceStorageType, Type)
@@ -4789,8 +4792,8 @@ class UnownedStorageType : public ReferenceStorageType {
47894792

47904793
public:
47914794
static UnownedStorageType *get(Type referent, const ASTContext &C) {
4792-
return static_cast<UnownedStorageType*>(
4793-
ReferenceStorageType::get(referent, Ownership::Unowned, C));
4795+
return static_cast<UnownedStorageType *>(
4796+
ReferenceStorageType::get(referent, ReferenceOwnership::Unowned, C));
47944797
}
47954798

47964799
/// Is this unowned storage type known to be loadable within the given
@@ -4820,8 +4823,8 @@ class UnmanagedStorageType : public ReferenceStorageType {
48204823

48214824
public:
48224825
static UnmanagedStorageType *get(Type referent, const ASTContext &C) {
4823-
return static_cast<UnmanagedStorageType*>(
4824-
ReferenceStorageType::get(referent, Ownership::Unmanaged, C));
4826+
return static_cast<UnmanagedStorageType *>(
4827+
ReferenceStorageType::get(referent, ReferenceOwnership::Unmanaged, C));
48254828
}
48264829

48274830
// Implement isa/cast/dyncast/etc.
@@ -4845,8 +4848,8 @@ class WeakStorageType : public ReferenceStorageType {
48454848

48464849
public:
48474850
static WeakStorageType *get(Type referent, const ASTContext &C) {
4848-
return static_cast<WeakStorageType*>(
4849-
ReferenceStorageType::get(referent, Ownership::Weak, C));
4851+
return static_cast<WeakStorageType *>(
4852+
ReferenceStorageType::get(referent, ReferenceOwnership::Weak, C));
48504853
}
48514854

48524855
// Implement isa/cast/dyncast/etc.

include/swift/Serialization/ModuleFormat.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,13 +311,13 @@ using AssociativityField = BCFixed<2>;
311311

312312
// These IDs must \em not be renumbered or reordered without incrementing
313313
// VERSION_MAJOR.
314-
enum Ownership : uint8_t {
314+
enum ReferenceOwnership : uint8_t {
315315
Strong = 0,
316316
Weak,
317317
Unowned,
318318
Unmanaged,
319319
};
320-
using OwnershipField = BCFixed<2>;
320+
using ReferenceOwnershipField = BCFixed<2>;
321321

322322
// These IDs must \em not be renumbered or reordered without incrementing
323323
// VERSION_MAJOR.
@@ -800,8 +800,8 @@ namespace decls_block {
800800

801801
using ReferenceStorageTypeLayout = BCRecordLayout<
802802
REFERENCE_STORAGE_TYPE,
803-
OwnershipField, // ownership
804-
TypeIDField // implementation type
803+
ReferenceOwnershipField, // ownership
804+
TypeIDField // implementation type
805805
>;
806806

807807
using UnboundGenericTypeLayout = BCRecordLayout<
@@ -1410,7 +1410,8 @@ namespace decls_block {
14101410
>;
14111411

14121412
// Stub layouts, unused.
1413-
using OwnershipDeclAttrLayout = BCRecordLayout<Ownership_DECL_ATTR>;
1413+
using ReferenceOwnershipDeclAttrLayout
1414+
= BCRecordLayout<ReferenceOwnership_DECL_ATTR>;
14141415
using RawDocCommentDeclAttrLayout = BCRecordLayout<RawDocComment_DECL_ATTR>;
14151416
using AccessControlDeclAttrLayout = BCRecordLayout<AccessControl_DECL_ATTR>;
14161417
using SetterAccessDeclAttrLayout = BCRecordLayout<SetterAccess_DECL_ATTR>;

lib/AST/ASTContext.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3376,9 +3376,10 @@ ProtocolCompositionType::build(const ASTContext &C, ArrayRef<Type> Members,
33763376
return compTy;
33773377
}
33783378

3379-
ReferenceStorageType *ReferenceStorageType::get(Type T, Ownership ownership,
3379+
ReferenceStorageType *ReferenceStorageType::get(Type T,
3380+
ReferenceOwnership ownership,
33803381
const ASTContext &C) {
3381-
assert(ownership != Ownership::Strong &&
3382+
assert(ownership != ReferenceOwnership::Strong &&
33823383
"ReferenceStorageType is unnecessary for strong ownership");
33833384
assert(!T->hasTypeVariable()); // not meaningful in type-checker
33843385
auto properties = T->getRecursiveProperties();
@@ -3390,16 +3391,17 @@ ReferenceStorageType *ReferenceStorageType::get(Type T, Ownership ownership,
33903391

33913392

33923393
switch (ownership) {
3393-
case Ownership::Strong: llvm_unreachable("not possible");
3394-
case Ownership::Unowned:
3394+
case ReferenceOwnership::Strong:
3395+
llvm_unreachable("not possible");
3396+
case ReferenceOwnership::Unowned:
33953397
return entry = new (C, arena) UnownedStorageType(
33963398
T, T->isCanonical() ? &C : nullptr, properties);
3397-
case Ownership::Weak:
3399+
case ReferenceOwnership::Weak:
33983400
assert(T->getOptionalObjectType() &&
33993401
"object of weak storage type is not optional");
34003402
return entry = new (C, arena)
34013403
WeakStorageType(T, T->isCanonical() ? &C : nullptr, properties);
3402-
case Ownership::Unmanaged:
3404+
case ReferenceOwnership::Unmanaged:
34033405
return entry = new (C, arena) UnmanagedStorageType(
34043406
T, T->isCanonical() ? &C : nullptr, properties);
34053407
}

lib/AST/ASTVerifier.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2249,9 +2249,9 @@ class Verifier : public ASTWalker {
22492249

22502250
// The fact that this is *directly* be a reference storage type
22512251
// cuts the code down quite a bit in getTypeOfReference.
2252-
if (var->getAttrs().hasAttribute<OwnershipAttr>() !=
2252+
if (var->getAttrs().hasAttribute<ReferenceOwnershipAttr>() !=
22532253
isa<ReferenceStorageType>(var->getInterfaceType().getPointer())) {
2254-
if (var->getAttrs().hasAttribute<OwnershipAttr>()) {
2254+
if (var->getAttrs().hasAttribute<ReferenceOwnershipAttr>()) {
22552255
Out << "VarDecl has an ownership attribute, but its type"
22562256
" is not a ReferenceStorageType: ";
22572257
} else {

lib/AST/Attr.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
338338
#include "swift/AST/Attr.def"
339339
case DAK_Inline:
340340
case DAK_AccessControl:
341-
case DAK_Ownership:
341+
case DAK_ReferenceOwnership:
342342
case DAK_Effects:
343343
case DAK_Optimize:
344344
if (DeclAttribute::isDeclModifier(getKind())) {
@@ -622,12 +622,16 @@ StringRef DeclAttribute::getAttrName() const {
622622
}
623623
llvm_unreachable("bad access level");
624624

625-
case DAK_Ownership:
626-
switch (cast<OwnershipAttr>(this)->get()) {
627-
case Ownership::Strong: llvm_unreachable("Never present in the attribute");
628-
case Ownership::Weak: return "weak";
629-
case Ownership::Unowned: return "unowned";
630-
case Ownership::Unmanaged: return "unowned(unsafe)";
625+
case DAK_ReferenceOwnership:
626+
switch (cast<ReferenceOwnershipAttr>(this)->get()) {
627+
case ReferenceOwnership::Strong:
628+
llvm_unreachable("Never present in the attribute");
629+
case ReferenceOwnership::Weak:
630+
return "weak";
631+
case ReferenceOwnership::Unowned:
632+
return "unowned";
633+
case ReferenceOwnership::Unmanaged:
634+
return "unowned(unsafe)";
631635
}
632636
llvm_unreachable("bad ownership kind");
633637
case DAK_RawDocComment:

lib/AST/Decl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,7 @@ static bool isDefaultInitializable(const TypeRepr *typeRepr) {
11771177
// Look through most attributes.
11781178
if (const auto attributed = dyn_cast<AttributedTypeRepr>(typeRepr)) {
11791179
// Weak ownership implies optionality.
1180-
if (attributed->getAttrs().getOwnership() == Ownership::Weak)
1180+
if (attributed->getAttrs().getOwnership() == ReferenceOwnership::Weak)
11811181
return true;
11821182

11831183
return isDefaultInitializable(attributed->getTypeRepr());

0 commit comments

Comments
 (0)