@@ -3968,27 +3968,25 @@ class Serializer::TypeSerializer : public TypeVisitor<TypeSerializer> {
3968
3968
S.addTypeRef (nominalTy->getParent ()));
3969
3969
}
3970
3970
3971
- void visitExistentialMetatypeType ( const ExistentialMetatypeType *metatypeTy) {
3972
- using namespace decls_block ;
3973
- unsigned abbrCode = S.DeclTypeAbbrCodes [ExistentialMetatypeTypeLayout ::Code];
3971
+ template < typename Layout>
3972
+ void visitMetatypeImpl ( const AnyMetatypeType *metatypeTy) {
3973
+ unsigned abbrCode = S.DeclTypeAbbrCodes [Layout ::Code];
3974
3974
3975
3975
// Map the metatype representation.
3976
3976
auto repr = getRawStableMetatypeRepresentation (metatypeTy);
3977
- ExistentialMetatypeTypeLayout::emitRecord (
3978
- S.Out , S.ScratchRecord , abbrCode,
3979
- S.addTypeRef (metatypeTy->getInstanceType ()),
3980
- static_cast <uint8_t >(repr));
3977
+ Layout::emitRecord (S.Out , S.ScratchRecord , abbrCode,
3978
+ S.addTypeRef (metatypeTy->getInstanceType ()),
3979
+ static_cast <uint8_t >(repr));
3981
3980
}
3982
3981
3983
- void visitMetatypeType (const MetatypeType *metatypeTy) {
3982
+ void visitExistentialMetatypeType (const ExistentialMetatypeType *metatypeTy) {
3984
3983
using namespace decls_block ;
3985
- unsigned abbrCode = S.DeclTypeAbbrCodes [MetatypeTypeLayout::Code];
3984
+ visitMetatypeImpl<ExistentialMetatypeTypeLayout>(metatypeTy);
3985
+ }
3986
3986
3987
- // Map the metatype representation.
3988
- auto repr = getRawStableMetatypeRepresentation (metatypeTy);
3989
- MetatypeTypeLayout::emitRecord (S.Out , S.ScratchRecord , abbrCode,
3990
- S.addTypeRef (metatypeTy->getInstanceType ()),
3991
- static_cast <uint8_t >(repr));
3987
+ void visitMetatypeType (const MetatypeType *metatypeTy) {
3988
+ using namespace decls_block ;
3989
+ visitMetatypeImpl<MetatypeTypeLayout>(metatypeTy);
3992
3990
}
3993
3991
3994
3992
void visitDynamicSelfType (const DynamicSelfType *dynamicSelfTy) {
@@ -4070,28 +4068,8 @@ class Serializer::TypeSerializer : public TypeVisitor<TypeSerializer> {
4070
4068
S.addDeclRef (dependent->getAssocType ()));
4071
4069
}
4072
4070
4073
- void visitAnyFunctionType (const AnyFunctionType *fnTy) {
4071
+ void serializeFunctionTypeParams (const AnyFunctionType *fnTy) {
4074
4072
using namespace decls_block ;
4075
-
4076
- if (isa<FunctionType>(fnTy)) {
4077
- unsigned abbrCode = S.DeclTypeAbbrCodes [FunctionTypeLayout::Code];
4078
- FunctionTypeLayout::emitRecord (S.Out , S.ScratchRecord , abbrCode,
4079
- S.addTypeRef (fnTy->getResult ()),
4080
- getRawStableFunctionTypeRepresentation (fnTy->getRepresentation ()),
4081
- fnTy->isNoEscape (),
4082
- fnTy->throws ());
4083
- } else {
4084
- assert (!fnTy->isNoEscape ());
4085
-
4086
- auto *genericSig = cast<GenericFunctionType>(fnTy)->getGenericSignature ();
4087
- unsigned abbrCode = S.DeclTypeAbbrCodes [GenericFunctionTypeLayout::Code];
4088
- GenericFunctionTypeLayout::emitRecord (S.Out , S.ScratchRecord , abbrCode,
4089
- S.addTypeRef (fnTy->getResult ()),
4090
- getRawStableFunctionTypeRepresentation (fnTy->getRepresentation ()),
4091
- fnTy->throws (),
4092
- S.addGenericSignatureRef (genericSig));
4093
- }
4094
-
4095
4073
unsigned abbrCode = S.DeclTypeAbbrCodes [FunctionParamLayout::Code];
4096
4074
for (auto ¶m : fnTy->getParams ()) {
4097
4075
auto paramFlags = param.getParameterFlags ();
@@ -4105,6 +4083,34 @@ class Serializer::TypeSerializer : public TypeVisitor<TypeSerializer> {
4105
4083
}
4106
4084
}
4107
4085
4086
+ void visitFunctionType (const FunctionType *fnTy) {
4087
+ using namespace decls_block ;
4088
+
4089
+ unsigned abbrCode = S.DeclTypeAbbrCodes [FunctionTypeLayout::Code];
4090
+ FunctionTypeLayout::emitRecord (S.Out , S.ScratchRecord , abbrCode,
4091
+ S.addTypeRef (fnTy->getResult ()),
4092
+ getRawStableFunctionTypeRepresentation (fnTy->getRepresentation ()),
4093
+ fnTy->isNoEscape (),
4094
+ fnTy->throws ());
4095
+
4096
+ serializeFunctionTypeParams (fnTy);
4097
+ }
4098
+
4099
+ void visitGenericFunctionType (const GenericFunctionType *fnTy) {
4100
+ using namespace decls_block ;
4101
+ assert (!fnTy->isNoEscape ());
4102
+
4103
+ auto *genericSig = fnTy->getGenericSignature ();
4104
+ unsigned abbrCode = S.DeclTypeAbbrCodes [GenericFunctionTypeLayout::Code];
4105
+ GenericFunctionTypeLayout::emitRecord (S.Out , S.ScratchRecord , abbrCode,
4106
+ S.addTypeRef (fnTy->getResult ()),
4107
+ getRawStableFunctionTypeRepresentation (fnTy->getRepresentation ()),
4108
+ fnTy->throws (),
4109
+ S.addGenericSignatureRef (genericSig));
4110
+
4111
+ serializeFunctionTypeParams (fnTy);
4112
+ }
4113
+
4108
4114
void visitSILBlockStorageType (const SILBlockStorageType *storageTy) {
4109
4115
using namespace decls_block ;
4110
4116
unsigned abbrCode = S.DeclTypeAbbrCodes [SILBlockStorageTypeLayout::Code];
0 commit comments