Skip to content

Commit 5bb42c3

Browse files
committed
SIL: Visit pack conformances in DeadFunctionElimination
1 parent 944267d commit 5bb42c3

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

Diff for: lib/SILOptimizer/IPO/DeadFunctionElimination.cpp

+20-10
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#define DEBUG_TYPE "sil-dead-function-elimination"
14+
#include "swift/AST/PackConformance.h"
1415
#include "swift/AST/ProtocolConformance.h"
1516
#include "swift/Basic/Assertions.h"
1617
#include "swift/SIL/InstructionUtils.h"
@@ -204,12 +205,11 @@ class DeadFunctionAndGlobalElimination {
204205
case SILWitnessTable::AssociatedConformance: {
205206
ProtocolConformanceRef CRef =
206207
entry.getAssociatedConformanceWitness().Witness;
207-
if (CRef.isConcrete())
208-
ensureAliveConformance(CRef.getConcrete());
208+
ensureAliveConformance(CRef);
209209
break;
210210
}
211211
case SILWitnessTable::BaseProtocol:
212-
ensureAliveConformance(entry.getBaseProtocolWitness().Witness);
212+
ensureAliveConformance(ProtocolConformanceRef(entry.getBaseProtocolWitness().Witness));
213213
break;
214214

215215
case SILWitnessTable::Invalid:
@@ -219,8 +219,7 @@ class DeadFunctionAndGlobalElimination {
219219
}
220220

221221
for (const auto &conf : WT->getConditionalConformances()) {
222-
if (conf.isConcrete())
223-
ensureAliveConformance(conf.getConcrete());
222+
ensureAliveConformance(conf);
224223
}
225224
}
226225

@@ -280,11 +279,22 @@ class DeadFunctionAndGlobalElimination {
280279
}
281280

282281
/// Marks a witness table as alive if it is not alive yet.
283-
void ensureAliveConformance(const ProtocolConformance *C) {
284-
SILWitnessTable *WT = Module->lookUpWitnessTable(C);
285-
if (!WT || isAlive(WT))
286-
return;
287-
makeAlive(WT);
282+
void ensureAliveConformance(ProtocolConformanceRef conformance) {
283+
if (conformance.isConcrete()) {
284+
auto *concrete = conformance.getConcrete();
285+
SILWitnessTable *WT = Module->lookUpWitnessTable(concrete);
286+
if (!WT || isAlive(WT))
287+
return;
288+
makeAlive(WT);
289+
290+
// FIXME: If 'concrete' is a SpecializedProtocolConformance,
291+
// do we need to check its substitution map and root conformance
292+
// recursively?
293+
} else if (conformance.isPack()) {
294+
auto *pack = conformance.getPack();
295+
for (auto patternConf : pack->getPatternConformances())
296+
ensureAliveConformance(patternConf);
297+
}
288298
}
289299

290300
/// Returns true if the implementation of method \p FD in class \p ImplCl

0 commit comments

Comments
 (0)