Skip to content

Commit b215d61

Browse files
committed
Serialization: Fix various problems with SIL serialization of variadic generic instructions
Fixes rdar://108004074.
1 parent 760912b commit b215d61

File tree

5 files changed

+35
-3
lines changed

5 files changed

+35
-3
lines changed

lib/Serialization/DeserializeSIL.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,11 +1285,10 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn,
12851285
RawOpCode = (unsigned)SILInstructionKind::HasSymbolInst;
12861286
break;
12871287
case SIL_PACK_ELEMENT_GET:
1288-
SILPackElementGetLayout::readRecord(scratch,
1288+
SILPackElementGetLayout::readRecord(scratch, RawOpCode,
12891289
TyID, TyCategory,
12901290
TyID2, TyCategory2, ValID2,
12911291
ValID3);
1292-
RawOpCode = (unsigned)SILInstructionKind::PackElementGetInst;
12931292
break;
12941293
case SIL_PACK_ELEMENT_SET:
12951294
SILPackElementSetLayout::readRecord(scratch,
@@ -1332,7 +1331,7 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn,
13321331
}
13331332
case SILInstructionKind::AllocPackInst: {
13341333
assert(RecordKind == SIL_ONE_TYPE && "Layout should be OneType.");
1335-
ResultInst = Builder.createAllocStack(
1334+
ResultInst = Builder.createAllocPack(
13361335
Loc, getSILType(MF->getType(TyID), (SILValueCategory)TyCategory, Fn));
13371336
break;
13381337
}

lib/Serialization/SILFormat.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ namespace sil_block {
471471
// The pack_element_get instruction.
472472
using SILPackElementGetLayout = BCRecordLayout<
473473
SIL_PACK_ELEMENT_GET,
474+
SILInstOpCodeField,
474475
TypeIDField, // element type
475476
SILTypeCategoryField, // element type category
476477
TypeIDField, // pack type

lib/Serialization/Serialization.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5549,6 +5549,7 @@ void Serializer::writeAllDeclsAndTypes() {
55495549
registerDeclTypeAbbr<ExistentialMetatypeTypeLayout>();
55505550
registerDeclTypeAbbr<PrimaryArchetypeTypeLayout>();
55515551
registerDeclTypeAbbr<OpenedArchetypeTypeLayout>();
5552+
registerDeclTypeAbbr<ElementArchetypeTypeLayout>();
55525553
registerDeclTypeAbbr<OpaqueArchetypeTypeLayout>();
55535554
registerDeclTypeAbbr<PackArchetypeTypeLayout>();
55545555
registerDeclTypeAbbr<ProtocolCompositionTypeLayout>();
@@ -5568,6 +5569,7 @@ void Serializer::writeAllDeclsAndTypes() {
55685569
registerDeclTypeAbbr<DynamicSelfTypeLayout>();
55695570
registerDeclTypeAbbr<PackExpansionTypeLayout>();
55705571
registerDeclTypeAbbr<PackTypeLayout>();
5572+
registerDeclTypeAbbr<SILPackTypeLayout>();
55715573

55725574
registerDeclTypeAbbr<ErrorFlagLayout>();
55735575
registerDeclTypeAbbr<ErrorTypeLayout>();

lib/Serialization/SerializeSIL.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,6 +1679,7 @@ void SILSerializer::writeSILInstruction(const SILInstruction &SI) {
16791679
auto indexRef = addValueRef(PEGI->getIndex());
16801680
SILPackElementGetLayout::emitRecord(Out, ScratchRecord,
16811681
SILAbbrCodes[SILPackElementGetLayout::Code],
1682+
(unsigned)SI.getKind(),
16821683
elementTypeRef,
16831684
(unsigned) elementType.getCategory(),
16841685
packTypeRef,
@@ -1720,6 +1721,7 @@ void SILSerializer::writeSILInstruction(const SILInstruction &SI) {
17201721
auto indexRef = addValueRef(TPEAI->getIndex());
17211722
SILPackElementGetLayout::emitRecord(Out, ScratchRecord,
17221723
SILAbbrCodes[SILPackElementGetLayout::Code],
1724+
(unsigned)SI.getKind(),
17231725
elementTypeRef,
17241726
(unsigned) elementType.getCategory(),
17251727
tupleTypeRef,
@@ -3056,6 +3058,8 @@ void SILSerializer::writeSILBlock(const SILModule *SILMod) {
30563058
registerSILAbbr<SILInstLinearFunctionExtractLayout>();
30573059
registerSILAbbr<SILInstIncrementProfilerCounterLayout>();
30583060
registerSILAbbr<SILInstHasSymbolLayout>();
3061+
registerSILAbbr<SILPackElementGetLayout>();
3062+
registerSILAbbr<SILPackElementSetLayout>();
30593063

30603064
registerSILAbbr<VTableLayout>();
30613065
registerSILAbbr<VTableEntryLayout>();
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module %s -emit-module-path %t/pack_expansion_type.swiftmodule -DLIB -enable-experimental-feature VariadicGenerics
3+
// RUN: %target-swift-frontend -emit-sil %s -I %t -DAPP -module-name main -enable-experimental-feature VariadicGenerics
4+
5+
// Because of -enable-experimental-feature VariadicGenerics
6+
// REQUIRES: asserts
7+
8+
#if LIB
9+
10+
public func callee<each T>(_: repeat each T) {}
11+
12+
@_transparent public func caller<each T>(_ t: repeat each T) {
13+
callee(repeat [each t])
14+
}
15+
16+
public func calleer() {
17+
caller(1, "hi", false)
18+
}
19+
20+
#elseif APP
21+
22+
import pack_expansion_type
23+
24+
caller(1, "hi", false)
25+
26+
#endif

0 commit comments

Comments
 (0)