Skip to content

Commit 01dd467

Browse files
committed
Fix SIL serialization of witness tables and protocol witness thunks
Serialize witness tables only if it -sil-serialize-all or -sil-serialize-witness-tables options are provided, which should happen only when building the stdlib and overlays, or it is a compilation with explicitly enabled resilience support. Disable serialization of witness tables in all other cases. Disabling the serialization of witness tables also avoids serialization of protocol witness thunks, whose serialization in 3rd party code sometimes resulted in performance degradation, because resilience checking rules used by many parts of the compiler would prohibit certain optimizations like inlining or specialization, if the caller was serialized and the callee would not be serialized. This should fix rdar://32718853 and address rdar://32743391
1 parent 2f920c4 commit 01dd467

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

lib/SILGen/SILGenType.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,17 @@ class SILGenConformance : public SILGenWitnessTable<SILGenConformance> {
314314
Serialized = IsNotSerialized;
315315

316316
// Serialize the witness table if we're serializing everything with
317-
// -sil-serialize-all, or if the conformance itself thinks it should be.
318-
if (SGM.isMakeModuleFragile() || Conformance->isSerialized())
317+
// -sil-serialize-all.
318+
if (SGM.isMakeModuleFragile())
319+
Serialized = IsSerialized;
320+
321+
// Serialize the witness table if the conformance itself thinks it should be
322+
// and resilience is explicitly enabled for this compilaiton or if we serialize
323+
// all eligible witness tables.
324+
if ((SGM.M.getSwiftModule()->getResilienceStrategy() ==
325+
ResilienceStrategy::Resilient ||
326+
SGM.M.getOptions().SILSerializeWitnessTables) &&
327+
Conformance->isSerialized())
319328
Serialized = IsSerialized;
320329

321330
// Not all protocols use witness tables; in this case we just skip

0 commit comments

Comments
 (0)