Skip to content

Commit 11a1741

Browse files
committed
[move-only] Fix dead code elimination to preserve value deinits.
(cherry picked from commit 1dcc240)
1 parent ce68e4c commit 11a1741

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

include/swift/SIL/SILMoveOnlyDeinit.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ class SILMoveOnlyDeinit final : public SILAllocated<SILMoveOnlyDeinit> {
6161

6262
NominalTypeDecl *getNominalDecl() const { return nominalDecl; }
6363

64-
SILFunction *getImplementation() const { return funcImpl; }
64+
SILFunction *getImplementation() const {
65+
assert(funcImpl);
66+
return funcImpl;
67+
}
6568

6669
IsSerialized_t isSerialized() const {
6770
return serialized ? IsSerialized : IsNotSerialized;

lib/SILOptimizer/IPO/DeadFunctionElimination.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ class DeadFunctionAndGlobalElimination {
7171
}
7272

7373
/// Adds an implementation of the method in a specific conformance.
74+
///
75+
/// \p Conf is null for default implementations and move-only deinits
7476
void addWitnessFunction(SILFunction *F, RootProtocolConformance *Conf) {
7577
assert(isWitnessMethod);
7678
implementingFunctions.push_back(FuncImpl(F, Conf));
@@ -616,6 +618,14 @@ class DeadFunctionAndGlobalElimination {
616618
if (dw.getVJP())
617619
ensureAlive(dw.getVJP());
618620
}
621+
622+
// Collect move-only deinit methods.
623+
//
624+
// TODO: Similar to addWitnessFunction, track the associated
625+
// struct/enum decl to allow DCE of unused deinits.
626+
for (auto *deinit : Module->getMoveOnlyDeinits()) {
627+
makeAlive(deinit->getImplementation());
628+
}
619629
}
620630

621631
/// Removes all dead methods from vtables and witness tables.

0 commit comments

Comments
 (0)