Skip to content

Commit f932eaf

Browse files
committed
[Serialization] Simplify metatype and function type serialization
No functionality change.
1 parent f89358f commit f932eaf

File tree

1 file changed

+41
-35
lines changed

1 file changed

+41
-35
lines changed

lib/Serialization/Serialization.cpp

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3968,27 +3968,25 @@ class Serializer::TypeSerializer : public TypeVisitor<TypeSerializer> {
39683968
S.addTypeRef(nominalTy->getParent()));
39693969
}
39703970

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];
39743974

39753975
// Map the metatype representation.
39763976
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));
39813980
}
39823981

3983-
void visitMetatypeType(const MetatypeType *metatypeTy) {
3982+
void visitExistentialMetatypeType(const ExistentialMetatypeType *metatypeTy) {
39843983
using namespace decls_block;
3985-
unsigned abbrCode = S.DeclTypeAbbrCodes[MetatypeTypeLayout::Code];
3984+
visitMetatypeImpl<ExistentialMetatypeTypeLayout>(metatypeTy);
3985+
}
39863986

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);
39923990
}
39933991

39943992
void visitDynamicSelfType(const DynamicSelfType *dynamicSelfTy) {
@@ -4070,28 +4068,8 @@ class Serializer::TypeSerializer : public TypeVisitor<TypeSerializer> {
40704068
S.addDeclRef(dependent->getAssocType()));
40714069
}
40724070

4073-
void visitAnyFunctionType(const AnyFunctionType *fnTy) {
4071+
void serializeFunctionTypeParams(const AnyFunctionType *fnTy) {
40744072
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-
40954073
unsigned abbrCode = S.DeclTypeAbbrCodes[FunctionParamLayout::Code];
40964074
for (auto &param : fnTy->getParams()) {
40974075
auto paramFlags = param.getParameterFlags();
@@ -4105,6 +4083,34 @@ class Serializer::TypeSerializer : public TypeVisitor<TypeSerializer> {
41054083
}
41064084
}
41074085

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+
41084114
void visitSILBlockStorageType(const SILBlockStorageType *storageTy) {
41094115
using namespace decls_block;
41104116
unsigned abbrCode = S.DeclTypeAbbrCodes[SILBlockStorageTypeLayout::Code];

0 commit comments

Comments
 (0)