@@ -228,10 +228,19 @@ struct OverloadSignature {
228
228
// / Determine whether two overload signatures conflict.
229
229
bool conflicting (const OverloadSignature& sig1, const OverloadSignature& sig2);
230
230
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
+
231
240
// / Decl - Base class for all declarations in Swift.
232
241
class alignas (1 << DeclAlignInBits) Decl {
233
- class DeclBitfields {
234
- friend class Decl ;
242
+ enum { Num_DeclBits = 0 };
243
+ BITFIELD_START (Decl, _Decl, 13 ) ;
235
244
unsigned Kind : 6 ;
236
245
237
246
// / \brief Whether this declaration is invalid.
@@ -260,14 +269,9 @@ class alignas(1 << DeclAlignInBits) Decl {
260
269
// / \brief Whether this declaration was added to the surrounding
261
270
// / DeclContext of an active #if config clause.
262
271
unsigned EscapedFromIfConfig : 1 ;
263
- };
264
- enum { NumDeclBits = 13 };
265
- static_assert (NumDeclBits <= 32 , " fits in an unsigned" );
272
+ BITFIELD_END;
266
273
267
- class PatternBindingDeclBitfields {
268
- friend class PatternBindingDecl ;
269
- unsigned : NumDeclBits;
270
-
274
+ BITFIELD_START (PatternBindingDecl, Decl, 19 );
271
275
// / \brief Whether this pattern binding declares static variables.
272
276
unsigned IsStatic : 1 ;
273
277
@@ -276,14 +280,11 @@ class alignas(1 << DeclAlignInBits) Decl {
276
280
277
281
// / \brief The number of pattern binding declarations.
278
282
unsigned NumPatternEntries : 16 ;
279
- };
280
- enum { NumPatternBindingDeclBits = NumDeclBits + 19 };
281
- static_assert (NumPatternBindingDeclBits <= 32 , " fits in an unsigned" );
283
+ BITFIELD_END;
282
284
283
- class ValueDeclBitfields {
284
- friend class ValueDecl ;
285
+ BITFIELD_START (ValueDecl, Decl, 3 );
285
286
friend class MemberLookupTable ;
286
- unsigned : NumDeclBits;
287
+
287
288
unsigned AlreadyInLookupTable : 1 ;
288
289
289
290
// / Whether we have already checked whether this declaration is a
@@ -293,14 +294,9 @@ class alignas(1 << DeclAlignInBits) Decl {
293
294
// / Whether the decl can be accessed by swift users; for instance,
294
295
// / a.storage for lazy var a is a decl that cannot be accessed.
295
296
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;
303
298
299
+ BITFIELD_START (AbstractStorageDecl, ValueDecl, 7 );
304
300
// / Whether we are overridden later
305
301
unsigned Overridden : 1 ;
306
302
@@ -312,14 +308,9 @@ class alignas(1 << DeclAlignInBits) Decl {
312
308
313
309
// / The storage kind.
314
310
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;
322
312
313
+ BITFIELD_START (VarDecl, AbstractStorageDecl, 6 );
323
314
// / \brief Whether this property is a type property (currently unfortunately
324
315
// / called 'static').
325
316
unsigned IsStatic : 1 ;
@@ -339,29 +330,18 @@ class alignas(1 << DeclAlignInBits) Decl {
339
330
// / \brief Whether this is a property used in expressions in the debugger.
340
331
// / It is up to the debugger to instruct SIL how to access this variable.
341
332
unsigned IsDebuggerVar : 1 ;
333
+ BITFIELD_END;
342
334
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 );
351
336
// / \brief Whether or not this element directly or indirectly references
352
337
// / the enum type.
353
338
unsigned Recursiveness : 2 ;
354
339
355
340
// / \brief Whether or not this element has an associated value.
356
341
unsigned HasArgumentType : 1 ;
357
- };
358
- enum { NumEnumElementDeclBits = NumValueDeclBits + 3 };
359
- static_assert (NumEnumElementDeclBits <= 32 , " fits in an unsigned" );
342
+ BITFIELD_END;
360
343
361
- class AbstractFunctionDeclBitfields {
362
- friend class AbstractFunctionDecl ;
363
- unsigned : NumValueDeclBits;
364
-
344
+ BITFIELD_START (AbstractFunctionDecl, ValueDecl, 13 );
365
345
// / \see AbstractFunctionDecl::BodyKind
366
346
unsigned BodyKind : 3 ;
367
347
@@ -382,72 +362,41 @@ class alignas(1 << DeclAlignInBits) Decl {
382
362
383
363
// / The ResilienceExpansion to use for default arguments.
384
364
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;
392
366
367
+ BITFIELD_START (FuncDecl, AbstractFunctionDecl, 3 );
393
368
// / Whether this function is a 'static' method.
394
369
unsigned IsStatic : 1 ;
395
370
396
371
// / \brief Whether 'static' or 'class' was used.
397
372
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;
405
374
375
+ BITFIELD_START (ConstructorDecl, AbstractFunctionDecl, 3 );
406
376
// / The body initialization kind (+1), or zero if not yet computed.
407
377
// /
408
378
// / This value is cached but is not serialized, because it is a property
409
379
// / of the definition of the constructor that is useful only to semantic
410
380
// / analysis and SIL generation.
411
381
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;
419
383
384
+ BITFIELD_START (TypeDecl, ValueDecl, 1 );
420
385
// / Whether we have already checked the inheritance clause.
421
386
// /
422
387
// / FIXME: Is this too fine-grained?
423
388
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;
433
390
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;
440
393
394
+ BITFIELD_START (TypeAliasDecl, GenericTypeDecl, 1 );
441
395
// / Whether the typealias forwards perfectly to its underlying type.
442
396
unsigned IsCompatibilityAlias : 1 ;
443
- };
444
- enum { NumTypeAliasDeclBits = NumGenericTypeDeclBits + 1 };
445
- static_assert (NumTypeAliasDeclBits <= 32 , " fits in an unsigned" );
397
+ BITFIELD_END;
446
398
447
- class NominalTypeDeclBitFields {
448
- friend class NominalTypeDecl ;
449
- unsigned : NumGenericTypeDeclBits;
450
-
399
+ BITFIELD_START (NominalTypeDecl, GenericTypeDecl, 4 );
451
400
// / Whether or not the nominal type decl has delayed protocol or member
452
401
// / declarations.
453
402
unsigned HasDelayedMembers : 1 ;
@@ -462,14 +411,9 @@ class alignas(1 << DeclAlignInBits) Decl {
462
411
// / Whether we have already validated all members of the type that
463
412
// / affect layout.
464
413
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;
472
415
416
+ BITFIELD_START (ProtocolDecl, NominalTypeDecl, 8 );
473
417
// / Whether the \c RequiresClass bit is valid.
474
418
unsigned RequiresClassValid : 1 ;
475
419
@@ -490,14 +434,9 @@ class alignas(1 << DeclAlignInBits) Decl {
490
434
491
435
// / The stage of the circularity check for this protocol.
492
436
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;
500
438
439
+ BITFIELD_START (ClassDecl, NominalTypeDecl, 8 );
501
440
// / The stage of the inheritance circularity check for this class.
502
441
unsigned Circularity : 2 ;
503
442
@@ -520,70 +459,40 @@ class alignas(1 << DeclAlignInBits) Decl {
520
459
// / it is implicit. This bit is used during parsing and type-checking to
521
460
// / control inserting the implicit destructor.
522
461
unsigned HasDestructorDecl : 1 ;
462
+ BITFIELD_END;
523
463
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 );
532
465
// / True if this struct has storage for fields that aren't accessible in
533
466
// / Swift.
534
467
unsigned HasUnreferenceableStorage : 1 ;
535
- };
536
- enum { NumStructDeclBits = NumNominalTypeDeclBits + 1 };
537
- static_assert (NumStructDeclBits <= 32 , " fits in an unsigned" );
468
+ BITFIELD_END;
538
469
539
- class EnumDeclBitfields {
540
- friend class EnumDecl ;
541
- unsigned : NumNominalTypeDeclBits;
542
-
470
+ BITFIELD_START (EnumDecl, NominalTypeDecl, 4 );
543
471
// / The stage of the raw type circularity check for this class.
544
472
unsigned Circularity : 2 ;
545
473
546
474
// / True if the enum has cases and at least one case has associated values.
547
475
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;
555
477
478
+ BITFIELD_START (PrecedenceGroupDecl, Decl, 11 );
556
479
// / The group's associativity. A value of the Associativity enum.
557
480
unsigned Associativity : 2 ;
558
481
559
482
// / Is this an assignment operator?
560
483
unsigned IsAssignment : 1 ;
561
- };
562
- enum { NumPrecedenceGroupDeclBits = NumDeclBits + 11 };
563
- static_assert (NumPrecedenceGroupDeclBits <= 32 , " fits in an unsigned" );
484
+ BITFIELD_END;
564
485
565
- class AssociatedTypeDeclBitfields {
566
- friend class AssociatedTypeDecl ;
567
- unsigned : NumTypeDeclBits;
486
+ BITFIELD_START (AssociatedTypeDecl, TypeDecl, 2 );
568
487
unsigned ComputedOverridden : 1 ;
569
488
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;
577
490
491
+ BITFIELD_START (ImportDecl, Decl, 3 );
578
492
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;
586
494
495
+ BITFIELD_START (ExtensionDecl, Decl, 5 );
587
496
// / Whether we have already checked the inheritance clause.
588
497
// /
589
498
// / FIXME: Is this too fine-grained?
@@ -598,30 +507,20 @@ class alignas(1 << DeclAlignInBits) Decl {
598
507
599
508
// / Whether there is are lazily-loaded conformances for this extension.
600
509
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;
608
511
512
+ BITFIELD_START (IfConfigDecl, Decl, 1 );
609
513
// / Whether this decl is missing its closing '#endif'.
610
514
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;
618
516
517
+ BITFIELD_START (MissingMemberDecl, Decl, 3 );
619
518
unsigned NumberOfVTableEntries : 2 ;
620
519
unsigned NumberOfFieldOffsetVectorEntries : 1 ;
621
- };
622
- enum { NumMissingMemberDeclBits = NumDeclBits + 3 };
623
- static_assert (NumMissingMemberDeclBits <= 32 , " fits in an unsigned" );
520
+ BITFIELD_END;
624
521
522
+ #undef BITFIELD_START
523
+ #undef BITFIELD_END
625
524
protected:
626
525
union {
627
526
DeclBitfields DeclBits;
@@ -636,7 +535,7 @@ class alignas(1 << DeclAlignInBits) Decl {
636
535
TypeDeclBitfields TypeDeclBits;
637
536
GenericTypeDeclBitfields GenericTypeDeclBits;
638
537
TypeAliasDeclBitfields TypeAliasDeclBits;
639
- NominalTypeDeclBitFields NominalTypeDeclBits;
538
+ NominalTypeDeclBitfields NominalTypeDeclBits;
640
539
ProtocolDeclBitfields ProtocolDeclBits;
641
540
ClassDeclBitfields ClassDeclBits;
642
541
StructDeclBitfields StructDeclBits;
@@ -647,11 +546,9 @@ class alignas(1 << DeclAlignInBits) Decl {
647
546
ExtensionDeclBitfields ExtensionDeclBits;
648
547
IfConfigDeclBitfields IfConfigDeclBits;
649
548
MissingMemberDeclBitfields MissingMemberDeclBits;
650
- uint32_t OpaqueBits;
549
+ uint64_t OpaqueBits;
651
550
};
652
551
653
- // FIXME: Unused padding here.
654
-
655
552
// Storage for the declaration attributes.
656
553
DeclAttributes Attrs;
657
554
0 commit comments