@@ -231,11 +231,12 @@ bool conflicting(const OverloadSignature& sig1, const OverloadSignature& sig2);
231
231
#define BITFIELD_START (D, PD, C ) \
232
232
enum { Num##D##Bits = Num##PD##Bits + C }; \
233
233
static_assert (Num##D##Bits <= 64 , " fits in a uint64_t" ); \
234
+ LLVM_PACKED_START; \
234
235
class D ##Bitfields { \
235
236
friend class D ; \
236
237
uint64_t : Num##PD##Bits
237
238
238
- #define BITFIELD_END }
239
+ #define BITFIELD_END }; LLVM_PACKED_END
239
240
240
241
// / Decl - Base class for all declarations in Swift.
241
242
class alignas (1 << DeclAlignInBits) Decl {
@@ -282,6 +283,13 @@ class alignas(1 << DeclAlignInBits) Decl {
282
283
unsigned NumPatternEntries : 16 ;
283
284
BITFIELD_END;
284
285
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
+
285
293
BITFIELD_START (ValueDecl, Decl, 3 );
286
294
friend class MemberLookupTable ;
287
295
@@ -353,13 +361,16 @@ class alignas(1 << DeclAlignInBits) Decl {
353
361
unsigned HasArgumentType : 1 ;
354
362
BITFIELD_END;
355
363
356
- BITFIELD_START (AbstractFunctionDecl, ValueDecl, 13 );
364
+ BITFIELD_START (AbstractFunctionDecl, ValueDecl, 21 );
357
365
// / \see AbstractFunctionDecl::BodyKind
358
366
unsigned BodyKind : 3 ;
359
367
360
368
// / Number of curried parameter lists.
361
369
unsigned NumParameterLists : 5 ;
362
370
371
+ // / Import as member status.
372
+ unsigned IAMStatus : 8 ;
373
+
363
374
// / Whether we are overridden later.
364
375
unsigned Overridden : 1 ;
365
376
@@ -424,6 +435,16 @@ class alignas(1 << DeclAlignInBits) Decl {
424
435
unsigned CheckedInheritanceClause : 1 ;
425
436
BITFIELD_END;
426
437
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
+
427
448
BITFIELD_START (GenericTypeDecl, TypeDecl, 0 );
428
449
BITFIELD_END;
429
450
@@ -449,7 +470,7 @@ class alignas(1 << DeclAlignInBits) Decl {
449
470
unsigned HasValidatedLayout : 1 ;
450
471
BITFIELD_END;
451
472
452
- BITFIELD_START (ProtocolDecl, NominalTypeDecl, 8 );
473
+ BITFIELD_START (ProtocolDecl, NominalTypeDecl, 43 );
453
474
// / Whether the \c RequiresClass bit is valid.
454
475
unsigned RequiresClassValid : 1 ;
455
476
@@ -468,11 +489,24 @@ class alignas(1 << DeclAlignInBits) Decl {
468
489
// / Whether the existential of this protocol can be represented.
469
490
unsigned ExistentialTypeSupported : 1 ;
470
491
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
+
471
502
// / The stage of the circularity check for this protocol.
472
503
unsigned Circularity : 2 ;
504
+
505
+ // / The number of requirements in the requirement signature.
506
+ unsigned NumRequirementsInSignature : 16 ;
473
507
BITFIELD_END;
474
508
475
- BITFIELD_START (ClassDecl, NominalTypeDecl, 8 );
509
+ BITFIELD_START (ClassDecl, NominalTypeDecl, 13 );
476
510
// / The stage of the inheritance circularity check for this class.
477
511
unsigned Circularity : 2 ;
478
512
@@ -495,6 +529,12 @@ class alignas(1 << DeclAlignInBits) Decl {
495
529
// / it is implicit. This bit is used during parsing and type-checking to
496
530
// / control inserting the implicit destructor.
497
531
unsigned HasDestructorDecl : 1 ;
532
+
533
+ // / Whether the class has @objc ancestry.
534
+ unsigned ObjCKind : 3 ;
535
+
536
+ unsigned HasMissingDesignatedInitializers : 1 ;
537
+ unsigned HasMissingVTableEntries : 1 ;
498
538
BITFIELD_END;
499
539
500
540
BITFIELD_START (StructDecl, NominalTypeDecl, 1 );
@@ -524,8 +564,11 @@ class alignas(1 << DeclAlignInBits) Decl {
524
564
unsigned HasOverridden : 1 ;
525
565
BITFIELD_END;
526
566
527
- BITFIELD_START (ImportDecl, Decl, 3 );
567
+ BITFIELD_START (ImportDecl, Decl, 11 );
528
568
unsigned ImportKind : 3 ;
569
+
570
+ // / The number of elements in this path.
571
+ unsigned NumPathElements : 8 ;
529
572
BITFIELD_END;
530
573
531
574
BITFIELD_START (ExtensionDecl, Decl, 5 );
@@ -561,6 +604,7 @@ class alignas(1 << DeclAlignInBits) Decl {
561
604
union {
562
605
DeclBitfields DeclBits;
563
606
PatternBindingDeclBitfields PatternBindingDeclBits;
607
+ EnumCaseDeclBitfields EnumCaseDeclBits;
564
608
ValueDeclBitfields ValueDeclBits;
565
609
AbstractStorageDeclBitfields AbstractStorageDeclBits;
566
610
AbstractFunctionDeclBitfields AbstractFunctionDeclBits;
@@ -570,6 +614,8 @@ class alignas(1 << DeclAlignInBits) Decl {
570
614
FuncDeclBitfields FuncDeclBits;
571
615
ConstructorDeclBitfields ConstructorDeclBits;
572
616
TypeDeclBitfields TypeDeclBits;
617
+ AbstractTypeParamDeclBitfields AbstractTypeParamDeclBit;
618
+ GenericTypeParamDeclBitfields GenericTypeParamDeclBits;
573
619
GenericTypeDeclBitfields GenericTypeDeclBits;
574
620
TypeAliasDeclBitfields TypeAliasDeclBits;
575
621
NominalTypeDeclBitfields NominalTypeDeclBits;
@@ -1450,9 +1496,6 @@ class ImportDecl final : public Decl,
1450
1496
SourceLoc ImportLoc;
1451
1497
SourceLoc KindLoc;
1452
1498
1453
- // / The number of elements in this path.
1454
- unsigned NumPathElements;
1455
-
1456
1499
// / The resolved module.
1457
1500
ModuleDecl *Mod = nullptr ;
1458
1501
// / The resolved decls if this is a decl import.
@@ -1481,7 +1524,8 @@ class ImportDecl final : public Decl,
1481
1524
static Optional<ImportKind> findBestImportKind (ArrayRef<ValueDecl *> Decls);
1482
1525
1483
1526
ArrayRef<AccessPathElement> getFullAccessPath () const {
1484
- return {getTrailingObjects<AccessPathElement>(), NumPathElements};
1527
+ return {getTrailingObjects<AccessPathElement>(),
1528
+ ImportDeclBits.NumPathElements };
1485
1529
}
1486
1530
1487
1531
ArrayRef<AccessPathElement> getModulePath () const {
@@ -2481,9 +2525,6 @@ class AbstractTypeParamDecl : public TypeDecl {
2481
2525
// / func min<T : Comparable>(x : T, y : T) -> T { ... }
2482
2526
// / \endcode
2483
2527
class GenericTypeParamDecl : public AbstractTypeParamDecl {
2484
- unsigned Depth : 16 ;
2485
- unsigned Index : 16 ;
2486
-
2487
2528
public:
2488
2529
static const unsigned InvalidDepth = 0xFFFF ;
2489
2530
@@ -2508,12 +2549,15 @@ class GenericTypeParamDecl : public AbstractTypeParamDecl {
2508
2549
// / \endcode
2509
2550
// /
2510
2551
// / 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 ; }
2512
2553
2513
2554
// / Set the depth of this generic type parameter.
2514
2555
// /
2515
2556
// / \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
+ }
2517
2561
2518
2562
// / The index of this generic type parameter within its generic parameter
2519
2563
// / list.
@@ -2525,7 +2569,7 @@ class GenericTypeParamDecl : public AbstractTypeParamDecl {
2525
2569
// / \endcode
2526
2570
// /
2527
2571
// / 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 ; }
2529
2573
2530
2574
SourceLoc getStartLoc () const { return getNameLoc (); }
2531
2575
SourceRange getSourceRange () const ;
@@ -3226,12 +3270,6 @@ class ClassDecl final : public NominalTypeDecl {
3226
3270
llvm::PointerIntPair<Type, 1 , bool > Superclass;
3227
3271
} LazySemanticInfo;
3228
3272
3229
- // / Whether the class has @objc ancestry.
3230
- unsigned ObjCKind : 3 ;
3231
-
3232
- unsigned HasMissingDesignatedInitializers : 1 ;
3233
- unsigned HasMissingVTableEntries : 1 ;
3234
-
3235
3273
friend class IterativeTypeChecker ;
3236
3274
3237
3275
public:
@@ -3324,7 +3362,7 @@ class ClassDecl final : public NominalTypeDecl {
3324
3362
bool hasMissingDesignatedInitializers () const ;
3325
3363
3326
3364
void setHasMissingDesignatedInitializers (bool newValue = true ) {
3327
- HasMissingDesignatedInitializers = newValue;
3365
+ ClassDeclBits. HasMissingDesignatedInitializers = newValue;
3328
3366
}
3329
3367
3330
3368
// / Returns true if the class has missing members that require vtable entries.
@@ -3334,7 +3372,7 @@ class ClassDecl final : public NominalTypeDecl {
3334
3372
bool hasMissingVTableEntries () const ;
3335
3373
3336
3374
void setHasMissingVTableEntries (bool newValue = true ) {
3337
- HasMissingVTableEntries = newValue;
3375
+ ClassDeclBits. HasMissingVTableEntries = newValue;
3338
3376
}
3339
3377
3340
3378
// / Find a method of a class that overrides a given method.
@@ -3523,17 +3561,6 @@ class ProtocolDecl final : public NominalTypeDecl {
3523
3561
// / by this protocol.
3524
3562
const Requirement *RequirementSignature = nullptr ;
3525
3563
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
-
3537
3564
bool requiresClassSlow ();
3538
3565
3539
3566
bool existentialConformsToSelfSlow ();
@@ -3653,9 +3680,9 @@ class ProtocolDecl final : public NominalTypeDecl {
3653
3680
// /
3654
3681
// / Note that this is only valid after type-checking.
3655
3682
Optional<KnownProtocolKind> getKnownProtocolKind () const {
3656
- if (KnownProtocol == 0 )
3683
+ if (ProtocolDeclBits. KnownProtocol == 0 )
3657
3684
return None;
3658
- return static_cast <KnownProtocolKind>(KnownProtocol - 1 );
3685
+ return static_cast <KnownProtocolKind>(ProtocolDeclBits. KnownProtocol - 1 );
3659
3686
}
3660
3687
3661
3688
// / Check whether this protocol is of a specific, known protocol kind.
@@ -3670,7 +3697,7 @@ class ProtocolDecl final : public NominalTypeDecl {
3670
3697
void setKnownProtocolKind (KnownProtocolKind kind) {
3671
3698
assert ((!getKnownProtocolKind () || *getKnownProtocolKind () == kind) &&
3672
3699
" can't reset known protocol kind" );
3673
- KnownProtocol = static_cast <unsigned >(kind) + 1 ;
3700
+ ProtocolDeclBits. KnownProtocol = static_cast <unsigned >(kind) + 1 ;
3674
3701
assert (getKnownProtocolKind () && *getKnownProtocolKind () == kind &&
3675
3702
" not enough bits" );
3676
3703
}
@@ -3692,11 +3719,11 @@ class ProtocolDecl final : public NominalTypeDecl {
3692
3719
// / with requirements that cannot be represented in Swift.
3693
3720
bool hasMissingRequirements () const {
3694
3721
(void )getMembers ();
3695
- return HasMissingRequirements;
3722
+ return ProtocolDeclBits. HasMissingRequirements ;
3696
3723
}
3697
3724
3698
3725
void setHasMissingRequirements (bool newValue) {
3699
- HasMissingRequirements = newValue;
3726
+ ProtocolDeclBits. HasMissingRequirements = newValue;
3700
3727
}
3701
3728
3702
3729
// / Returns the default witness for a requirement, or nullptr if there is
@@ -3733,7 +3760,8 @@ class ProtocolDecl final : public NominalTypeDecl {
3733
3760
ArrayRef<Requirement> getRequirementSignature () const {
3734
3761
assert (isRequirementSignatureComputed () &&
3735
3762
" getting requirement signature before computing it" );
3736
- return llvm::makeArrayRef (RequirementSignature, NumRequirementsInSignature);
3763
+ return llvm::makeArrayRef (RequirementSignature,
3764
+ ProtocolDeclBits.NumRequirementsInSignature );
3737
3765
}
3738
3766
3739
3767
// / Has the requirement signature been computed yet?
@@ -4784,10 +4812,17 @@ class SubscriptDecl : public AbstractStorageDecl, public GenericContext {
4784
4812
4785
4813
// / Encodes imported-as-member status for C functions that get imported
4786
4814
// / as methods.
4787
- struct ImportAsMemberStatus {
4815
+ class ImportAsMemberStatus {
4816
+ friend class AbstractFunctionDecl ;
4817
+
4788
4818
// non-0 denotes import-as-member. 1 denotes no self index. n+2 denotes self
4789
4819
// 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; }
4791
4826
4792
4827
bool isImportAsMember () const { return rawValue != 0 ; }
4793
4828
bool isInstance () const { return rawValue >= 2 ; }
@@ -4864,8 +4899,6 @@ class AbstractFunctionDecl : public ValueDecl, public GenericContext {
4864
4899
// / Location of the 'throws' token.
4865
4900
SourceLoc ThrowsLoc;
4866
4901
4867
- ImportAsMemberStatus IAMStatus;
4868
-
4869
4902
AbstractFunctionDecl (DeclKind Kind, DeclContext *Parent, DeclName Name,
4870
4903
SourceLoc NameLoc, bool Throws, SourceLoc ThrowsLoc,
4871
4904
unsigned NumParameterLists,
@@ -4903,14 +4936,32 @@ class AbstractFunctionDecl : public ValueDecl, public GenericContext {
4903
4936
bool isTransparent () const ;
4904
4937
4905
4938
// 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
+ }
4911
4954
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
+ }
4914
4965
4915
4966
public:
4916
4967
// / Retrieve the location of the 'throws' keyword, if present.
@@ -5461,15 +5512,13 @@ class EnumCaseDecl final : public Decl,
5461
5512
friend TrailingObjects;
5462
5513
SourceLoc CaseLoc;
5463
5514
5464
- // / The number of tail-allocated element pointers.
5465
- unsigned NumElements;
5466
-
5467
5515
EnumCaseDecl (SourceLoc CaseLoc,
5468
5516
ArrayRef<EnumElementDecl *> Elements,
5469
5517
DeclContext *DC)
5470
5518
: Decl(DeclKind::EnumCase, DC),
5471
- CaseLoc (CaseLoc), NumElements(Elements.size())
5519
+ CaseLoc (CaseLoc)
5472
5520
{
5521
+ EnumCaseDeclBits.NumElements = Elements.size ();
5473
5522
std::uninitialized_copy (Elements.begin (), Elements.end (),
5474
5523
getTrailingObjects<EnumElementDecl *>());
5475
5524
}
@@ -5481,7 +5530,8 @@ class EnumCaseDecl final : public Decl,
5481
5530
5482
5531
// / Get the list of elements declared in this case.
5483
5532
ArrayRef<EnumElementDecl *> getElements () const {
5484
- return {getTrailingObjects<EnumElementDecl *>(), NumElements};
5533
+ return {getTrailingObjects<EnumElementDecl *>(),
5534
+ EnumCaseDeclBits.NumElements };
5485
5535
}
5486
5536
5487
5537
SourceLoc getLoc () const {
0 commit comments