BorrowToDestructureUtils: handle borrowing switches.

Instead of trying to convert all switches into consumes, allow a switch of a borrow
to remain as such.
This commit is contained in:
Joe Groff
2024-01-31 16:09:53 -08:00
parent 6706feaf5e
commit 03e2e8f476
4 changed files with 120 additions and 47 deletions

View File

@@ -304,11 +304,23 @@ SubElementOffset::computeForValue(SILValue projectionDerivedFromRoot,
// So our payload is always going to start at the current field number since
// we are the left most child of our parent enum. So we just need to look
// through to our parent enum.
//
// Enum projections can happen either directly via an unchecked instruction…
if (auto *enumData =
dyn_cast<UncheckedEnumDataInst>(projectionDerivedFromRoot)) {
projectionDerivedFromRoot = enumData->getOperand();
continue;
}
// …or via the bb arg of a `switch_enum` successor.
if (auto bbArg = dyn_cast<SILArgument>(projectionDerivedFromRoot)) {
if (auto pred = bbArg->getParent()->getSinglePredecessorBlock()) {
if (auto switchEnum = dyn_cast<SwitchEnumInst>(pred->getTerminator())) {
projectionDerivedFromRoot = switchEnum->getOperand();
continue;
}
}
}
// If we do not know how to handle this case, just return None.
//