Skip to content

Commit 9b9d173

Browse files
committed
[AST] NFC: Pack Ctor bits into intrusive bitfield
1 parent 392e336 commit 9b9d173

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

include/swift/AST/Decl.h

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -372,13 +372,28 @@ class alignas(1 << DeclAlignInBits) Decl {
372372
unsigned StaticSpelling : 2;
373373
BITFIELD_END;
374374

375-
BITFIELD_START(ConstructorDecl, AbstractFunctionDecl, 3);
375+
BITFIELD_START(ConstructorDecl, AbstractFunctionDecl, 8);
376376
/// The body initialization kind (+1), or zero if not yet computed.
377377
///
378378
/// This value is cached but is not serialized, because it is a property
379379
/// of the definition of the constructor that is useful only to semantic
380380
/// analysis and SIL generation.
381381
unsigned ComputedBodyInitKind : 3;
382+
383+
/// The kind of initializer we have.
384+
unsigned InitKind : 2;
385+
386+
/// The failability of this initializer, which is an OptionalTypeKind.
387+
unsigned Failability : 2;
388+
389+
/// Whether this initializer is a stub placed into a subclass to
390+
/// catch invalid delegations to a designated initializer not
391+
/// overridden by the subclass. A stub will always trap at runtime.
392+
///
393+
/// Initializer stubs can be invoked from Objective-C or through
394+
/// the Objective-C runtime; there is no way to directly express
395+
/// an object construction that will invoke a stub.
396+
unsigned HasStubImplementation : 1;
382397
BITFIELD_END;
383398

384399
BITFIELD_START(TypeDecl, ValueDecl, 1);
@@ -5644,21 +5659,6 @@ enum class CtorInitializerKind {
56445659
/// }
56455660
/// \endcode
56465661
class ConstructorDecl : public AbstractFunctionDecl {
5647-
/// The kind of initializer we have.
5648-
unsigned InitKind : 2;
5649-
5650-
/// The failability of this initializer, which is an OptionalTypeKind.
5651-
unsigned Failability : 2;
5652-
5653-
/// Whether this initializer is a stub placed into a subclass to
5654-
/// catch invalid delegations to a designated initializer not
5655-
/// overridden by the subclass. A stub will always trap at runtime.
5656-
///
5657-
/// Initializer stubs can be invoked from Objective-C or through
5658-
/// the Objective-C runtime; there is no way to directly express
5659-
/// an object construction that will invoke a stub.
5660-
unsigned HasStubImplementation : 1;
5661-
56625662
/// The location of the '!' or '?' for a failable initializer.
56635663
SourceLoc FailabilityLoc;
56645664

@@ -5763,12 +5763,12 @@ class ConstructorDecl : public AbstractFunctionDecl {
57635763

57645764
/// Determine the kind of initializer this is.
57655765
CtorInitializerKind getInitKind() const {
5766-
return static_cast<CtorInitializerKind>(InitKind);
5766+
return static_cast<CtorInitializerKind>(ConstructorDeclBits.InitKind);
57675767
}
57685768

57695769
/// Set whether this is a convenience initializer.
57705770
void setInitKind(CtorInitializerKind kind) {
5771-
InitKind = static_cast<unsigned>(kind);
5771+
ConstructorDeclBits.InitKind = static_cast<unsigned>(kind);
57725772
}
57735773

57745774
/// Whether this is a designated initializer.
@@ -5812,21 +5812,21 @@ class ConstructorDecl : public AbstractFunctionDecl {
58125812

58135813
/// Determine the failability of the initializer.
58145814
OptionalTypeKind getFailability() const {
5815-
return static_cast<OptionalTypeKind>(Failability);
5815+
return static_cast<OptionalTypeKind>(ConstructorDeclBits.Failability);
58165816
}
58175817

58185818
/// Retrieve the location of the '!' or '?' in a failable initializer.
58195819
SourceLoc getFailabilityLoc() const { return FailabilityLoc; }
58205820

58215821
/// Whether the implementation of this method is a stub that traps at runtime.
58225822
bool hasStubImplementation() const {
5823-
return HasStubImplementation;
5823+
return ConstructorDeclBits.HasStubImplementation;
58245824
}
58255825

58265826
/// Set whether the implementation of this method is a stub that
58275827
/// traps at runtime.
58285828
void setStubImplementation(bool stub) {
5829-
HasStubImplementation = stub;
5829+
ConstructorDeclBits.HasStubImplementation = stub;
58305830
}
58315831

58325832
ConstructorDecl *getOverriddenDecl() const { return OverriddenDecl; }

lib/AST/Decl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5083,9 +5083,9 @@ ConstructorDecl::ConstructorDecl(DeclName Name, SourceLoc ConstructorLoc,
50835083
setParameterLists(SelfDecl, BodyParams);
50845084

50855085
ConstructorDeclBits.ComputedBodyInitKind = 0;
5086-
this->HasStubImplementation = 0;
5087-
this->InitKind = static_cast<unsigned>(CtorInitializerKind::Designated);
5088-
this->Failability = static_cast<unsigned>(Failability);
5086+
ConstructorDeclBits.HasStubImplementation = 0;
5087+
ConstructorDeclBits.InitKind = static_cast<unsigned>(CtorInitializerKind::Designated);
5088+
ConstructorDeclBits.Failability = static_cast<unsigned>(Failability);
50895089
}
50905090

50915091
void ConstructorDecl::setParameterLists(ParamDecl *selfDecl,

0 commit comments

Comments
 (0)