Skip to content

Commit e482bcb

Browse files
authored
Merge pull request #13079 from davezarzycki/nfc_ExtInfo_feedback
2 parents 603e535 + 5cc0d83 commit e482bcb

File tree

2 files changed

+30
-18
lines changed

2 files changed

+30
-18
lines changed

include/swift/AST/Types.h

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,8 @@ class alignas(1 << TypeAlignInBits) TypeBase {
289289

290290
/// Extra information which affects how the function is called, like
291291
/// regparm and the calling convention.
292-
unsigned ExtInfo : 7;
292+
enum { NumExtInfoBits = 7 };
293+
unsigned ExtInfo : NumExtInfoBits;
293294
};
294295
enum { NumAnyFunctionTypeBits = NumTypeBaseBits + 7 };
295296
static_assert(NumAnyFunctionTypeBits <= 32, "fits in an unsigned");
@@ -316,7 +317,8 @@ class alignas(1 << TypeAlignInBits) TypeBase {
316317

317318
struct SILFunctionTypeBitfields {
318319
unsigned : NumTypeBaseBits;
319-
unsigned ExtInfo : 6;
320+
enum { NumExtInfoBits = 6 };
321+
unsigned ExtInfo : NumExtInfoBits;
320322
unsigned CalleeConvention : 3;
321323
unsigned HasErrorResult : 1;
322324
unsigned CoroutineKind : 2;
@@ -2392,20 +2394,21 @@ class AnyFunctionType : public TypeBase {
23922394
/// \brief A class which abstracts out some details necessary for
23932395
/// making a call.
23942396
class ExtInfo {
2395-
// NOTE: If bits are added or removed, then TypeBase::AnyFunctionTypeBits
2396-
// must be updated to match.
2397-
2397+
// If bits are added or removed, then TypeBase::AnyFunctionTypeBits
2398+
// and NumMaskBits must be updated, and they must match.
2399+
//
23982400
// |representation|isAutoClosure|noEscape|throws|
23992401
// | 0 .. 3 | 4 | 5 | 6 |
24002402
//
24012403
enum : unsigned {
2402-
RepresentationMask = 0x0F,
2403-
AutoClosureMask = 0x10,
2404-
NoEscapeMask = 0x20,
2405-
ThrowsMask = 0x40,
2404+
RepresentationMask = 0xF << 0,
2405+
AutoClosureMask = 1 << 4,
2406+
NoEscapeMask = 1 << 5,
2407+
ThrowsMask = 1 << 6,
2408+
NumMaskBits = 7
24062409
};
24072410

2408-
unsigned Bits;
2411+
unsigned Bits; // Naturally sized for speed.
24092412

24102413
ExtInfo(unsigned Bits) : Bits(Bits) {}
24112414

@@ -2505,7 +2508,7 @@ class AnyFunctionType : public TypeBase {
25052508
return ExtInfo(Bits & ~ThrowsMask);
25062509
}
25072510

2508-
uint16_t getFuncAttrKey() const {
2511+
unsigned getFuncAttrKey() const {
25092512
return Bits;
25102513
}
25112514

@@ -2539,7 +2542,11 @@ class AnyFunctionType : public TypeBase {
25392542
: TypeBase(Kind, CanTypeContext, properties), Input(Input), Output(Output),
25402543
NumParams(NumParams) {
25412544
AnyFunctionTypeBits.ExtInfo = Info.Bits;
2545+
// The use of both assert() and static_assert() is intentional.
25422546
assert(AnyFunctionTypeBits.ExtInfo == Info.Bits && "Bits were dropped!");
2547+
static_assert(ExtInfo::NumMaskBits ==
2548+
AnyFunctionTypeBitfields::NumExtInfoBits,
2549+
"ExtInfo and AnyFunctionTypeBitfields must agree on bit size");
25432550
}
25442551

25452552
public:
@@ -3249,19 +3256,20 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,
32493256
/// \brief A class which abstracts out some details necessary for
32503257
/// making a call.
32513258
class ExtInfo {
3252-
// NOTE: If bits are added or removed, then TypeBase::SILFunctionTypeBits
3253-
// must be updated to match.
3259+
// If bits are added or removed, then TypeBase::SILFunctionTypeBits
3260+
// and NumMaskBits must be updated, and they must match.
32543261

32553262
// |representation|pseudogeneric| noescape |
32563263
// | 0 .. 3 | 4 | 5 |
32573264
//
32583265
enum : unsigned {
3259-
RepresentationMask = 0x0F,
3260-
PseudogenericMask = 0x10,
3261-
NoEscapeMask = 0x20,
3266+
RepresentationMask = 0xF << 0,
3267+
PseudogenericMask = 1 << 4,
3268+
NoEscapeMask = 1 << 5,
3269+
NumMaskBits = 6
32623270
};
32633271

3264-
unsigned Bits;
3272+
unsigned Bits; // Naturally sized for speed.
32653273

32663274
ExtInfo(unsigned Bits) : Bits(Bits) {}
32673275

@@ -3364,7 +3372,7 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,
33643372
return ExtInfo(Bits & ~NoEscapeMask);
33653373
}
33663374

3367-
uint16_t getFuncAttrKey() const {
3375+
unsigned getFuncAttrKey() const {
33683376
return Bits;
33693377
}
33703378

lib/AST/ASTContext.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3869,7 +3869,11 @@ SILFunctionType::SILFunctionType(GenericSignature *genericSig, ExtInfo ext,
38693869

38703870
SILFunctionTypeBits.HasErrorResult = errorResult.hasValue();
38713871
SILFunctionTypeBits.ExtInfo = ext.Bits;
3872+
// The use of both assert() and static_assert() below is intentional.
38723873
assert(SILFunctionTypeBits.ExtInfo == ext.Bits && "Bits were dropped!");
3874+
static_assert(ExtInfo::NumMaskBits ==
3875+
SILFunctionTypeBitfields::NumExtInfoBits,
3876+
"ExtInfo and SILFunctionTypeBitfields must agree on bit size");
38733877
SILFunctionTypeBits.CoroutineKind = unsigned(coroutineKind);
38743878
NumParameters = params.size();
38753879
if (coroutineKind == SILCoroutineKind::None) {

0 commit comments

Comments
 (0)