Skip to content

Commit 07a4c22

Browse files
authored
Merge pull request #22519 from gottesmm/pr-bafb507409a233c2b64c95d66aa152e937fe7b86
[gardening] Change an if-else over ApplySite to a covered switch over…
2 parents 2e6b330 + bc280ab commit 07a4c22

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

lib/SILOptimizer/IPO/UsePrespecialized.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ class UsePrespecialized: public SILModuleTransform {
5555
bool replaceByPrespecialized(SILFunction &F);
5656
};
5757

58+
} // end anonymous namespace
59+
5860
// Analyze the function and replace each apply of
5961
// a generic function by an apply of the corresponding
6062
// pre-specialized function, if such a pre-specialization exists.
@@ -143,12 +145,17 @@ bool UsePrespecialized::replaceByPrespecialized(SILFunction &F) {
143145
<< " : " << NewF->getName() << "\n");
144146

145147
auto NewAI = replaceWithSpecializedFunction(AI, NewF, ReInfo);
146-
if (auto oldApply = dyn_cast<ApplyInst>(AI)) {
147-
oldApply->replaceAllUsesWith(cast<ApplyInst>(NewAI));
148-
} else if (auto oldPApply = dyn_cast<PartialApplyInst>(AI)) {
149-
oldPApply->replaceAllUsesWith(cast<PartialApplyInst>(NewAI));
150-
} else {
151-
assert(isa<TryApplyInst>(NewAI) || isa<BeginApplyInst>(NewAI));
148+
switch (AI.getKind()) {
149+
case ApplySiteKind::ApplyInst:
150+
cast<ApplyInst>(AI)->replaceAllUsesWith(cast<ApplyInst>(NewAI));
151+
break;
152+
case ApplySiteKind::PartialApplyInst:
153+
cast<PartialApplyInst>(AI)->replaceAllUsesWith(
154+
cast<PartialApplyInst>(NewAI));
155+
break;
156+
case ApplySiteKind::TryApplyInst:
157+
case ApplySiteKind::BeginApplyInst:
158+
break;
152159
}
153160
recursivelyDeleteTriviallyDeadInstructions(AI.getInstruction(), true);
154161
Changed = true;
@@ -157,8 +164,6 @@ bool UsePrespecialized::replaceByPrespecialized(SILFunction &F) {
157164
return Changed;
158165
}
159166

160-
} // end anonymous namespace
161-
162167

163168
SILTransform *swift::createUsePrespecialized() {
164169
return new UsePrespecialized();

0 commit comments

Comments
 (0)