Create two versions (for caller and callee) of the functions that answer questions about parameter convention (#74124)

Create two versions of the following functions:

isConsumedParameter
isGuaranteedParameter
SILParameterInfo::isConsumed
SILParameterInfo::isGuaranteed
SILArgumentConvention::isOwnedConvention
SILArgumentConvention::isGuaranteedConvention

These changes will be needed when we add a new convention for
non-trivial C++ types as the functions will return different answers
depending on whether they are called for the caller or the callee. This
commit doesn't change any functionality.
This commit is contained in:
Akira Hatanaka
2024-06-18 09:06:09 -07:00
committed by GitHub
parent 13bf2ec540
commit d92f181ace
35 changed files with 136 additions and 90 deletions

View File

@@ -2010,7 +2010,7 @@ private:
auto convention = innerSlot.getConvention();
assert(!isPackParameter(convention));
assert(innerSlot.shouldProduceAddress(SGF) == innerValue.getType().isAddress());
if (innerValue.hasCleanup() && !isConsumedParameter(convention)) {
if (innerValue.hasCleanup() && !isConsumedParameterInCaller(convention)) {
return innerValue.borrow(SGF, Loc);
}
return innerValue;
@@ -2047,7 +2047,7 @@ private:
// Easy case: we want to pass exactly this value.
if (outer.getType() == innerParam.getType()) {
if (isConsumedParameter(innerParam.getConvention()) &&
if (isConsumedParameterInCaller(innerParam.getConvention()) &&
!outer.isPlusOne(SGF)) {
outer = outer.copyUnmanaged(SGF, Loc);
}
@@ -2792,12 +2792,12 @@ static void forwardFunctionArguments(SILGenFunction &SGF,
arg = applyTrivialConversions(SGF, loc, arg,
SILType::getPrimitiveObjectType(argSubstTy));
if (argTy.isConsumed()) {
if (argTy.isConsumedInCaller()) {
forwardedArgs.push_back(arg.ensurePlusOne(SGF, loc).forward(SGF));
continue;
}
if (isGuaranteedParameter(argTy.getConvention())) {
if (isGuaranteedParameterInCallee(argTy.getConvention())) {
forwardedArgs.push_back(
SGF.emitManagedBeginBorrow(loc, arg.getValue()).getValue());
continue;
@@ -3932,7 +3932,7 @@ ManagedValue TranslateArguments::expandPackExpansion(
// Note that we need to force *trivial* packs/tuples to be copied, in
// case the inner context wants to mutate the memory, even though we might
// have ownership of that memory (e.g. if it's a consuming parameter).
needsInnerTemporary = (isConsumedParameter(innerConvention) &&
needsInnerTemporary = (isConsumedParameterInCaller(innerConvention) &&
!outerTupleOrPackMV.isPlusOne(SGF));
}
@@ -3960,7 +3960,7 @@ ManagedValue TranslateArguments::expandPackExpansion(
// This doesn't apply if we're translating into a tuple because we
// always need to copy/move into the tuple.
if (!innerIsTuple && !needsInnerTemporary &&
!isConsumedParameter(innerConvention)) {
!isConsumedParameterInCaller(innerConvention)) {
outerTupleOrPackMV =
ManagedValue::forBorrowedAddressRValue(outerTupleOrPackMV.getValue());
}
@@ -3970,7 +3970,7 @@ ManagedValue TranslateArguments::expandPackExpansion(
SILValue outerTupleOrPackAddr = outerTupleOrPackMV.forward(SGF);
bool innerIsOwned = (innerIsTuple || needsInnerTemporary ||
isConsumedParameter(innerConvention));
isConsumedParameterInCaller(innerConvention));
// Perform a pack loop to translate the components and set the element
// addresses for this pack expansion in the inner pack (if it's a pack).
@@ -4085,7 +4085,7 @@ ManagedValue TranslateArguments::expandPackExpansion(
// We only associate this cleanup with what we return from this function
// if we're generating an owned value; otherwise we just leave it active
// so that we destroy the values later.
if (isConsumedParameter(innerConvention)) {
if (isConsumedParameterInCaller(innerConvention)) {
return ManagedValue::forOwnedAddressRValue(innerTupleOrPackAddr,
innerExpansionCleanup);
}