Skip to content

Commit 7989d3f

Browse files
authored
Merge pull request #22720 from gottesmm/pr-92e66215cb00ac99f0a42ba2235807d017811217
[silgen] Remove some unnecessary indentation from SILGenPattern::emitSwitchStmt
2 parents 43feb9c + 9b9d01e commit 7989d3f

File tree

1 file changed

+53
-50
lines changed

1 file changed

+53
-50
lines changed

lib/SILGen/SILGenPattern.cpp

Lines changed: 53 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2654,62 +2654,65 @@ void SILGenFunction::emitSwitchStmt(SwitchStmt *S) {
26542654
// statement.
26552655
JumpDest sharedDest = emission.getSharedCaseBlockDest(caseBlock);
26562656
Cleanups.emitBranchAndCleanups(sharedDest, caseBlock);
2657-
} else if (row.hasFallthroughTo() || caseBlock->getCaseLabelItems().size() > 1) {
2658-
JumpDest sharedDest =
2659-
emission.getSharedCaseBlockDest(caseBlock);
2660-
2661-
// Generate the arguments from this row's pattern in the case block's
2662-
// expected order, and keep those arguments from being cleaned up, as
2663-
// we're passing the +1 along to the shared case block dest. (The
2664-
// cleanups still happen, as they are threaded through here messily,
2665-
// but the explicit retains here counteract them, and then the
2666-
// retain/release pair gets optimized out.)
2667-
ArrayRef<CaseLabelItem> labelItems = caseBlock->getCaseLabelItems();
2668-
SmallVector<SILValue, 4> args;
2669-
SmallVector<VarDecl *, 4> expectedVarOrder;
2670-
SmallVector<VarDecl *, 4> vars;
2671-
labelItems[0].getPattern()->collectVariables(expectedVarOrder);
2672-
row.getCasePattern()->collectVariables(vars);
2673-
2674-
SILModule &M = F.getModule();
2675-
for (auto expected : expectedVarOrder) {
2676-
if (!expected->hasName())
2657+
return;
2658+
}
2659+
2660+
// If we don't have a fallthrough or a multi-pattern 'case', we can just
2661+
// emit the body inline and save some dead blocks. Emit the statement here.
2662+
if (!row.hasFallthroughTo() && caseBlock->getCaseLabelItems().size() == 1) {
2663+
emission.emitCaseBody(caseBlock);
2664+
return;
2665+
}
2666+
2667+
JumpDest sharedDest = emission.getSharedCaseBlockDest(caseBlock);
2668+
2669+
// Generate the arguments from this row's pattern in the case block's
2670+
// expected order, and keep those arguments from being cleaned up, as
2671+
// we're passing the +1 along to the shared case block dest. (The
2672+
// cleanups still happen, as they are threaded through here messily,
2673+
// but the explicit retains here counteract them, and then the
2674+
// retain/release pair gets optimized out.)
2675+
ArrayRef<CaseLabelItem> labelItems = caseBlock->getCaseLabelItems();
2676+
SmallVector<SILValue, 4> args;
2677+
SmallVector<VarDecl *, 4> expectedVarOrder;
2678+
SmallVector<VarDecl *, 4> vars;
2679+
labelItems[0].getPattern()->collectVariables(expectedVarOrder);
2680+
row.getCasePattern()->collectVariables(vars);
2681+
2682+
SILModule &M = F.getModule();
2683+
for (auto expected : expectedVarOrder) {
2684+
if (!expected->hasName())
2685+
continue;
2686+
for (auto *var : vars) {
2687+
if (!var->hasName() || var->getName() != expected->getName())
26772688
continue;
2678-
for (auto *var : vars) {
2679-
if (var->hasName() && var->getName() == expected->getName()) {
2680-
SILValue value = VarLocs[var].value;
2681-
SILType type = value->getType();
2682-
2683-
// If we have an address-only type, initialize the temporary
2684-
// allocation. We're not going to pass the address as a block
2685-
// argument.
2686-
if (type.isAddressOnly(M)) {
2687-
emission.emitAddressOnlyInitialization(expected, value);
2688-
break;
2689-
}
26902689

2691-
// If we have a loadable address, perform a load [copy].
2692-
if (type.isAddress()) {
2693-
value = B.emitLoadValueOperation(CurrentSILLoc, value,
2694-
LoadOwnershipQualifier::Copy);
2695-
args.push_back(value);
2696-
break;
2697-
}
2690+
SILValue value = VarLocs[var].value;
2691+
SILType type = value->getType();
26982692

2699-
value = B.emitCopyValueOperation(CurrentSILLoc, value);
2700-
args.push_back(value);
2701-
break;
2702-
}
2693+
// If we have an address-only type, initialize the temporary
2694+
// allocation. We're not going to pass the address as a block
2695+
// argument.
2696+
if (type.isAddressOnly(M)) {
2697+
emission.emitAddressOnlyInitialization(expected, value);
2698+
break;
27032699
}
2704-
}
27052700

2706-
Cleanups.emitBranchAndCleanups(sharedDest, caseBlock, args);
2707-
} else {
2708-
// However, if we don't have a fallthrough or a multi-pattern 'case', we
2709-
// can just emit the body inline and save some dead blocks.
2710-
// Emit the statement here.
2711-
emission.emitCaseBody(caseBlock);
2701+
// If we have a loadable address, perform a load [copy].
2702+
if (type.isAddress()) {
2703+
value = B.emitLoadValueOperation(CurrentSILLoc, value,
2704+
LoadOwnershipQualifier::Copy);
2705+
args.push_back(value);
2706+
break;
2707+
}
2708+
2709+
value = B.emitCopyValueOperation(CurrentSILLoc, value);
2710+
args.push_back(value);
2711+
break;
2712+
}
27122713
}
2714+
2715+
Cleanups.emitBranchAndCleanups(sharedDest, caseBlock, args);
27132716
};
27142717

27152718
PatternMatchEmission emission(*this, S, completionHandler);

0 commit comments

Comments
 (0)