Skip to content

Commit 392e336

Browse files
committed
[AST] NFC: Make Decl bitfield be 64 bit
1 parent 9da4373 commit 392e336

File tree

1 file changed

+61
-164
lines changed

1 file changed

+61
-164
lines changed

include/swift/AST/Decl.h

Lines changed: 61 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,19 @@ struct OverloadSignature {
228228
/// Determine whether two overload signatures conflict.
229229
bool conflicting(const OverloadSignature& sig1, const OverloadSignature& sig2);
230230

231+
#define BITFIELD_START(D, PD, C) \
232+
enum { Num##D##Bits = Num##PD##Bits + C }; \
233+
static_assert(Num##D##Bits <= 64, "fits in a uint64_t"); \
234+
class D##Bitfields { \
235+
friend class D; \
236+
uint64_t : Num##PD##Bits
237+
238+
#define BITFIELD_END }
239+
231240
/// Decl - Base class for all declarations in Swift.
232241
class alignas(1 << DeclAlignInBits) Decl {
233-
class DeclBitfields {
234-
friend class Decl;
242+
enum { Num_DeclBits = 0 };
243+
BITFIELD_START(Decl, _Decl, 13);
235244
unsigned Kind : 6;
236245

237246
/// \brief Whether this declaration is invalid.
@@ -260,14 +269,9 @@ class alignas(1 << DeclAlignInBits) Decl {
260269
/// \brief Whether this declaration was added to the surrounding
261270
/// DeclContext of an active #if config clause.
262271
unsigned EscapedFromIfConfig : 1;
263-
};
264-
enum { NumDeclBits = 13 };
265-
static_assert(NumDeclBits <= 32, "fits in an unsigned");
272+
BITFIELD_END;
266273

267-
class PatternBindingDeclBitfields {
268-
friend class PatternBindingDecl;
269-
unsigned : NumDeclBits;
270-
274+
BITFIELD_START(PatternBindingDecl, Decl, 19);
271275
/// \brief Whether this pattern binding declares static variables.
272276
unsigned IsStatic : 1;
273277

@@ -276,14 +280,11 @@ class alignas(1 << DeclAlignInBits) Decl {
276280

277281
/// \brief The number of pattern binding declarations.
278282
unsigned NumPatternEntries : 16;
279-
};
280-
enum { NumPatternBindingDeclBits = NumDeclBits + 19 };
281-
static_assert(NumPatternBindingDeclBits <= 32, "fits in an unsigned");
283+
BITFIELD_END;
282284

283-
class ValueDeclBitfields {
284-
friend class ValueDecl;
285+
BITFIELD_START(ValueDecl, Decl, 3);
285286
friend class MemberLookupTable;
286-
unsigned : NumDeclBits;
287+
287288
unsigned AlreadyInLookupTable : 1;
288289

289290
/// Whether we have already checked whether this declaration is a
@@ -293,14 +294,9 @@ class alignas(1 << DeclAlignInBits) Decl {
293294
/// Whether the decl can be accessed by swift users; for instance,
294295
/// a.storage for lazy var a is a decl that cannot be accessed.
295296
unsigned IsUserAccessible : 1;
296-
};
297-
enum { NumValueDeclBits = NumDeclBits + 3 };
298-
static_assert(NumValueDeclBits <= 32, "fits in an unsigned");
299-
300-
class AbstractStorageDeclBitfields {
301-
friend class AbstractStorageDecl;
302-
unsigned : NumValueDeclBits;
297+
BITFIELD_END;
303298

299+
BITFIELD_START(AbstractStorageDecl, ValueDecl, 7);
304300
/// Whether we are overridden later
305301
unsigned Overridden : 1;
306302

@@ -312,14 +308,9 @@ class alignas(1 << DeclAlignInBits) Decl {
312308

313309
/// The storage kind.
314310
unsigned StorageKind : 4;
315-
};
316-
enum { NumAbstractStorageDeclBits = NumValueDeclBits + 7 };
317-
static_assert(NumAbstractStorageDeclBits <= 32, "fits in an unsigned");
318-
319-
class VarDeclBitfields {
320-
friend class VarDecl;
321-
unsigned : NumAbstractStorageDeclBits;
311+
BITFIELD_END;
322312

313+
BITFIELD_START(VarDecl, AbstractStorageDecl, 6);
323314
/// \brief Whether this property is a type property (currently unfortunately
324315
/// called 'static').
325316
unsigned IsStatic : 1;
@@ -339,29 +330,18 @@ class alignas(1 << DeclAlignInBits) Decl {
339330
/// \brief Whether this is a property used in expressions in the debugger.
340331
/// It is up to the debugger to instruct SIL how to access this variable.
341332
unsigned IsDebuggerVar : 1;
333+
BITFIELD_END;
342334

343-
};
344-
enum { NumVarDeclBits = NumAbstractStorageDeclBits + 6 };
345-
static_assert(NumVarDeclBits <= 32, "fits in an unsigned");
346-
347-
class EnumElementDeclBitfields {
348-
friend class EnumElementDecl;
349-
unsigned : NumValueDeclBits;
350-
335+
BITFIELD_START(EnumElementDecl, ValueDecl, 3);
351336
/// \brief Whether or not this element directly or indirectly references
352337
/// the enum type.
353338
unsigned Recursiveness : 2;
354339

355340
/// \brief Whether or not this element has an associated value.
356341
unsigned HasArgumentType : 1;
357-
};
358-
enum { NumEnumElementDeclBits = NumValueDeclBits + 3 };
359-
static_assert(NumEnumElementDeclBits <= 32, "fits in an unsigned");
342+
BITFIELD_END;
360343

361-
class AbstractFunctionDeclBitfields {
362-
friend class AbstractFunctionDecl;
363-
unsigned : NumValueDeclBits;
364-
344+
BITFIELD_START(AbstractFunctionDecl, ValueDecl, 13);
365345
/// \see AbstractFunctionDecl::BodyKind
366346
unsigned BodyKind : 3;
367347

@@ -382,72 +362,41 @@ class alignas(1 << DeclAlignInBits) Decl {
382362

383363
/// The ResilienceExpansion to use for default arguments.
384364
unsigned DefaultArgumentResilienceExpansion : 1;
385-
};
386-
enum { NumAbstractFunctionDeclBits = NumValueDeclBits + 13 };
387-
static_assert(NumAbstractFunctionDeclBits <= 32, "fits in an unsigned");
388-
389-
class FuncDeclBitfields {
390-
friend class FuncDecl;
391-
unsigned : NumAbstractFunctionDeclBits;
365+
BITFIELD_END;
392366

367+
BITFIELD_START(FuncDecl, AbstractFunctionDecl, 3);
393368
/// Whether this function is a 'static' method.
394369
unsigned IsStatic : 1;
395370

396371
/// \brief Whether 'static' or 'class' was used.
397372
unsigned StaticSpelling : 2;
398-
};
399-
enum { NumFuncDeclBits = NumAbstractFunctionDeclBits + 3 };
400-
static_assert(NumFuncDeclBits <= 32, "fits in an unsigned");
401-
402-
class ConstructorDeclBitfields {
403-
friend class ConstructorDecl;
404-
unsigned : NumAbstractFunctionDeclBits;
373+
BITFIELD_END;
405374

375+
BITFIELD_START(ConstructorDecl, AbstractFunctionDecl, 3);
406376
/// The body initialization kind (+1), or zero if not yet computed.
407377
///
408378
/// This value is cached but is not serialized, because it is a property
409379
/// of the definition of the constructor that is useful only to semantic
410380
/// analysis and SIL generation.
411381
unsigned ComputedBodyInitKind : 3;
412-
};
413-
enum { NumConstructorDeclBits = NumAbstractFunctionDeclBits + 3 };
414-
static_assert(NumConstructorDeclBits <= 32, "fits in an unsigned");
415-
416-
class TypeDeclBitfields {
417-
friend class TypeDecl;
418-
unsigned : NumValueDeclBits;
382+
BITFIELD_END;
419383

384+
BITFIELD_START(TypeDecl, ValueDecl, 1);
420385
/// Whether we have already checked the inheritance clause.
421386
///
422387
/// FIXME: Is this too fine-grained?
423388
unsigned CheckedInheritanceClause : 1;
424-
};
425-
426-
enum { NumTypeDeclBits = NumValueDeclBits + 1 };
427-
static_assert(NumTypeDeclBits <= 32, "fits in an unsigned");
428-
429-
class GenericTypeDeclBitfields {
430-
friend class GenericTypeDecl;
431-
unsigned : NumTypeDeclBits;
432-
};
389+
BITFIELD_END;
433390

434-
enum { NumGenericTypeDeclBits = NumTypeDeclBits };
435-
static_assert(NumGenericTypeDeclBits <= 32, "fits in an unsigned");
436-
437-
class TypeAliasDeclBitfields {
438-
friend class TypeAliasDecl;
439-
unsigned : NumGenericTypeDeclBits;
391+
BITFIELD_START(GenericTypeDecl, TypeDecl, 0);
392+
BITFIELD_END;
440393

394+
BITFIELD_START(TypeAliasDecl, GenericTypeDecl, 1);
441395
/// Whether the typealias forwards perfectly to its underlying type.
442396
unsigned IsCompatibilityAlias : 1;
443-
};
444-
enum { NumTypeAliasDeclBits = NumGenericTypeDeclBits + 1 };
445-
static_assert(NumTypeAliasDeclBits <= 32, "fits in an unsigned");
397+
BITFIELD_END;
446398

447-
class NominalTypeDeclBitFields {
448-
friend class NominalTypeDecl;
449-
unsigned : NumGenericTypeDeclBits;
450-
399+
BITFIELD_START(NominalTypeDecl, GenericTypeDecl, 4);
451400
/// Whether or not the nominal type decl has delayed protocol or member
452401
/// declarations.
453402
unsigned HasDelayedMembers : 1;
@@ -462,14 +411,9 @@ class alignas(1 << DeclAlignInBits) Decl {
462411
/// Whether we have already validated all members of the type that
463412
/// affect layout.
464413
unsigned HasValidatedLayout : 1;
465-
};
466-
enum { NumNominalTypeDeclBits = NumGenericTypeDeclBits + 4 };
467-
static_assert(NumNominalTypeDeclBits <= 32, "fits in an unsigned");
468-
469-
class ProtocolDeclBitfields {
470-
friend class ProtocolDecl;
471-
unsigned : NumNominalTypeDeclBits;
414+
BITFIELD_END;
472415

416+
BITFIELD_START(ProtocolDecl, NominalTypeDecl, 8);
473417
/// Whether the \c RequiresClass bit is valid.
474418
unsigned RequiresClassValid : 1;
475419

@@ -490,14 +434,9 @@ class alignas(1 << DeclAlignInBits) Decl {
490434

491435
/// The stage of the circularity check for this protocol.
492436
unsigned Circularity : 2;
493-
};
494-
enum { NumProtocolDeclBits = NumNominalTypeDeclBits + 8 };
495-
static_assert(NumProtocolDeclBits <= 32, "fits in an unsigned");
496-
497-
class ClassDeclBitfields {
498-
friend class ClassDecl;
499-
unsigned : NumNominalTypeDeclBits;
437+
BITFIELD_END;
500438

439+
BITFIELD_START(ClassDecl, NominalTypeDecl, 8);
501440
/// The stage of the inheritance circularity check for this class.
502441
unsigned Circularity : 2;
503442

@@ -520,70 +459,40 @@ class alignas(1 << DeclAlignInBits) Decl {
520459
/// it is implicit. This bit is used during parsing and type-checking to
521460
/// control inserting the implicit destructor.
522461
unsigned HasDestructorDecl : 1;
462+
BITFIELD_END;
523463

524-
};
525-
enum { NumClassDeclBits = NumNominalTypeDeclBits + 8 };
526-
static_assert(NumClassDeclBits <= 32, "fits in an unsigned");
527-
528-
class StructDeclBitfields {
529-
friend class StructDecl;
530-
unsigned : NumNominalTypeDeclBits;
531-
464+
BITFIELD_START(StructDecl, NominalTypeDecl, 1);
532465
/// True if this struct has storage for fields that aren't accessible in
533466
/// Swift.
534467
unsigned HasUnreferenceableStorage : 1;
535-
};
536-
enum { NumStructDeclBits = NumNominalTypeDeclBits + 1 };
537-
static_assert(NumStructDeclBits <= 32, "fits in an unsigned");
468+
BITFIELD_END;
538469

539-
class EnumDeclBitfields {
540-
friend class EnumDecl;
541-
unsigned : NumNominalTypeDeclBits;
542-
470+
BITFIELD_START(EnumDecl, NominalTypeDecl, 4);
543471
/// The stage of the raw type circularity check for this class.
544472
unsigned Circularity : 2;
545473

546474
/// True if the enum has cases and at least one case has associated values.
547475
mutable unsigned HasAssociatedValues : 2;
548-
};
549-
enum { NumEnumDeclBits = NumNominalTypeDeclBits + 4 };
550-
static_assert(NumEnumDeclBits <= 32, "fits in an unsigned");
551-
552-
class PrecedenceGroupDeclBitfields {
553-
friend class PrecedenceGroupDecl;
554-
unsigned : NumDeclBits;
476+
BITFIELD_END;
555477

478+
BITFIELD_START(PrecedenceGroupDecl, Decl, 11);
556479
/// The group's associativity. A value of the Associativity enum.
557480
unsigned Associativity : 2;
558481

559482
/// Is this an assignment operator?
560483
unsigned IsAssignment : 1;
561-
};
562-
enum { NumPrecedenceGroupDeclBits = NumDeclBits + 11 };
563-
static_assert(NumPrecedenceGroupDeclBits <= 32, "fits in an unsigned");
484+
BITFIELD_END;
564485

565-
class AssociatedTypeDeclBitfields {
566-
friend class AssociatedTypeDecl;
567-
unsigned : NumTypeDeclBits;
486+
BITFIELD_START(AssociatedTypeDecl, TypeDecl, 2);
568487
unsigned ComputedOverridden : 1;
569488
unsigned HasOverridden : 1;
570-
};
571-
enum { NumAssociatedTypeDeclBits = NumTypeDeclBits + 2 };
572-
static_assert(NumAssociatedTypeDeclBits <= 32, "fits in an unsigned");
573-
574-
class ImportDeclBitfields {
575-
friend class ImportDecl;
576-
unsigned : NumDeclBits;
489+
BITFIELD_END;
577490

491+
BITFIELD_START(ImportDecl, Decl, 3);
578492
unsigned ImportKind : 3;
579-
};
580-
enum { NumImportDeclBits = NumDeclBits + 3 };
581-
static_assert(NumImportDeclBits <= 32, "fits in an unsigned");
582-
583-
class ExtensionDeclBitfields {
584-
friend class ExtensionDecl;
585-
unsigned : NumDeclBits;
493+
BITFIELD_END;
586494

495+
BITFIELD_START(ExtensionDecl, Decl, 5);
587496
/// Whether we have already checked the inheritance clause.
588497
///
589498
/// FIXME: Is this too fine-grained?
@@ -598,30 +507,20 @@ class alignas(1 << DeclAlignInBits) Decl {
598507

599508
/// Whether there is are lazily-loaded conformances for this extension.
600509
unsigned HasLazyConformances : 1;
601-
};
602-
enum { NumExtensionDeclBits = NumDeclBits + 5 };
603-
static_assert(NumExtensionDeclBits <= 32, "fits in an unsigned");
604-
605-
class IfConfigDeclBitfields {
606-
friend class IfConfigDecl;
607-
unsigned : NumDeclBits;
510+
BITFIELD_END;
608511

512+
BITFIELD_START(IfConfigDecl, Decl, 1);
609513
/// Whether this decl is missing its closing '#endif'.
610514
unsigned HadMissingEnd : 1;
611-
};
612-
enum { NumIfConfigDeclBits = NumDeclBits + 1 };
613-
static_assert(NumIfConfigDeclBits <= 32, "fits in an unsigned");
614-
615-
class MissingMemberDeclBitfields {
616-
friend class MissingMemberDecl;
617-
unsigned : NumDeclBits;
515+
BITFIELD_END;
618516

517+
BITFIELD_START(MissingMemberDecl, Decl, 3);
619518
unsigned NumberOfVTableEntries : 2;
620519
unsigned NumberOfFieldOffsetVectorEntries : 1;
621-
};
622-
enum { NumMissingMemberDeclBits = NumDeclBits + 3 };
623-
static_assert(NumMissingMemberDeclBits <= 32, "fits in an unsigned");
520+
BITFIELD_END;
624521

522+
#undef BITFIELD_START
523+
#undef BITFIELD_END
625524
protected:
626525
union {
627526
DeclBitfields DeclBits;
@@ -636,7 +535,7 @@ class alignas(1 << DeclAlignInBits) Decl {
636535
TypeDeclBitfields TypeDeclBits;
637536
GenericTypeDeclBitfields GenericTypeDeclBits;
638537
TypeAliasDeclBitfields TypeAliasDeclBits;
639-
NominalTypeDeclBitFields NominalTypeDeclBits;
538+
NominalTypeDeclBitfields NominalTypeDeclBits;
640539
ProtocolDeclBitfields ProtocolDeclBits;
641540
ClassDeclBitfields ClassDeclBits;
642541
StructDeclBitfields StructDeclBits;
@@ -647,11 +546,9 @@ class alignas(1 << DeclAlignInBits) Decl {
647546
ExtensionDeclBitfields ExtensionDeclBits;
648547
IfConfigDeclBitfields IfConfigDeclBits;
649548
MissingMemberDeclBitfields MissingMemberDeclBits;
650-
uint32_t OpaqueBits;
549+
uint64_t OpaqueBits;
651550
};
652551

653-
// FIXME: Unused padding here.
654-
655552
// Storage for the declaration attributes.
656553
DeclAttributes Attrs;
657554

0 commit comments

Comments
 (0)