Skip to content

Commit 76374f8

Browse files
committed
[move-only] Expand FuncDecl's SelfAccessKind field so it can fit Consuming/Borrowing.
I also added a static_assert to make sure that we always catch this in the future.
1 parent 508866a commit 76374f8

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
lines changed

include/swift/AST/Decl.h

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,26 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, StaticSpellingKind SSK);
225225
/// Diagnostic printing of \c ReferenceOwnership.
226226
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, ReferenceOwnership RO);
227227

228+
enum class SelfAccessKind : uint8_t {
229+
NonMutating,
230+
Mutating,
231+
LegacyConsuming,
232+
Consuming,
233+
Borrowing,
234+
LastSelfAccessKind = Borrowing,
235+
};
236+
enum : unsigned {
237+
NumSelfAccessKindBits =
238+
countBitsUsed(static_cast<unsigned>(SelfAccessKind::LastSelfAccessKind))
239+
};
240+
static_assert(uint8_t(SelfAccessKind::LastSelfAccessKind) <
241+
(NumSelfAccessKindBits << 1),
242+
"Self Access Kind is too small to fit in SelfAccess kind bits. "
243+
"Please expand ");
244+
245+
/// Diagnostic printing of \c SelfAccessKind.
246+
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, SelfAccessKind SAK);
247+
228248
/// Encapsulation of the overload signature of a given declaration,
229249
/// which is used to determine uniqueness of a declaration within a
230250
/// given context.
@@ -316,6 +336,10 @@ enum class ArtificialMainKind : uint8_t {
316336
/// Decl - Base class for all declarations in Swift.
317337
class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
318338
protected:
339+
// clang-format off
340+
//
341+
// We format these different than clang-format wishes us to... so turn if off
342+
// for the inline bitfields.
319343
union { uint64_t OpaqueBits;
320344

321345
SWIFT_INLINE_BITFIELD_BASE(Decl, bitmax(NumDeclKindBits,8)+1+1+1+1+1,
@@ -457,7 +481,8 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
457481
DistributedThunk: 1
458482
);
459483

460-
SWIFT_INLINE_BITFIELD(FuncDecl, AbstractFunctionDecl, 1+1+2+1+1+2+1,
484+
SWIFT_INLINE_BITFIELD(FuncDecl, AbstractFunctionDecl,
485+
1+1+2+1+1+NumSelfAccessKindBits+1,
461486
/// Whether we've computed the 'static' flag yet.
462487
IsStaticComputed : 1,
463488

@@ -474,7 +499,7 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
474499
SelfAccessComputed : 1,
475500

476501
/// Backing bits for 'self' access kind.
477-
SelfAccess : 2,
502+
SelfAccess : NumSelfAccessKindBits,
478503

479504
/// Whether this is a top-level function which should be treated
480505
/// as if it were in local context for the purposes of capture
@@ -736,6 +761,8 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
736761
);
737762

738763
} Bits;
764+
// Turn back on clang-format now that we have defined our inline bitfields.
765+
// clang-format on
739766

740767
// Storage for the declaration attributes.
741768
DeclAttributes Attrs;
@@ -7233,17 +7260,6 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
72337260

72347261
class OperatorDecl;
72357262

7236-
enum class SelfAccessKind : uint8_t {
7237-
NonMutating,
7238-
Mutating,
7239-
LegacyConsuming,
7240-
Consuming,
7241-
Borrowing,
7242-
};
7243-
7244-
/// Diagnostic printing of \c SelfAccessKind.
7245-
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, SelfAccessKind SAK);
7246-
72477263
/// FuncDecl - 'func' declaration.
72487264
class FuncDecl : public AbstractFunctionDecl {
72497265
friend class AbstractFunctionDecl;

0 commit comments

Comments
 (0)