Skip to content

Commit 27c5366

Browse files
committed
[dfe] Change Impl to be a stongly typed PointerUnion instead of a union.
1 parent 6982d65 commit 27c5366

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

lib/SILOptimizer/IPO/DeadFunctionElimination.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,15 @@ class FunctionLivenessComputation {
3939
/// Represents a function which is implementing a vtable or witness table
4040
/// method.
4141
struct FuncImpl {
42-
FuncImpl(SILFunction *F, ClassDecl *Cl) : F(F) { Impl.Cl = Cl; }
43-
FuncImpl(SILFunction *F, ProtocolConformance *C) : F(F) { Impl.Conf = C; }
42+
FuncImpl(SILFunction *F, ClassDecl *Cl) : F(F), Impl(Cl) {}
43+
FuncImpl(SILFunction *F, ProtocolConformance *C) : F(F), Impl(C) {}
4444

4545
/// The implementing function.
4646
SILFunction *F;
4747

48-
union {
49-
/// In case of a vtable method.
50-
ClassDecl *Cl;
51-
52-
/// In case of a witness method.
53-
ProtocolConformance *Conf;
54-
} Impl;
48+
/// This is a class decl if we are tracking a class_method (i.e. a vtable
49+
/// method) and a protocol conformance if we are tracking a witness_method.
50+
PointerUnion<ClassDecl *, ProtocolConformance *> Impl;
5551
};
5652

5753
/// Stores which functions implement a vtable or witness table method.
@@ -303,7 +299,8 @@ class FunctionLivenessComputation {
303299

304300
for (FuncImpl &FImpl : mi->implementingFunctions) {
305301
if (!isAlive(FImpl.F) &&
306-
canHaveSameImplementation(FD, MethodCl, FImpl.Impl.Cl)) {
302+
canHaveSameImplementation(FD, MethodCl,
303+
FImpl.Impl.get<ClassDecl *>())) {
307304
makeAlive(FImpl.F);
308305
} else {
309306
allImplsAreCalled = false;
@@ -320,9 +317,10 @@ class FunctionLivenessComputation {
320317
return;
321318
mi->methodIsCalled = true;
322319
for (FuncImpl &FImpl : mi->implementingFunctions) {
323-
if (FImpl.Impl.Conf) {
324-
SILWitnessTable *WT = Module->lookUpWitnessTable(FImpl.Impl.Conf,
325-
/*deserializeLazily*/ false);
320+
if (auto *Conf = FImpl.Impl.dyn_cast<ProtocolConformance *>()) {
321+
SILWitnessTable *WT =
322+
Module->lookUpWitnessTable(Conf,
323+
/*deserializeLazily*/ false);
326324
if (!WT || isAlive(WT))
327325
makeAlive(FImpl.F);
328326
} else {

0 commit comments

Comments
 (0)