11
11
// ===----------------------------------------------------------------------===//
12
12
13
13
#define DEBUG_TYPE " sil-dead-function-elimination"
14
+ #include " swift/AST/PackConformance.h"
14
15
#include " swift/AST/ProtocolConformance.h"
15
16
#include " swift/Basic/Assertions.h"
16
17
#include " swift/SIL/InstructionUtils.h"
@@ -204,12 +205,11 @@ class DeadFunctionAndGlobalElimination {
204
205
case SILWitnessTable::AssociatedConformance: {
205
206
ProtocolConformanceRef CRef =
206
207
entry.getAssociatedConformanceWitness ().Witness ;
207
- if (CRef.isConcrete ())
208
- ensureAliveConformance (CRef.getConcrete ());
208
+ ensureAliveConformance (CRef);
209
209
break ;
210
210
}
211
211
case SILWitnessTable::BaseProtocol:
212
- ensureAliveConformance (entry.getBaseProtocolWitness ().Witness );
212
+ ensureAliveConformance (ProtocolConformanceRef ( entry.getBaseProtocolWitness ().Witness ) );
213
213
break ;
214
214
215
215
case SILWitnessTable::Invalid:
@@ -219,8 +219,7 @@ class DeadFunctionAndGlobalElimination {
219
219
}
220
220
221
221
for (const auto &conf : WT->getConditionalConformances ()) {
222
- if (conf.isConcrete ())
223
- ensureAliveConformance (conf.getConcrete ());
222
+ ensureAliveConformance (conf);
224
223
}
225
224
}
226
225
@@ -280,11 +279,22 @@ class DeadFunctionAndGlobalElimination {
280
279
}
281
280
282
281
// / 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
+ }
288
298
}
289
299
290
300
// / Returns true if the implementation of method \p FD in class \p ImplCl
0 commit comments