Skip to content

Commit 0747bea

Browse files
committed
[+0-normal-args] Use ManagedValues instead of SILValues in PatternMatchEmission::emitSharedCaseBlocks().
This commit hoists the creation of ManagedValues earlier in the function. This ensures that the SILValues are never separated from their cleanups and allow us to pass ManagedValues that have proper cleanups to the forwardInto/assignInto API that is used herethe values into memory at +1. Previously, we would just drop the cleanup and forward the non-trivial value into memory without a cleanup, breaking invariants. Since it is just moving things earlier this is a pure /NFC/ change. As an extra benefit, this updates the code to use more modern SILGen. rdar://34222540
1 parent fa76278 commit 0747bea

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

lib/SILGen/SILGenPattern.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2460,7 +2460,9 @@ void PatternMatchEmission::emitSharedCaseBlocks() {
24602460

24612461
SILType ty = SGF.getLoweredType(V->getType());
24622462

2463-
SILValue value;
2463+
// Initialize mv at +1. We always pass values in at +1 for today into
2464+
// shared blocks.
2465+
ManagedValue mv;
24642466
if (ty.isAddressOnly(SGF.F.getModule())) {
24652467
// There's no basic block argument, since we don't allow basic blocks
24662468
// to have address arguments.
@@ -2473,21 +2475,22 @@ void PatternMatchEmission::emitSharedCaseBlocks() {
24732475
// been initialized on entry.
24742476
auto found = Temporaries.find(V);
24752477
assert(found != Temporaries.end());
2476-
value = found->second;
2478+
mv = SGF.emitManagedRValueWithCleanup(found->second);
24772479
} else {
2478-
value = caseBB->getArgument(argIndex++);
2480+
SILValue arg = caseBB->getArgument(argIndex++);
2481+
assert(arg.getOwnershipKind() == ValueOwnershipKind::Owned ||
2482+
arg.getOwnershipKind() == ValueOwnershipKind::Trivial);
2483+
mv = SGF.emitManagedRValueWithCleanup(arg);
24792484
}
24802485

24812486
if (V->isLet()) {
2482-
// Just emit a let with cleanup.
2483-
SGF.VarLocs[V].value = value;
2484-
SGF.enterDestroyCleanup(value);
2487+
// Just emit a let and leave the cleanup alone.
2488+
SGF.VarLocs[V].value = mv.getValue();
24852489
} else {
24862490
// The pattern variables were all emitted as lets and one got passed in,
24872491
// now we finally alloc a box for the var and forward in the chosen value.
24882492
SGF.VarLocs.erase(V);
24892493
auto newVar = SGF.emitInitializationForVarDecl(V, V->isLet());
2490-
auto mv = ManagedValue::forUnmanaged(value);
24912494
newVar->copyOrInitValueInto(SGF, V, mv, /*isInit*/ true);
24922495
newVar->finishInitialization(SGF);
24932496
}

0 commit comments

Comments
 (0)