Skip to content

Commit e4d0f31

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. (cherry picked from commit 76374f8)
1 parent 76950f3 commit e4d0f31

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
@@ -224,6 +224,26 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, StaticSpellingKind SSK);
224224
/// Diagnostic printing of \c ReferenceOwnership.
225225
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, ReferenceOwnership RO);
226226

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

320344
SWIFT_INLINE_BITFIELD_BASE(Decl, bitmax(NumDeclKindBits,8)+1+1+1+1+1,
@@ -456,7 +480,8 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
456480
DistributedThunk: 1
457481
);
458482

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

@@ -473,7 +498,7 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
473498
SelfAccessComputed : 1,
474499

475500
/// Backing bits for 'self' access kind.
476-
SelfAccess : 2,
501+
SelfAccess : NumSelfAccessKindBits,
477502

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

737762
} Bits;
763+
// Turn back on clang-format now that we have defined our inline bitfields.
764+
// clang-format on
738765

739766
// Storage for the declaration attributes.
740767
DeclAttributes Attrs;
@@ -7234,17 +7261,6 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
72347261

72357262
class OperatorDecl;
72367263

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

0 commit comments

Comments
 (0)