Skip to content

Commit d7bd071

Browse files
committed
SIL: Change the linker to deserialize more lazily
Note that SILModule::lookUpWitnessTable() only attempts to deserialize the witness table if we already have a declaration. In the SILLinkerVisitor, we would call lookUpWitnessTable(), see if it returned null, create a declaration, and if deserializeLazily is true, we would call lookUpWitnessTable() again; this time, there was a declaration, and we would deserialize the witness table. However, if there was already a witness table declaration when we first called lookUpWitnessTable(), we would trigger deserialization, even if deserializeLazily is false. Change the first call to pass false. I had to update a couple of tests; I believe they were already somewhat nonsensical.
1 parent 39c93b9 commit d7bd071

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

lib/SIL/Linker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ void SILLinkerVisitor::visitProtocolConformance(
212212
if (!VisitedConformances.insert(C).second)
213213
return;
214214

215-
SILWitnessTable *WT = Mod.lookUpWitnessTable(C, true);
215+
SILWitnessTable *WT = Mod.lookUpWitnessTable(C, /*deserializeLazily=*/false);
216216

217217
// If we don't find any witness table for the conformance, bail and return
218218
// false.
@@ -222,7 +222,7 @@ void SILLinkerVisitor::visitProtocolConformance(
222222
// Adding the declaration may allow us to now deserialize the body.
223223
// Force the body if we must deserialize this witness table.
224224
if (mustDeserialize) {
225-
WT = Mod.lookUpWitnessTable(C, true);
225+
WT = Mod.lookUpWitnessTable(C, /*deserializeLazily=*/true);
226226
assert(WT && WT->isDefinition()
227227
&& "unable to deserialize witness table when we must?!");
228228
} else {

test/SIL/Serialization/Inputs/init_existential_inst_deserializes_witness_tables_input.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public struct X : P {
1313
public init() {}
1414
}
1515

16+
@inlinable
1617
public func whatShouldIDo(_ p : P) {
1718
p.doSomething()
1819
}

test/SILOptimizer/dead_witness_module.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
// DeadFunctionElimination may not remove a method from a witness table which
66
// is imported from another module.
77

8+
// FIXME: Ever since @usableFromInline began to be enforced, this test did not
9+
// test anything useful, and now the witness table is never deserialized at all.
10+
811
import TestModule
912

1013
testit(MyStruct())
1114

12-
// CHECK: sil_witness_table public_external MyStruct: Proto module TestModule
13-
// CHECK-NEXT: method #Proto.confx!1: {{.*}} : @$s{{.*}}confx{{.*}}FTW
15+
// CHECK: sil_witness_table MyStruct: Proto module TestModule{{$}}

0 commit comments

Comments
 (0)