mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[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
This commit is contained in:
@@ -856,6 +856,8 @@ void Serializer::writeBlockInfoBlock() {
|
||||
BLOCK_RECORD(sil_index_block, SIL_DEFAULT_WITNESS_TABLE_NAMES);
|
||||
BLOCK_RECORD(sil_index_block, SIL_DEFAULT_WITNESS_TABLE_OFFSETS);
|
||||
BLOCK_RECORD(sil_index_block, SIL_PROPERTY_OFFSETS);
|
||||
BLOCK_RECORD(sil_index_block, SIL_DIFFERENTIABILITY_WITNESS_NAMES);
|
||||
BLOCK_RECORD(sil_index_block, SIL_DIFFERENTIABILITY_WITNESS_OFFSETS);
|
||||
|
||||
#undef BLOCK
|
||||
#undef BLOCK_RECORD
|
||||
|
||||
@@ -2346,6 +2346,11 @@ void SILSerializer::writeIndexTables() {
|
||||
DefaultWitnessTableOffset);
|
||||
}
|
||||
|
||||
if (!PropertyOffset.empty()) {
|
||||
Offset.emit(ScratchRecord, sil_index_block::SIL_PROPERTY_OFFSETS,
|
||||
PropertyOffset);
|
||||
}
|
||||
|
||||
if (!DifferentiabilityWitnessList.empty()) {
|
||||
writeIndexTable(S, List,
|
||||
sil_index_block::SIL_DIFFERENTIABILITY_WITNESS_NAMES,
|
||||
@@ -2355,11 +2360,6 @@ void SILSerializer::writeIndexTables() {
|
||||
DifferentiabilityWitnessOffset);
|
||||
}
|
||||
|
||||
if (!PropertyOffset.empty()) {
|
||||
Offset.emit(ScratchRecord, sil_index_block::SIL_PROPERTY_OFFSETS,
|
||||
PropertyOffset);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void SILSerializer::writeSILGlobalVar(const SILGlobalVariable &g) {
|
||||
|
||||
51
test/Serialization/index-table-order.sil
Normal file
51
test/Serialization/index-table-order.sil
Normal file
@@ -0,0 +1,51 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
|
||||
// Ensure that serialized sib can be deserialized correctly assuming
|
||||
// contents of SIL_INDEX_BLOCK are sorted by their ids
|
||||
// RUN: %target-swift-frontend -emit-sib %s -module-name test -o %t/test.sib
|
||||
// RUN: %target-swift-frontend -emit-sil %t/test.sib -module-name test
|
||||
// CHECK-DAG: sil_vtable
|
||||
// CHECK-DAG: sil_global
|
||||
// CHECK-DAG: sil_witness_table
|
||||
// CHECK-DAG: sil_default_witness_table
|
||||
// CHECK-DAG: sil_property
|
||||
|
||||
sil_stage canonical
|
||||
|
||||
import Builtin
|
||||
import Swift
|
||||
|
||||
// For SIL_FUNC_NAMES
|
||||
sil @id : $@convention(thin) (Float) -> Float {
|
||||
bb0(%0 : $Float):
|
||||
return %0 : $Float
|
||||
}
|
||||
|
||||
|
||||
// For SIL_VTABLE_NAMES
|
||||
class C {}
|
||||
sil_vtable C {}
|
||||
|
||||
// For SIL_GLOBALVAR_NAMES
|
||||
sil_global @x : $Int
|
||||
|
||||
// For SIL_WITNESS_TABLE_NAMES
|
||||
protocol P1 {}
|
||||
struct S : P1 {}
|
||||
|
||||
sil_witness_table S: P1 module test {}
|
||||
|
||||
// For SIL_DEFAULT_WITNESS_TABLE_NAMES
|
||||
protocol P2 {}
|
||||
sil_default_witness_table P2 {}
|
||||
|
||||
// For SIL_PROPERTY_OFFSETS
|
||||
struct A {
|
||||
var a: Int
|
||||
}
|
||||
|
||||
sil_property #A.a ()
|
||||
|
||||
// For SIL_DIFFERENTIABILITY_WITNESS_NAMES
|
||||
sil_differentiability_witness [parameters 0] [results 0] @id : $@convention(thin) (Float) -> Float {}
|
||||
|
||||
Reference in New Issue
Block a user