Skip to content

Commit eddfe11

Browse files
authored
Merge pull request #13363 from davezarzycki/nfc_repack_various_decls
2 parents eebde10 + 4d56dfc commit eddfe11

File tree

5 files changed

+155
-92
lines changed

5 files changed

+155
-92
lines changed

include/swift/AST/Decl.h

Lines changed: 106 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,12 @@ bool conflicting(const OverloadSignature& sig1, const OverloadSignature& sig2);
231231
#define BITFIELD_START(D, PD, C) \
232232
enum { Num##D##Bits = Num##PD##Bits + C }; \
233233
static_assert(Num##D##Bits <= 64, "fits in a uint64_t"); \
234+
LLVM_PACKED_START; \
234235
class D##Bitfields { \
235236
friend class D; \
236237
uint64_t : Num##PD##Bits
237238

238-
#define BITFIELD_END }
239+
#define BITFIELD_END }; LLVM_PACKED_END
239240

240241
/// Decl - Base class for all declarations in Swift.
241242
class alignas(1 << DeclAlignInBits) Decl {
@@ -282,6 +283,13 @@ class alignas(1 << DeclAlignInBits) Decl {
282283
unsigned NumPatternEntries : 16;
283284
BITFIELD_END;
284285

286+
BITFIELD_START(EnumCaseDecl, Decl, 51);
287+
unsigned : 19; // unused / padding
288+
289+
/// The number of tail-allocated element pointers.
290+
unsigned NumElements : 32;
291+
BITFIELD_END;
292+
285293
BITFIELD_START(ValueDecl, Decl, 3);
286294
friend class MemberLookupTable;
287295

@@ -353,13 +361,16 @@ class alignas(1 << DeclAlignInBits) Decl {
353361
unsigned HasArgumentType : 1;
354362
BITFIELD_END;
355363

356-
BITFIELD_START(AbstractFunctionDecl, ValueDecl, 13);
364+
BITFIELD_START(AbstractFunctionDecl, ValueDecl, 21);
357365
/// \see AbstractFunctionDecl::BodyKind
358366
unsigned BodyKind : 3;
359367

360368
/// Number of curried parameter lists.
361369
unsigned NumParameterLists : 5;
362370

371+
/// Import as member status.
372+
unsigned IAMStatus : 8;
373+
363374
/// Whether we are overridden later.
364375
unsigned Overridden : 1;
365376

@@ -424,6 +435,16 @@ class alignas(1 << DeclAlignInBits) Decl {
424435
unsigned CheckedInheritanceClause : 1;
425436
BITFIELD_END;
426437

438+
BITFIELD_START(AbstractTypeParamDecl, TypeDecl, 0);
439+
BITFIELD_END;
440+
441+
BITFIELD_START(GenericTypeParamDecl, AbstractTypeParamDecl, 47);
442+
unsigned : 15; // unused padding
443+
444+
unsigned Depth : 16;
445+
unsigned Index : 16;
446+
BITFIELD_END;
447+
427448
BITFIELD_START(GenericTypeDecl, TypeDecl, 0);
428449
BITFIELD_END;
429450

@@ -449,7 +470,7 @@ class alignas(1 << DeclAlignInBits) Decl {
449470
unsigned HasValidatedLayout : 1;
450471
BITFIELD_END;
451472

452-
BITFIELD_START(ProtocolDecl, NominalTypeDecl, 8);
473+
BITFIELD_START(ProtocolDecl, NominalTypeDecl, 43);
453474
/// Whether the \c RequiresClass bit is valid.
454475
unsigned RequiresClassValid : 1;
455476

@@ -468,11 +489,24 @@ class alignas(1 << DeclAlignInBits) Decl {
468489
/// Whether the existential of this protocol can be represented.
469490
unsigned ExistentialTypeSupported : 1;
470491

492+
/// True if the protocol has requirements that cannot be satisfied (e.g.
493+
/// because they could not be imported from Objective-C).
494+
unsigned HasMissingRequirements : 1;
495+
496+
unsigned : 12; // unused flags
497+
498+
/// If this is a compiler-known protocol, this will be a KnownProtocolKind
499+
/// value, plus one. Otherwise, it will be 0.
500+
unsigned KnownProtocol : 6;
501+
471502
/// The stage of the circularity check for this protocol.
472503
unsigned Circularity : 2;
504+
505+
/// The number of requirements in the requirement signature.
506+
unsigned NumRequirementsInSignature : 16;
473507
BITFIELD_END;
474508

475-
BITFIELD_START(ClassDecl, NominalTypeDecl, 8);
509+
BITFIELD_START(ClassDecl, NominalTypeDecl, 13);
476510
/// The stage of the inheritance circularity check for this class.
477511
unsigned Circularity : 2;
478512

@@ -495,6 +529,12 @@ class alignas(1 << DeclAlignInBits) Decl {
495529
/// it is implicit. This bit is used during parsing and type-checking to
496530
/// control inserting the implicit destructor.
497531
unsigned HasDestructorDecl : 1;
532+
533+
/// Whether the class has @objc ancestry.
534+
unsigned ObjCKind : 3;
535+
536+
unsigned HasMissingDesignatedInitializers : 1;
537+
unsigned HasMissingVTableEntries : 1;
498538
BITFIELD_END;
499539

500540
BITFIELD_START(StructDecl, NominalTypeDecl, 1);
@@ -524,8 +564,11 @@ class alignas(1 << DeclAlignInBits) Decl {
524564
unsigned HasOverridden : 1;
525565
BITFIELD_END;
526566

527-
BITFIELD_START(ImportDecl, Decl, 3);
567+
BITFIELD_START(ImportDecl, Decl, 11);
528568
unsigned ImportKind : 3;
569+
570+
/// The number of elements in this path.
571+
unsigned NumPathElements : 8;
529572
BITFIELD_END;
530573

531574
BITFIELD_START(ExtensionDecl, Decl, 5);
@@ -561,6 +604,7 @@ class alignas(1 << DeclAlignInBits) Decl {
561604
union {
562605
DeclBitfields DeclBits;
563606
PatternBindingDeclBitfields PatternBindingDeclBits;
607+
EnumCaseDeclBitfields EnumCaseDeclBits;
564608
ValueDeclBitfields ValueDeclBits;
565609
AbstractStorageDeclBitfields AbstractStorageDeclBits;
566610
AbstractFunctionDeclBitfields AbstractFunctionDeclBits;
@@ -570,6 +614,8 @@ class alignas(1 << DeclAlignInBits) Decl {
570614
FuncDeclBitfields FuncDeclBits;
571615
ConstructorDeclBitfields ConstructorDeclBits;
572616
TypeDeclBitfields TypeDeclBits;
617+
AbstractTypeParamDeclBitfields AbstractTypeParamDeclBit;
618+
GenericTypeParamDeclBitfields GenericTypeParamDeclBits;
573619
GenericTypeDeclBitfields GenericTypeDeclBits;
574620
TypeAliasDeclBitfields TypeAliasDeclBits;
575621
NominalTypeDeclBitfields NominalTypeDeclBits;
@@ -1450,9 +1496,6 @@ class ImportDecl final : public Decl,
14501496
SourceLoc ImportLoc;
14511497
SourceLoc KindLoc;
14521498

1453-
/// The number of elements in this path.
1454-
unsigned NumPathElements;
1455-
14561499
/// The resolved module.
14571500
ModuleDecl *Mod = nullptr;
14581501
/// The resolved decls if this is a decl import.
@@ -1481,7 +1524,8 @@ class ImportDecl final : public Decl,
14811524
static Optional<ImportKind> findBestImportKind(ArrayRef<ValueDecl *> Decls);
14821525

14831526
ArrayRef<AccessPathElement> getFullAccessPath() const {
1484-
return {getTrailingObjects<AccessPathElement>(), NumPathElements};
1527+
return {getTrailingObjects<AccessPathElement>(),
1528+
ImportDeclBits.NumPathElements};
14851529
}
14861530

14871531
ArrayRef<AccessPathElement> getModulePath() const {
@@ -2481,9 +2525,6 @@ class AbstractTypeParamDecl : public TypeDecl {
24812525
/// func min<T : Comparable>(x : T, y : T) -> T { ... }
24822526
/// \endcode
24832527
class GenericTypeParamDecl : public AbstractTypeParamDecl {
2484-
unsigned Depth : 16;
2485-
unsigned Index : 16;
2486-
24872528
public:
24882529
static const unsigned InvalidDepth = 0xFFFF;
24892530

@@ -2508,12 +2549,15 @@ class GenericTypeParamDecl : public AbstractTypeParamDecl {
25082549
/// \endcode
25092550
///
25102551
/// Here 'T' has depth 0 and 'U' has depth 1. Both have index 0.
2511-
unsigned getDepth() const { return Depth; }
2552+
unsigned getDepth() const { return GenericTypeParamDeclBits.Depth; }
25122553

25132554
/// Set the depth of this generic type parameter.
25142555
///
25152556
/// \sa getDepth
2516-
void setDepth(unsigned depth) { Depth = depth; }
2557+
void setDepth(unsigned depth) {
2558+
GenericTypeParamDeclBits.Depth = depth;
2559+
assert(GenericTypeParamDeclBits.Depth == depth && "Truncation");
2560+
}
25172561

25182562
/// The index of this generic type parameter within its generic parameter
25192563
/// list.
@@ -2525,7 +2569,7 @@ class GenericTypeParamDecl : public AbstractTypeParamDecl {
25252569
/// \endcode
25262570
///
25272571
/// Here 'T' and 'U' have indexes 0 and 1, respectively. 'V' has index 0.
2528-
unsigned getIndex() const { return Index; }
2572+
unsigned getIndex() const { return GenericTypeParamDeclBits.Index; }
25292573

25302574
SourceLoc getStartLoc() const { return getNameLoc(); }
25312575
SourceRange getSourceRange() const;
@@ -3226,12 +3270,6 @@ class ClassDecl final : public NominalTypeDecl {
32263270
llvm::PointerIntPair<Type, 1, bool> Superclass;
32273271
} LazySemanticInfo;
32283272

3229-
/// Whether the class has @objc ancestry.
3230-
unsigned ObjCKind : 3;
3231-
3232-
unsigned HasMissingDesignatedInitializers : 1;
3233-
unsigned HasMissingVTableEntries : 1;
3234-
32353273
friend class IterativeTypeChecker;
32363274

32373275
public:
@@ -3324,7 +3362,7 @@ class ClassDecl final : public NominalTypeDecl {
33243362
bool hasMissingDesignatedInitializers() const;
33253363

33263364
void setHasMissingDesignatedInitializers(bool newValue = true) {
3327-
HasMissingDesignatedInitializers = newValue;
3365+
ClassDeclBits.HasMissingDesignatedInitializers = newValue;
33283366
}
33293367

33303368
/// Returns true if the class has missing members that require vtable entries.
@@ -3334,7 +3372,7 @@ class ClassDecl final : public NominalTypeDecl {
33343372
bool hasMissingVTableEntries() const;
33353373

33363374
void setHasMissingVTableEntries(bool newValue = true) {
3337-
HasMissingVTableEntries = newValue;
3375+
ClassDeclBits.HasMissingVTableEntries = newValue;
33383376
}
33393377

33403378
/// Find a method of a class that overrides a given method.
@@ -3523,17 +3561,6 @@ class ProtocolDecl final : public NominalTypeDecl {
35233561
/// by this protocol.
35243562
const Requirement *RequirementSignature = nullptr;
35253563

3526-
/// True if the protocol has requirements that cannot be satisfied (e.g.
3527-
/// because they could not be imported from Objective-C).
3528-
unsigned HasMissingRequirements : 1;
3529-
3530-
/// If this is a compiler-known protocol, this will be a KnownProtocolKind
3531-
/// value, plus one. Otherwise, it will be 0.
3532-
unsigned KnownProtocol : 6;
3533-
3534-
/// The number of requirements in the requirement signature.
3535-
unsigned NumRequirementsInSignature : 16;
3536-
35373564
bool requiresClassSlow();
35383565

35393566
bool existentialConformsToSelfSlow();
@@ -3653,9 +3680,9 @@ class ProtocolDecl final : public NominalTypeDecl {
36533680
///
36543681
/// Note that this is only valid after type-checking.
36553682
Optional<KnownProtocolKind> getKnownProtocolKind() const {
3656-
if (KnownProtocol == 0)
3683+
if (ProtocolDeclBits.KnownProtocol == 0)
36573684
return None;
3658-
return static_cast<KnownProtocolKind>(KnownProtocol - 1);
3685+
return static_cast<KnownProtocolKind>(ProtocolDeclBits.KnownProtocol - 1);
36593686
}
36603687

36613688
/// Check whether this protocol is of a specific, known protocol kind.
@@ -3670,7 +3697,7 @@ class ProtocolDecl final : public NominalTypeDecl {
36703697
void setKnownProtocolKind(KnownProtocolKind kind) {
36713698
assert((!getKnownProtocolKind() || *getKnownProtocolKind() == kind) &&
36723699
"can't reset known protocol kind");
3673-
KnownProtocol = static_cast<unsigned>(kind) + 1;
3700+
ProtocolDeclBits.KnownProtocol = static_cast<unsigned>(kind) + 1;
36743701
assert(getKnownProtocolKind() && *getKnownProtocolKind() == kind &&
36753702
"not enough bits");
36763703
}
@@ -3692,11 +3719,11 @@ class ProtocolDecl final : public NominalTypeDecl {
36923719
/// with requirements that cannot be represented in Swift.
36933720
bool hasMissingRequirements() const {
36943721
(void)getMembers();
3695-
return HasMissingRequirements;
3722+
return ProtocolDeclBits.HasMissingRequirements;
36963723
}
36973724

36983725
void setHasMissingRequirements(bool newValue) {
3699-
HasMissingRequirements = newValue;
3726+
ProtocolDeclBits.HasMissingRequirements = newValue;
37003727
}
37013728

37023729
/// Returns the default witness for a requirement, or nullptr if there is
@@ -3733,7 +3760,8 @@ class ProtocolDecl final : public NominalTypeDecl {
37333760
ArrayRef<Requirement> getRequirementSignature() const {
37343761
assert(isRequirementSignatureComputed() &&
37353762
"getting requirement signature before computing it");
3736-
return llvm::makeArrayRef(RequirementSignature, NumRequirementsInSignature);
3763+
return llvm::makeArrayRef(RequirementSignature,
3764+
ProtocolDeclBits.NumRequirementsInSignature);
37373765
}
37383766

37393767
/// Has the requirement signature been computed yet?
@@ -4784,10 +4812,17 @@ class SubscriptDecl : public AbstractStorageDecl, public GenericContext {
47844812

47854813
/// Encodes imported-as-member status for C functions that get imported
47864814
/// as methods.
4787-
struct ImportAsMemberStatus {
4815+
class ImportAsMemberStatus {
4816+
friend class AbstractFunctionDecl;
4817+
47884818
// non-0 denotes import-as-member. 1 denotes no self index. n+2 denotes self
47894819
// index of n
4790-
uint8_t rawValue = 0;
4820+
uint8_t rawValue;
4821+
4822+
public:
4823+
ImportAsMemberStatus(uint8_t rawValue = 0) : rawValue(rawValue) {}
4824+
4825+
uint8_t getRawValue() const { return rawValue; }
47914826

47924827
bool isImportAsMember() const { return rawValue != 0; }
47934828
bool isInstance() const { return rawValue >= 2; }
@@ -4864,8 +4899,6 @@ class AbstractFunctionDecl : public ValueDecl, public GenericContext {
48644899
/// Location of the 'throws' token.
48654900
SourceLoc ThrowsLoc;
48664901

4867-
ImportAsMemberStatus IAMStatus;
4868-
48694902
AbstractFunctionDecl(DeclKind Kind, DeclContext *Parent, DeclName Name,
48704903
SourceLoc NameLoc, bool Throws, SourceLoc ThrowsLoc,
48714904
unsigned NumParameterLists,
@@ -4903,14 +4936,32 @@ class AbstractFunctionDecl : public ValueDecl, public GenericContext {
49034936
bool isTransparent() const;
49044937

49054938
// Expose our import as member status
4906-
bool isImportAsMember() const { return IAMStatus.isImportAsMember(); }
4907-
bool isImportAsInstanceMember() const { return IAMStatus.isInstance(); }
4908-
bool isImportAsStaticMember() const { return IAMStatus.isStatic(); }
4909-
uint8_t getSelfIndex() const { return IAMStatus.getSelfIndex(); }
4910-
ImportAsMemberStatus getImportAsMemberStatus() const { return IAMStatus; }
4939+
ImportAsMemberStatus getImportAsMemberStatus() const {
4940+
return ImportAsMemberStatus(AbstractFunctionDeclBits.IAMStatus);
4941+
}
4942+
bool isImportAsMember() const {
4943+
return getImportAsMemberStatus().isImportAsMember();
4944+
}
4945+
bool isImportAsInstanceMember() const {
4946+
return getImportAsMemberStatus().isInstance();
4947+
}
4948+
bool isImportAsStaticMember() const {
4949+
return getImportAsMemberStatus().isStatic();
4950+
}
4951+
uint8_t getSelfIndex() const {
4952+
return getImportAsMemberStatus().getSelfIndex();
4953+
}
49114954

4912-
void setImportAsStaticMember() { IAMStatus.setStatic(); }
4913-
void setSelfIndex(uint8_t idx) { return IAMStatus.setSelfIndex(idx); }
4955+
void setImportAsStaticMember() {
4956+
auto newValue = getImportAsMemberStatus();
4957+
newValue.setStatic();
4958+
AbstractFunctionDeclBits.IAMStatus = newValue.getRawValue();
4959+
}
4960+
void setSelfIndex(uint8_t idx) {
4961+
auto newValue = getImportAsMemberStatus();
4962+
newValue.setSelfIndex(idx);
4963+
AbstractFunctionDeclBits.IAMStatus = newValue.getRawValue();
4964+
}
49144965

49154966
public:
49164967
/// Retrieve the location of the 'throws' keyword, if present.
@@ -5461,15 +5512,13 @@ class EnumCaseDecl final : public Decl,
54615512
friend TrailingObjects;
54625513
SourceLoc CaseLoc;
54635514

5464-
/// The number of tail-allocated element pointers.
5465-
unsigned NumElements;
5466-
54675515
EnumCaseDecl(SourceLoc CaseLoc,
54685516
ArrayRef<EnumElementDecl *> Elements,
54695517
DeclContext *DC)
54705518
: Decl(DeclKind::EnumCase, DC),
5471-
CaseLoc(CaseLoc), NumElements(Elements.size())
5519+
CaseLoc(CaseLoc)
54725520
{
5521+
EnumCaseDeclBits.NumElements = Elements.size();
54735522
std::uninitialized_copy(Elements.begin(), Elements.end(),
54745523
getTrailingObjects<EnumElementDecl *>());
54755524
}
@@ -5481,7 +5530,8 @@ class EnumCaseDecl final : public Decl,
54815530

54825531
/// Get the list of elements declared in this case.
54835532
ArrayRef<EnumElementDecl *> getElements() const {
5484-
return {getTrailingObjects<EnumElementDecl *>(), NumElements};
5533+
return {getTrailingObjects<EnumElementDecl *>(),
5534+
EnumCaseDeclBits.NumElements};
54855535
}
54865536

54875537
SourceLoc getLoc() const {

0 commit comments

Comments
 (0)