Skip to content

Commit 1dcc240

Browse files
committed
[move-only] Fix dead code elimination to preserve value deinits.
1 parent 4a37b00 commit 1dcc240

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));
@@ -618,6 +620,14 @@ class DeadFunctionAndGlobalElimination {
618620
if (dw.getVJP())
619621
ensureAlive(dw.getVJP());
620622
}
623+
624+
// Collect move-only deinit methods.
625+
//
626+
// TODO: Similar to addWitnessFunction, track the associated
627+
// struct/enum decl to allow DCE of unused deinits.
628+
for (auto *deinit : Module->getMoveOnlyDeinits()) {
629+
makeAlive(deinit->getImplementation());
630+
}
621631
}
622632

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

0 commit comments

Comments
 (0)