mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[+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
This commit is contained in:
@@ -2460,7 +2460,9 @@ void PatternMatchEmission::emitSharedCaseBlocks() {
|
||||
|
||||
SILType ty = SGF.getLoweredType(V->getType());
|
||||
|
||||
SILValue value;
|
||||
// Initialize mv at +1. We always pass values in at +1 for today into
|
||||
// shared blocks.
|
||||
ManagedValue mv;
|
||||
if (ty.isAddressOnly(SGF.F.getModule())) {
|
||||
// There's no basic block argument, since we don't allow basic blocks
|
||||
// to have address arguments.
|
||||
@@ -2473,21 +2475,22 @@ void PatternMatchEmission::emitSharedCaseBlocks() {
|
||||
// been initialized on entry.
|
||||
auto found = Temporaries.find(V);
|
||||
assert(found != Temporaries.end());
|
||||
value = found->second;
|
||||
mv = SGF.emitManagedRValueWithCleanup(found->second);
|
||||
} else {
|
||||
value = caseBB->getArgument(argIndex++);
|
||||
SILValue arg = caseBB->getArgument(argIndex++);
|
||||
assert(arg.getOwnershipKind() == ValueOwnershipKind::Owned ||
|
||||
arg.getOwnershipKind() == ValueOwnershipKind::Trivial);
|
||||
mv = SGF.emitManagedRValueWithCleanup(arg);
|
||||
}
|
||||
|
||||
if (V->isLet()) {
|
||||
// Just emit a let with cleanup.
|
||||
SGF.VarLocs[V].value = value;
|
||||
SGF.enterDestroyCleanup(value);
|
||||
// Just emit a let and leave the cleanup alone.
|
||||
SGF.VarLocs[V].value = mv.getValue();
|
||||
} else {
|
||||
// The pattern variables were all emitted as lets and one got passed in,
|
||||
// now we finally alloc a box for the var and forward in the chosen value.
|
||||
SGF.VarLocs.erase(V);
|
||||
auto newVar = SGF.emitInitializationForVarDecl(V, V->isLet());
|
||||
auto mv = ManagedValue::forUnmanaged(value);
|
||||
newVar->copyOrInitValueInto(SGF, V, mv, /*isInit*/ true);
|
||||
newVar->finishInitialization(SGF);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user