@@ -4567,69 +4567,57 @@ class swift::TypeDeserializer {
4567
4567
return deserializeAnyFunctionType (scratch, blobData, /* isGeneric*/ true );
4568
4568
}
4569
4569
4570
- Expected<Type >
4571
- deserializeExistentialMetatypeType (ArrayRef<uint64_t > scratch,
4572
- StringRef blobData) {
4570
+ template < typename Layout, typename ASTType, bool CanBeThin >
4571
+ Expected<Type> deserializeAnyMetatypeType (ArrayRef<uint64_t > scratch,
4572
+ StringRef blobData) {
4573
4573
TypeID instanceID;
4574
4574
uint8_t repr;
4575
- decls_block::ExistentialMetatypeTypeLayout:: readRecord (scratch,
4576
- instanceID, repr);
4575
+ Layout:: readRecord (scratch, instanceID, repr);
4576
+
4577
4577
auto instanceType = MF.getTypeChecked (instanceID);
4578
4578
if (!instanceType)
4579
4579
return instanceType.takeError ();
4580
4580
4581
4581
switch (repr) {
4582
4582
case serialization::MetatypeRepresentation::MR_None:
4583
- return ExistentialMetatypeType ::get (instanceType.get ());
4583
+ return ASTType ::get (instanceType.get ());
4584
4584
4585
4585
case serialization::MetatypeRepresentation::MR_Thin:
4586
- MF.error ();
4587
- llvm_unreachable (" an error is fatal" );
4586
+ if (!CanBeThin) {
4587
+ MF.error ();
4588
+ llvm_unreachable (" an error is fatal" );
4589
+ }
4590
+ return ASTType::get (instanceType.get (),
4591
+ MetatypeRepresentation::Thin);
4588
4592
4589
4593
case serialization::MetatypeRepresentation::MR_Thick:
4590
- return ExistentialMetatypeType ::get (instanceType.get (),
4591
- MetatypeRepresentation::Thick);
4594
+ return ASTType ::get (instanceType.get (),
4595
+ MetatypeRepresentation::Thick);
4592
4596
4593
4597
case serialization::MetatypeRepresentation::MR_ObjC:
4594
- return ExistentialMetatypeType ::get (instanceType.get (),
4595
- MetatypeRepresentation::ObjC);
4598
+ return ASTType ::get (instanceType.get (),
4599
+ MetatypeRepresentation::ObjC);
4596
4600
4597
4601
default :
4598
4602
MF.error ();
4599
4603
llvm_unreachable (" an error is fatal" );
4600
4604
}
4601
4605
}
4602
4606
4607
+ Expected<Type>
4608
+ deserializeExistentialMetatypeType (ArrayRef<uint64_t > scratch,
4609
+ StringRef blobData) {
4610
+ return
4611
+ deserializeAnyMetatypeType<decls_block::ExistentialMetatypeTypeLayout,
4612
+ ExistentialMetatypeType, /* CanBeThin*/ false >(
4613
+ scratch, blobData);
4614
+ }
4615
+
4603
4616
Expected<Type> deserializeMetatypeType (ArrayRef<uint64_t > scratch,
4604
4617
StringRef blobData) {
4605
- TypeID instanceID;
4606
- uint8_t repr;
4607
- decls_block::MetatypeTypeLayout::readRecord (scratch, instanceID, repr);
4608
-
4609
- auto instanceType = MF.getTypeChecked (instanceID);
4610
- if (!instanceType)
4611
- return instanceType.takeError ();
4612
-
4613
- switch (repr) {
4614
- case serialization::MetatypeRepresentation::MR_None:
4615
- return MetatypeType::get (instanceType.get ());
4616
-
4617
- case serialization::MetatypeRepresentation::MR_Thin:
4618
- return MetatypeType::get (instanceType.get (),
4619
- MetatypeRepresentation::Thin);
4620
-
4621
- case serialization::MetatypeRepresentation::MR_Thick:
4622
- return MetatypeType::get (instanceType.get (),
4623
- MetatypeRepresentation::Thick);
4624
-
4625
- case serialization::MetatypeRepresentation::MR_ObjC:
4626
- return MetatypeType::get (instanceType.get (),
4627
- MetatypeRepresentation::ObjC);
4628
-
4629
- default :
4630
- MF.error ();
4631
- llvm_unreachable (" an error is fatal" );
4632
- }
4618
+ return deserializeAnyMetatypeType<decls_block::MetatypeTypeLayout,
4619
+ MetatypeType, /* CanBeThin*/ true >(
4620
+ scratch, blobData);
4633
4621
}
4634
4622
4635
4623
Expected<Type> deserializeDynamicSelfType (ArrayRef<uint64_t > scratch,
0 commit comments