Skip to content

[+0-normal-args] When initializating an Any with trivial inline buffer contents, put a cleanup on the Any. #14641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions lib/SILGen/SILGenPoly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,11 @@ namespace {
SGF.B.createInjectEnumAddr(Loc, optionalBuf, someDecl);

auto payload = tupleTemp->getManagedAddress();
return ManagedValue(optionalBuf, payload.getCleanup());
if (payload.hasCleanup()) {
payload.forward(SGF);
return SGF.emitManagedBufferWithCleanup(optionalBuf);
}
return ManagedValue::forUnmanaged(optionalBuf);
}
}

Expand Down Expand Up @@ -1150,15 +1154,20 @@ namespace {

auto payload = tupleTemp->getManagedAddress();
if (SGF.silConv.useLoweredAddresses()) {
return ManagedValue(existentialBuf, payload.getCleanup());
// We always need to return the existential buf with a cleanup even if
// we stored trivial values, since SILGen maintains the invariant that
// forwarding a non-trivial value (i.e. an Any) into memory must be done
// at +1.
payload.forward(SGF);
return SGF.emitManagedBufferWithCleanup(existentialBuf);
}

// We are under opaque value(s) mode - load the any and init an opaque
auto loadedPayload = SGF.emitManagedLoadCopy(Loc, payload.getValue());
auto loadedPayload = SGF.B.createLoadCopy(Loc, payload);
auto &anyTL = SGF.getTypeLowering(opaque, outputSubstType);
SILValue loadedOpaque = SGF.B.createInitExistentialValue(
Loc, anyTL.getLoweredType(), inputTupleType, loadedPayload.getValue(),
return SGF.B.createInitExistentialValue(
Loc, anyTL.getLoweredType(), inputTupleType, loadedPayload,
/*Conformances=*/{});
return ManagedValue(loadedOpaque, loadedPayload.getCleanup());
}

/// Handle a tuple that has been exploded in both the input and
Expand Down