Skip to content

Commit f74502e

Browse files
authored
Merge pull request #33325 from kateinoigakukun/katei/sort-diff-wt-serialization
[Serialization] Serialize Differentiability WT index sorted
2 parents 643aa2d + d913e57 commit f74502e

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
@@ -2345,6 +2345,11 @@ void SILSerializer::writeIndexTables() {
23452345
DefaultWitnessTableOffset);
23462346
}
23472347

2348+
if (!PropertyOffset.empty()) {
2349+
Offset.emit(ScratchRecord, sil_index_block::SIL_PROPERTY_OFFSETS,
2350+
PropertyOffset);
2351+
}
2352+
23482353
if (!DifferentiabilityWitnessList.empty()) {
23492354
writeIndexTable(S, List,
23502355
sil_index_block::SIL_DIFFERENTIABILITY_WITNESS_NAMES,
@@ -2354,11 +2359,6 @@ void SILSerializer::writeIndexTables() {
23542359
DifferentiabilityWitnessOffset);
23552360
}
23562361

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

23642364
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)