Skip to content

Commit f0f70e4

Browse files
committed
SIL: Fix serialization of open_pack_element
1 parent 4540aea commit f0f70e4

File tree

5 files changed

+49
-12
lines changed

5 files changed

+49
-12
lines changed

lib/Serialization/DeserializeSIL.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1284,6 +1284,11 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn,
12841284
SILInstHasSymbolLayout::readRecord(scratch, ValID, ListOfValues);
12851285
RawOpCode = (unsigned)SILInstructionKind::HasSymbolInst;
12861286
break;
1287+
case SIL_OPEN_PACK_ELEMENT:
1288+
SILOpenPackElementLayout::readRecord(scratch, Attr,
1289+
TyID, TyCategory, ValID);
1290+
RawOpCode = (unsigned)SILInstructionKind::OpenPackElementInst;
1291+
break;
12871292
case SIL_PACK_ELEMENT_GET:
12881293
SILPackElementGetLayout::readRecord(scratch, RawOpCode,
12891294
TyID, TyCategory,
@@ -1424,7 +1429,7 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn,
14241429
break;
14251430
}
14261431
case SILInstructionKind::OpenPackElementInst: {
1427-
assert(RecordKind == SIL_ONE_OPERAND && "Layout should be OneOperand");
1432+
assert(RecordKind == SIL_OPEN_PACK_ELEMENT && "Layout should be OpenPackElement");
14281433
auto index = getLocalValue(ValID,
14291434
getSILType(MF->getType(TyID), (SILValueCategory) TyCategory, Fn));
14301435
auto env = MF->getGenericEnvironmentChecked(Attr);

lib/Serialization/SILFormat.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ namespace sil_block {
159159
SIL_INST_INCREMENT_PROFILER_COUNTER,
160160
SIL_MOVEONLY_DEINIT,
161161
SIL_INST_HAS_SYMBOL,
162+
SIL_OPEN_PACK_ELEMENT,
162163
SIL_PACK_ELEMENT_GET,
163164
SIL_PACK_ELEMENT_SET,
164165
};
@@ -468,6 +469,15 @@ namespace sil_block {
468469
ValueIDField
469470
>;
470471

472+
// The pack_element_get instruction.
473+
using SILOpenPackElementLayout = BCRecordLayout<
474+
SIL_OPEN_PACK_ELEMENT,
475+
GenericEnvironmentIDField,
476+
TypeIDField,
477+
SILTypeCategoryField,
478+
ValueIDField
479+
>;
480+
471481
// The pack_element_get instruction.
472482
using SILPackElementGetLayout = BCRecordLayout<
473483
SIL_PACK_ELEMENT_GET,

lib/Serialization/Serialization.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,9 @@ void Serializer::writeBlockInfoBlock() {
926926
BLOCK_RECORD(sil_block, SIL_ONE_OPERAND_EXTRA_ATTR);
927927
BLOCK_RECORD(sil_block, SIL_ONE_TYPE_ONE_OPERAND_EXTRA_ATTR);
928928
BLOCK_RECORD(sil_block, SIL_TWO_OPERANDS_EXTRA_ATTR);
929+
BLOCK_RECORD(sil_block, SIL_OPEN_PACK_ELEMENT);
930+
BLOCK_RECORD(sil_block, SIL_PACK_ELEMENT_GET);
931+
BLOCK_RECORD(sil_block, SIL_PACK_ELEMENT_SET);
929932

930933
BLOCK(SIL_INDEX_BLOCK);
931934
BLOCK_RECORD(sil_index_block, SIL_FUNC_NAMES);

lib/Serialization/SerializeSIL.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1868,7 +1868,16 @@ void SILSerializer::writeSILInstruction(const SILInstruction &SI) {
18681868
auto &opei = cast<OpenPackElementInst>(SI);
18691869
auto envRef =
18701870
S.addGenericEnvironmentRef(opei.getOpenedGenericEnvironment());
1871-
writeOneOperandLayout(SI.getKind(), envRef, opei.getIndexOperand());
1871+
auto operand = opei.getIndexOperand();
1872+
auto operandRef = addValueRef(operand);
1873+
auto operandType = operand->getType();
1874+
auto operandTypeRef = S.addTypeRef(operandType.getASTType());
1875+
1876+
SILOpenPackElementLayout::emitRecord(Out, ScratchRecord,
1877+
SILAbbrCodes[SILOpenPackElementLayout::Code],
1878+
envRef,
1879+
operandTypeRef, unsigned(operandType.getCategory()),
1880+
operandRef);
18721881
break;
18731882
}
18741883
case SILInstructionKind::GetAsyncContinuationAddrInst: {
@@ -3058,6 +3067,7 @@ void SILSerializer::writeSILBlock(const SILModule *SILMod) {
30583067
registerSILAbbr<SILInstLinearFunctionExtractLayout>();
30593068
registerSILAbbr<SILInstIncrementProfilerCounterLayout>();
30603069
registerSILAbbr<SILInstHasSymbolLayout>();
3070+
registerSILAbbr<SILOpenPackElementLayout>();
30613071
registerSILAbbr<SILPackElementGetLayout>();
30623072
registerSILAbbr<SILPackElementSetLayout>();
30633073

test/SIL/Serialization/pack_expansion_type.swift

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,36 @@
77

88
#if LIB
99

10-
public func callee<each T>(_: repeat each T) {}
10+
public func calleeWithPack<each T>(_: repeat each T) {}
1111

12-
@_transparent public func caller<each T>(_ t: repeat each T) {
13-
callee(repeat [each t])
12+
public func calleeGeneric<T>(_: T) {}
13+
14+
@_transparent public func transparentCaller<each T>(_ t: repeat each T) {
15+
calleeWithPack(repeat [each t])
16+
calleeGeneric((repeat [each t]))
17+
}
18+
19+
@_alwaysEmitIntoClient public func serializedCaller<each T>(_ t: repeat each T) {
20+
calleeWithPack(repeat [each t])
21+
calleeGeneric((repeat [each t]))
1422
}
1523

16-
public func calleer() {
17-
caller(1, "hi", false)
24+
public func transparentCaller2() {
25+
transparentCaller(1, "hi", false)
1826
}
1927

20-
public func foo<each T: Equatable>(_: repeat each T) {}
28+
public func calleeWithRequirement<each T: Equatable>(_: repeat each T) {}
2129

22-
@_transparent public func bar(x: Int, y: String) {
23-
foo(x, y)
30+
@_transparent public func callerWithRequirement(x: Int, y: String) {
31+
calleeWithRequirement(x, y)
2432
}
2533

2634
#elseif APP
2735

2836
import pack_expansion_type
2937

30-
caller(1, "hi", false)
31-
bar(x: 1, y: "hi")
38+
transparentCaller(1, "hi", false)
39+
serializedCaller(1, "hi", false)
40+
callerWithRequirement(x: 1, y: "hi")
3241

3342
#endif

0 commit comments

Comments
 (0)