@@ -4565,128 +4565,128 @@ void irgen::emitStructMetadata(IRGenModule &IGM, StructDecl *structDecl) {
4565
4565
4566
4566
namespace {
4567
4567
4568
- template <class Impl >
4569
- class EnumMetadataBuilderBase : public EnumMetadataVisitor <Impl> {
4570
- using super = EnumMetadataVisitor<Impl>;
4568
+ template <class Impl >
4569
+ class EnumMetadataBuilderBase : public EnumMetadataVisitor <Impl> {
4570
+ using super = EnumMetadataVisitor<Impl>;
4571
4571
4572
- protected:
4573
- ConstantStructBuilder &B;
4574
- using super::IGM;
4575
- using super::Target;
4572
+ protected:
4573
+ ConstantStructBuilder &B;
4574
+ using super::IGM;
4575
+ using super::Target;
4576
4576
4577
- public:
4578
- EnumMetadataBuilderBase (IRGenModule &IGM, EnumDecl *theEnum,
4579
- ConstantStructBuilder &B)
4580
- : super(IGM, theEnum), B(B) {
4581
- }
4582
-
4583
- void addMetadataFlags () {
4584
- auto kind = Target->classifyAsOptionalType ()
4585
- ? MetadataKind::Optional
4586
- : MetadataKind::Enum;
4587
- B.addInt (IGM.MetadataKindTy , unsigned (kind));
4588
- }
4577
+ public:
4578
+ EnumMetadataBuilderBase (IRGenModule &IGM, EnumDecl *theEnum,
4579
+ ConstantStructBuilder &B)
4580
+ : super(IGM, theEnum), B(B) {
4581
+ }
4589
4582
4590
- void addNominalTypeDescriptor () {
4591
- auto descriptor = EnumNominalTypeDescriptorBuilder (IGM, Target).emit ();
4592
- B.add (descriptor);
4593
- }
4583
+ void addMetadataFlags () {
4584
+ auto kind = Target->classifyAsOptionalType ()
4585
+ ? MetadataKind::Optional
4586
+ : MetadataKind::Enum;
4587
+ B.addInt (IGM.MetadataKindTy , unsigned (kind));
4588
+ }
4594
4589
4595
- void addGenericArgument (CanType type) {
4596
- B.addNullPointer (IGM.TypeMetadataPtrTy );
4597
- }
4598
-
4599
- void addGenericWitnessTable (CanType type, ProtocolConformanceRef conf) {
4600
- B.addNullPointer (IGM.WitnessTablePtrTy );
4601
- }
4602
- };
4603
-
4604
- class EnumMetadataBuilder
4605
- : public EnumMetadataBuilderBase<EnumMetadataBuilder> {
4606
- bool HasUnfilledPayloadSize = false ;
4607
-
4608
- public:
4609
- EnumMetadataBuilder (IRGenModule &IGM, EnumDecl *theEnum,
4610
- ConstantStructBuilder &B)
4611
- : EnumMetadataBuilderBase(IGM, theEnum, B) {}
4612
-
4613
- void addValueWitnessTable () {
4614
- auto type = Target->getDeclaredType ()->getCanonicalType ();
4615
- B.add (emitValueWitnessTable (IGM, type));
4616
- }
4617
-
4618
- void addPayloadSize () {
4619
- auto enumTy = Target->getDeclaredTypeInContext ()->getCanonicalType ();
4620
- auto &enumTI = IGM.getTypeInfoForUnlowered (enumTy);
4621
- if (!enumTI.isFixedSize (ResilienceExpansion::Maximal)) {
4622
- B.addInt (IGM.IntPtrTy , 0 );
4623
- HasUnfilledPayloadSize = true ;
4624
- return ;
4590
+ void addNominalTypeDescriptor () {
4591
+ auto descriptor = EnumNominalTypeDescriptorBuilder (IGM, Target).emit ();
4592
+ B.add (descriptor);
4625
4593
}
4626
4594
4627
- assert (!enumTI.isFixedSize (ResilienceExpansion::Minimal) &&
4628
- " non-generic, non-resilient enums don't need payload size in metadata" );
4629
- auto &strategy = getEnumImplStrategy (IGM, enumTy);
4630
- B.addInt (IGM.IntPtrTy , strategy.getPayloadSizeForMetadata ());
4631
- }
4595
+ void addGenericArgument (CanType type) {
4596
+ B.addNullPointer (IGM.TypeMetadataPtrTy );
4597
+ }
4632
4598
4633
- bool canBeConstant () {
4634
- return !HasUnfilledPayloadSize;
4635
- }
4599
+ void addGenericWitnessTable (CanType type, ProtocolConformanceRef conf) {
4600
+ B.addNullPointer (IGM.WitnessTablePtrTy );
4601
+ }
4602
+ };
4636
4603
4637
- void createMetadataAccessFunction () {
4638
- createInPlaceValueTypeMetadataAccessFunction (IGM, Target);
4639
- }
4640
- };
4641
-
4642
- class GenericEnumMetadataBuilder
4643
- : public GenericMetadataBuilderBase<GenericEnumMetadataBuilder,
4644
- EnumMetadataBuilderBase<GenericEnumMetadataBuilder>>
4645
- {
4646
- public:
4647
- GenericEnumMetadataBuilder (IRGenModule &IGM, EnumDecl *theEnum,
4648
- ConstantStructBuilder &B)
4649
- : GenericMetadataBuilderBase(IGM, theEnum, B) {}
4650
-
4651
- llvm::Value *emitAllocateMetadata (IRGenFunction &IGF,
4652
- llvm::Value *metadataPattern,
4653
- llvm::Value *arguments) {
4654
- return IGF.Builder .CreateCall (IGM.getAllocateGenericValueMetadataFn (),
4655
- {metadataPattern, arguments});
4656
- }
4604
+ class EnumMetadataBuilder
4605
+ : public EnumMetadataBuilderBase<EnumMetadataBuilder> {
4606
+ bool HasUnfilledPayloadSize = false ;
4607
+
4608
+ public:
4609
+ EnumMetadataBuilder (IRGenModule &IGM, EnumDecl *theEnum,
4610
+ ConstantStructBuilder &B)
4611
+ : EnumMetadataBuilderBase(IGM, theEnum, B) {}
4612
+
4613
+ void addValueWitnessTable () {
4614
+ auto type = Target->getDeclaredType ()->getCanonicalType ();
4615
+ B.add (emitValueWitnessTable (IGM, type));
4616
+ }
4617
+
4618
+ void addPayloadSize () {
4619
+ auto enumTy = Target->getDeclaredTypeInContext ()->getCanonicalType ();
4620
+ auto &enumTI = IGM.getTypeInfoForUnlowered (enumTy);
4621
+ if (!enumTI.isFixedSize (ResilienceExpansion::Maximal)) {
4622
+ B.addInt (IGM.IntPtrTy , 0 );
4623
+ HasUnfilledPayloadSize = true ;
4624
+ return ;
4625
+ }
4626
+
4627
+ assert (!enumTI.isFixedSize (ResilienceExpansion::Minimal) &&
4628
+ " non-generic, non-resilient enums don't need payload size in metadata" );
4629
+ auto &strategy = getEnumImplStrategy (IGM, enumTy);
4630
+ B.addInt (IGM.IntPtrTy , strategy.getPayloadSizeForMetadata ());
4631
+ }
4632
+
4633
+ bool canBeConstant () {
4634
+ return !HasUnfilledPayloadSize;
4635
+ }
4636
+
4637
+ void createMetadataAccessFunction () {
4638
+ createInPlaceValueTypeMetadataAccessFunction (IGM, Target);
4639
+ }
4640
+ };
4641
+
4642
+ class GenericEnumMetadataBuilder
4643
+ : public GenericMetadataBuilderBase<GenericEnumMetadataBuilder,
4644
+ EnumMetadataBuilderBase<GenericEnumMetadataBuilder>>
4645
+ {
4646
+ public:
4647
+ GenericEnumMetadataBuilder (IRGenModule &IGM, EnumDecl *theEnum,
4648
+ ConstantStructBuilder &B)
4649
+ : GenericMetadataBuilderBase(IGM, theEnum, B) {}
4650
+
4651
+ llvm::Value *emitAllocateMetadata (IRGenFunction &IGF,
4652
+ llvm::Value *metadataPattern,
4653
+ llvm::Value *arguments) {
4654
+ return IGF.Builder .CreateCall (IGM.getAllocateGenericValueMetadataFn (),
4655
+ {metadataPattern, arguments});
4656
+ }
4657
+
4658
+ void addValueWitnessTable () {
4659
+ B.add (getValueWitnessTableForGenericValueType (IGM, Target,
4660
+ HasDependentVWT));
4661
+ }
4662
+
4663
+ void addDependentValueWitnessTablePattern () {
4664
+ emitDependentValueWitnessTablePattern (IGM, B,
4665
+ Target->getDeclaredType ()->getCanonicalType ());
4666
+ }
4667
+
4668
+ void addPayloadSize () {
4669
+ // In all cases where a payload size is demanded in the metadata, it's
4670
+ // runtime-dependent, so fill in a zero here.
4671
+ auto enumTy = Target->getDeclaredTypeInContext ()->getCanonicalType ();
4672
+ auto &enumTI = IGM.getTypeInfoForUnlowered (enumTy);
4673
+ (void ) enumTI;
4674
+ assert (!enumTI.isFixedSize (ResilienceExpansion::Minimal) &&
4675
+ " non-generic, non-resilient enums don't need payload size in metadata" );
4676
+ B.addInt (IGM.IntPtrTy , 0 );
4677
+ }
4678
+
4679
+ void emitInitializeMetadata (IRGenFunction &IGF,
4680
+ llvm::Value *metadata,
4681
+ llvm::Value *vwtable) {
4682
+ // Nominal types are always preserved through SIL lowering.
4683
+ auto enumTy = Target->getDeclaredTypeInContext ()->getCanonicalType ();
4684
+ IGM.getTypeInfoForUnlowered (enumTy)
4685
+ .initializeMetadata (IGF, metadata, vwtable,
4686
+ IGF.IGM .getLoweredType (enumTy));
4687
+ }
4688
+ };
4657
4689
4658
- void addValueWitnessTable () {
4659
- B.add (getValueWitnessTableForGenericValueType (IGM, Target,
4660
- HasDependentVWT));
4661
- }
4662
-
4663
- void addDependentValueWitnessTablePattern () {
4664
- emitDependentValueWitnessTablePattern (IGM, B,
4665
- Target->getDeclaredType ()->getCanonicalType ());
4666
- }
4667
-
4668
- void addPayloadSize () {
4669
- // In all cases where a payload size is demanded in the metadata, it's
4670
- // runtime-dependent, so fill in a zero here.
4671
- auto enumTy = Target->getDeclaredTypeInContext ()->getCanonicalType ();
4672
- auto &enumTI = IGM.getTypeInfoForUnlowered (enumTy);
4673
- (void ) enumTI;
4674
- assert (!enumTI.isFixedSize (ResilienceExpansion::Minimal) &&
4675
- " non-generic, non-resilient enums don't need payload size in metadata" );
4676
- B.addInt (IGM.IntPtrTy , 0 );
4677
- }
4678
-
4679
- void emitInitializeMetadata (IRGenFunction &IGF,
4680
- llvm::Value *metadata,
4681
- llvm::Value *vwtable) {
4682
- // Nominal types are always preserved through SIL lowering.
4683
- auto enumTy = Target->getDeclaredTypeInContext ()->getCanonicalType ();
4684
- IGM.getTypeInfoForUnlowered (enumTy)
4685
- .initializeMetadata (IGF, metadata, vwtable,
4686
- IGF.IGM .getLoweredType (enumTy));
4687
- }
4688
- };
4689
-
4690
4690
} // end anonymous namespace
4691
4691
4692
4692
void irgen::emitEnumMetadata (IRGenModule &IGM, EnumDecl *theEnum) {
0 commit comments