Skip to content

Commit dc1653f

Browse files
committed
[Serialization] Factor out a helper for types that wrap other types
...and carry no other information (besides their record code). No functionality change.
1 parent f932eaf commit dc1653f

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

lib/Serialization/Serialization.cpp

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3936,13 +3936,17 @@ class Serializer::TypeSerializer : public TypeVisitor<TypeSerializer> {
39363936
S.addSubstitutionMapRef(alias->getSubstitutionMap()));
39373937
}
39383938

3939+
template <typename Layout>
3940+
void serializeSimpleWrapper(Type wrappedTy) {
3941+
unsigned abbrCode = S.DeclTypeAbbrCodes[Layout::Code];
3942+
Layout::emitRecord(S.Out, S.ScratchRecord, abbrCode,
3943+
S.addTypeRef(wrappedTy));
3944+
}
3945+
39393946
void visitParenType(const ParenType *parenTy) {
39403947
using namespace decls_block;
39413948
assert(parenTy->getParameterFlags().isNone());
3942-
3943-
unsigned abbrCode = S.DeclTypeAbbrCodes[ParenTypeLayout::Code];
3944-
ParenTypeLayout::emitRecord(S.Out, S.ScratchRecord, abbrCode,
3945-
S.addTypeRef(parenTy->getUnderlyingType()));
3949+
serializeSimpleWrapper<ParenTypeLayout>(parenTy->getUnderlyingType());
39463950
}
39473951

39483952
void visitTupleType(const TupleType *tupleTy) {
@@ -4014,10 +4018,8 @@ class Serializer::TypeSerializer : public TypeVisitor<TypeSerializer> {
40144018

40154019
void visitOpenedArchetypeType(const OpenedArchetypeType *archetypeTy) {
40164020
using namespace decls_block;
4017-
unsigned abbrCode = S.DeclTypeAbbrCodes[OpenedArchetypeTypeLayout::Code];
4018-
OpenedArchetypeTypeLayout::emitRecord(
4019-
S.Out, S.ScratchRecord, abbrCode,
4020-
S.addTypeRef(archetypeTy->getOpenedExistentialType()));
4021+
serializeSimpleWrapper<OpenedArchetypeTypeLayout>(
4022+
archetypeTy->getOpenedExistentialType());
40214023
}
40224024

40234025
void
@@ -4113,10 +4115,8 @@ class Serializer::TypeSerializer : public TypeVisitor<TypeSerializer> {
41134115

41144116
void visitSILBlockStorageType(const SILBlockStorageType *storageTy) {
41154117
using namespace decls_block;
4116-
unsigned abbrCode = S.DeclTypeAbbrCodes[SILBlockStorageTypeLayout::Code];
4117-
SILBlockStorageTypeLayout::emitRecord(
4118-
S.Out, S.ScratchRecord, abbrCode,
4119-
S.addTypeRef(storageTy->getCaptureType()));
4118+
serializeSimpleWrapper<SILBlockStorageTypeLayout>(
4119+
storageTy->getCaptureType());
41204120
}
41214121

41224122
void visitSILBoxType(const SILBoxType *boxTy) {
@@ -4182,10 +4182,7 @@ class Serializer::TypeSerializer : public TypeVisitor<TypeSerializer> {
41824182

41834183
void visitArraySliceType(const ArraySliceType *sliceTy) {
41844184
using namespace decls_block;
4185-
Type base = sliceTy->getBaseType();
4186-
unsigned abbrCode = S.DeclTypeAbbrCodes[ArraySliceTypeLayout::Code];
4187-
ArraySliceTypeLayout::emitRecord(S.Out, S.ScratchRecord, abbrCode,
4188-
S.addTypeRef(base));
4185+
serializeSimpleWrapper<ArraySliceTypeLayout>(sliceTy->getBaseType());
41894186
}
41904187

41914188
void visitDictionaryType(const DictionaryType *dictTy) {
@@ -4198,10 +4195,7 @@ class Serializer::TypeSerializer : public TypeVisitor<TypeSerializer> {
41984195

41994196
void visitOptionalType(const OptionalType *optionalTy) {
42004197
using namespace decls_block;
4201-
Type base = optionalTy->getBaseType();
4202-
unsigned abbrCode = S.DeclTypeAbbrCodes[OptionalTypeLayout::Code];
4203-
OptionalTypeLayout::emitRecord(S.Out, S.ScratchRecord, abbrCode,
4204-
S.addTypeRef(base));
4198+
serializeSimpleWrapper<OptionalTypeLayout>(optionalTy->getBaseType());
42054199
}
42064200

42074201
void

0 commit comments

Comments
 (0)