Skip to content

Commit d913e57

Browse files
[Serialization] Serialize Differentiability WT index sorted
When there are sil_property and sil_differentiability_witness at once, serialized file couldn't be deserialized because it's index table is serialized un-sortedly but deserializer assumes that contents of table index are sorted. This patch fixes the un-sorted serialization and adds test case to ensure that table index contents can be deserialized
1 parent d3f0de8 commit d913e57

File tree

3 files changed

+58
-5
lines changed

3 files changed

+58
-5
lines changed

lib/Serialization/Serialization.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,8 @@ void Serializer::writeBlockInfoBlock() {
856856
BLOCK_RECORD(sil_index_block, SIL_DEFAULT_WITNESS_TABLE_NAMES);
857857
BLOCK_RECORD(sil_index_block, SIL_DEFAULT_WITNESS_TABLE_OFFSETS);
858858
BLOCK_RECORD(sil_index_block, SIL_PROPERTY_OFFSETS);
859+
BLOCK_RECORD(sil_index_block, SIL_DIFFERENTIABILITY_WITNESS_NAMES);
860+
BLOCK_RECORD(sil_index_block, SIL_DIFFERENTIABILITY_WITNESS_OFFSETS);
859861

860862
#undef BLOCK
861863
#undef BLOCK_RECORD

lib/Serialization/SerializeSIL.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2346,6 +2346,11 @@ void SILSerializer::writeIndexTables() {
23462346
DefaultWitnessTableOffset);
23472347
}
23482348

2349+
if (!PropertyOffset.empty()) {
2350+
Offset.emit(ScratchRecord, sil_index_block::SIL_PROPERTY_OFFSETS,
2351+
PropertyOffset);
2352+
}
2353+
23492354
if (!DifferentiabilityWitnessList.empty()) {
23502355
writeIndexTable(S, List,
23512356
sil_index_block::SIL_DIFFERENTIABILITY_WITNESS_NAMES,
@@ -2355,11 +2360,6 @@ void SILSerializer::writeIndexTables() {
23552360
DifferentiabilityWitnessOffset);
23562361
}
23572362

2358-
if (!PropertyOffset.empty()) {
2359-
Offset.emit(ScratchRecord, sil_index_block::SIL_PROPERTY_OFFSETS,
2360-
PropertyOffset);
2361-
}
2362-
23632363
}
23642364

23652365
void SILSerializer::writeSILGlobalVar(const SILGlobalVariable &g) {
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// Ensure that serialized sib can be deserialized correctly assuming
4+
// contents of SIL_INDEX_BLOCK are sorted by their ids
5+
// RUN: %target-swift-frontend -emit-sib %s -module-name test -o %t/test.sib
6+
// RUN: %target-swift-frontend -emit-sil %t/test.sib -module-name test
7+
// CHECK-DAG: sil_vtable
8+
// CHECK-DAG: sil_global
9+
// CHECK-DAG: sil_witness_table
10+
// CHECK-DAG: sil_default_witness_table
11+
// CHECK-DAG: sil_property
12+
13+
sil_stage canonical
14+
15+
import Builtin
16+
import Swift
17+
18+
// For SIL_FUNC_NAMES
19+
sil @id : $@convention(thin) (Float) -> Float {
20+
bb0(%0 : $Float):
21+
return %0 : $Float
22+
}
23+
24+
25+
// For SIL_VTABLE_NAMES
26+
class C {}
27+
sil_vtable C {}
28+
29+
// For SIL_GLOBALVAR_NAMES
30+
sil_global @x : $Int
31+
32+
// For SIL_WITNESS_TABLE_NAMES
33+
protocol P1 {}
34+
struct S : P1 {}
35+
36+
sil_witness_table S: P1 module test {}
37+
38+
// For SIL_DEFAULT_WITNESS_TABLE_NAMES
39+
protocol P2 {}
40+
sil_default_witness_table P2 {}
41+
42+
// For SIL_PROPERTY_OFFSETS
43+
struct A {
44+
var a: Int
45+
}
46+
47+
sil_property #A.a ()
48+
49+
// For SIL_DIFFERENTIABILITY_WITNESS_NAMES
50+
sil_differentiability_witness [parameters 0] [results 0] @id : $@convention(thin) (Float) -> Float {}
51+

0 commit comments

Comments
 (0)