Skip to content

Commit 1e00c31

Browse files
committed
Serialization: Support PackType and PackExpansionType
1 parent 987552d commit 1e00c31

File tree

4 files changed

+82
-6
lines changed

4 files changed

+82
-6
lines changed

lib/Serialization/DeclTypeRecordNodes.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ TYPE(SIL_MOVE_ONLY)
113113
TYPE(SIL_BOX)
114114
TYPE(NAME_ALIAS)
115115

116+
TYPE(PACK_EXPANSION)
117+
TYPE(PACK)
118+
TRAILING_INFO(PACK_TYPE_ELT)
119+
116120
TYPE(ERROR)
117121

118122
FIRST_DECL(TYPE_ALIAS, 40)

lib/Serialization/Deserialization.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6431,6 +6431,51 @@ Expected<Type> DESERIALIZE_TYPE(UNBOUND_GENERIC_TYPE)(
64316431
return UnboundGenericType::get(genericDecl, parentTy, MF.getContext());
64326432
}
64336433

6434+
Expected<Type> DESERIALIZE_TYPE(PACK_EXPANSION_TYPE)(
6435+
ModuleFile &MF, SmallVectorImpl<uint64_t> &scratch, StringRef blobData) {
6436+
TypeID patternID;
6437+
TypeID countID;
6438+
decls_block::PackExpansionTypeLayout::readRecord(scratch, patternID, countID);
6439+
6440+
auto patternTy = MF.getTypeChecked(patternID);
6441+
if (!patternTy)
6442+
return patternTy.takeError();
6443+
auto countTy = MF.getTypeChecked(countID);
6444+
if (!countTy)
6445+
return countTy.takeError();
6446+
6447+
return PackExpansionType::get(patternTy.get(), countTy.get());
6448+
}
6449+
6450+
Expected<Type> DESERIALIZE_TYPE(PACK_TYPE)(
6451+
ModuleFile &MF, SmallVectorImpl<uint64_t> &scratch, StringRef blobData) {
6452+
// The pack record itself is empty. Read all trailing elements.
6453+
SmallVector<Type, 8> elements;
6454+
while (true) {
6455+
llvm::BitstreamEntry entry =
6456+
MF.fatalIfUnexpected(MF.DeclTypeCursor.advance(AF_DontPopBlockAtEnd));
6457+
if (entry.Kind != llvm::BitstreamEntry::Record)
6458+
break;
6459+
6460+
scratch.clear();
6461+
unsigned recordID = MF.fatalIfUnexpected(
6462+
MF.DeclTypeCursor.readRecord(entry.ID, scratch, &blobData));
6463+
if (recordID != decls_block::PACK_TYPE_ELT)
6464+
break;
6465+
6466+
TypeID typeID;
6467+
decls_block::PackTypeEltLayout::readRecord(scratch, typeID);
6468+
6469+
auto elementTy = MF.getTypeChecked(typeID);
6470+
if (!elementTy)
6471+
return elementTy.takeError();
6472+
6473+
elements.push_back(elementTy.get());
6474+
}
6475+
6476+
return PackType::get(MF.getContext(), elements);
6477+
}
6478+
64346479
Expected<Type> DESERIALIZE_TYPE(ERROR_TYPE)(ModuleFile &MF,
64356480
SmallVectorImpl<uint64_t> &scratch,
64366481
StringRef blobData) {

lib/Serialization/ModuleFormat.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,21 @@ namespace decls_block {
12721272
TypeIDField // parent
12731273
);
12741274

1275+
TYPE_LAYOUT(PackExpansionTypeLayout,
1276+
PACK_EXPANSION_TYPE,
1277+
TypeIDField, // pattern type
1278+
TypeIDField // count type
1279+
);
1280+
1281+
TYPE_LAYOUT(PackTypeLayout,
1282+
PACK_TYPE
1283+
);
1284+
1285+
using PackTypeEltLayout = BCRecordLayout<
1286+
PACK_TYPE_ELT,
1287+
TypeIDField // type
1288+
>;
1289+
12751290
using TypeAliasLayout = BCRecordLayout<
12761291
TYPE_ALIAS_DECL,
12771292
IdentifierIDField, // name

lib/Serialization/Serialization.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4611,16 +4611,25 @@ class Serializer::TypeSerializer : public TypeVisitor<TypeSerializer> {
46114611
S.addTypeRef(wrappedTy));
46124612
}
46134613

4614-
void visitPackType(const PackType *pack) {
4614+
void visitPackExpansionType(const PackExpansionType *expansionTy) {
46154615
using namespace decls_block;
4616-
// serializeSimpleWrapper<ParenTypeLayout>(parenTy->getUnderlyingType());
4617-
llvm_unreachable("Unimplemented!");
4616+
unsigned abbrCode = S.DeclTypeAbbrCodes[PackExpansionTypeLayout::Code];
4617+
PackExpansionTypeLayout::emitRecord(S.Out, S.ScratchRecord, abbrCode,
4618+
S.addTypeRef(expansionTy->getPatternType()),
4619+
S.addTypeRef(expansionTy->getCountType()));
46184620
}
46194621

4620-
void visitPackExpansionType(const PackExpansionType *pack) {
4622+
void visitPackType(const PackType *packTy) {
46214623
using namespace decls_block;
4622-
// serializeSimpleWrapper<ParenTypeLayout>(parenTy->getUnderlyingType());
4623-
llvm_unreachable("Unimplemented!");
4624+
unsigned abbrCode = S.DeclTypeAbbrCodes[PackTypeLayout::Code];
4625+
TupleTypeLayout::emitRecord(S.Out, S.ScratchRecord, abbrCode);
4626+
4627+
abbrCode = S.DeclTypeAbbrCodes[PackTypeEltLayout::Code];
4628+
for (auto elt : packTy->getElementTypes()) {
4629+
PackTypeEltLayout::emitRecord(
4630+
S.Out, S.ScratchRecord, abbrCode,
4631+
S.addTypeRef(elt));
4632+
}
46244633
}
46254634

46264635
void visitParenType(const ParenType *parenTy) {
@@ -5161,6 +5170,9 @@ void Serializer::writeAllDeclsAndTypes() {
51615170
registerDeclTypeAbbr<UnboundGenericTypeLayout>();
51625171
registerDeclTypeAbbr<OptionalTypeLayout>();
51635172
registerDeclTypeAbbr<DynamicSelfTypeLayout>();
5173+
registerDeclTypeAbbr<PackExpansionTypeLayout>();
5174+
registerDeclTypeAbbr<PackTypeLayout>();
5175+
registerDeclTypeAbbr<PackTypeEltLayout>();
51645176

51655177
registerDeclTypeAbbr<ErrorFlagLayout>();
51665178
registerDeclTypeAbbr<ErrorTypeLayout>();

0 commit comments

Comments
 (0)