Skip to content

Commit 36972a1

Browse files
committed
Be stricter about identifying reference types.
TypeReferenceOwnership here is a bitmap indicating which of the various ownership modifiers (weak, unowned, unmanaged) were present on the field declaration. Making this a bitmap ensures that we can accurately represent the data that may have been provided but we have to be careful when we interpret the result. This changes the `isWeak`, `isUnowned`, `isUnmanged` checks to only return true if exactly one bit is set. Combinations of bits will not be accepted. Also, add `isStrong` to check for the default ownership with no modifiers.
1 parent ca53953 commit 36972a1

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

stdlib/public/runtime/Private.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ class TypeReferenceOwnership {
5050

5151
#define REF_STORAGE(Name, ...) \
5252
void set##Name() { Data |= Name; } \
53-
bool is##Name() const { return Data & Name; }
53+
bool is##Name() const { return Data == Name; }
5454
#include "swift/AST/ReferenceStorage.def"
55+
56+
bool isStrong() const { return Data == 0; }
5557
};
5658

5759
/// Type information consists of metadata and its ownership info,
@@ -76,9 +78,11 @@ class TypeInfo {
7678
const Metadata *getMetadata() const { return Response.Value; }
7779
MetadataResponse getResponse() const { return Response; }
7880

79-
bool isWeak() const { return ReferenceOwnership.isWeak(); }
80-
bool isUnowned() const { return ReferenceOwnership.isUnowned(); }
81-
bool isUnmanaged() const { return ReferenceOwnership.isUnmanaged(); }
81+
#define REF_STORAGE(Name, ...) \
82+
bool is##Name() const { return ReferenceOwnership.is##Name(); }
83+
#include "swift/AST/ReferenceStorage.def"
84+
85+
bool isStrong() const { return ReferenceOwnership.isStrong(); }
8286

8387
TypeReferenceOwnership getReferenceOwnership() const {
8488
return ReferenceOwnership;

0 commit comments

Comments
 (0)