Skip to content

Commit 5095bd3

Browse files
committed
[silgen] Convert a few instances of ManagedValue::forUnmanaged(*).copy() -> ManagedValue::forCopyOwnedObjectRValue.
Just removing more ManagedValue::forUnmanaged.
1 parent 85e38af commit 5095bd3

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

lib/SILGen/ManagedValue.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,24 @@ class ManagedValue {
9292
return ManagedValue(value, false, CleanupHandle::invalid());
9393
}
9494

95+
enum class ScopeKind {
96+
Lexical,
97+
FormalAccess,
98+
};
99+
100+
/// Given a value \p value, create a copy of it and return the relevant
101+
/// ManagedValue.
102+
static ManagedValue forCopyOwnedObjectRValue(SILGenFunction &SGF,
103+
SILLocation loc, SILValue value,
104+
ScopeKind kind) {
105+
assert(value && "No value specified");
106+
assert(value->getType().isObject());
107+
auto mv = ManagedValue::forUnmanaged(value);
108+
if (kind == ScopeKind::Lexical)
109+
return mv.copy(SGF, loc);
110+
return mv.formalAccessCopy(SGF, loc);
111+
}
112+
95113
/// Create a managed value for a SILValue whose ownership is
96114
/// forwarded. Creates a new cleanup for +1 values. Forwarded +0 values
97115
/// require no cleanup.

lib/SILGen/ResultPlan.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -899,8 +899,9 @@ class ForeignAsyncInitializationPlan final : public ResultPlan {
899899
SILValue(wrappedContinuation));
900900
SGF.emitApplyOfLibraryIntrinsic(
901901
loc, errorIntrinsic, subs,
902-
{continuationMV,
903-
ManagedValue::forUnmanaged(bridgedForeignError).copy(SGF, loc)},
902+
{continuationMV, ManagedValue::forCopyOwnedObjectRValue(
903+
SGF, loc, bridgedForeignError,
904+
ManagedValue::ScopeKind::Lexical)},
904905
SGFContext());
905906

906907
// Second, emit a branch from the end of the foreign error block to the

lib/SILGen/SILGenBuilder.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,8 @@ static ManagedValue createInputFunctionArgument(
525525
//
526526
// NOTE: If we have a trivial value, the copy will do nothing, so this is
527527
// just a convenient way to avoid writing conditional code.
528-
return ManagedValue::forUnmanaged(arg).copy(SGF, loc);
528+
return ManagedValue::forCopyOwnedObjectRValue(
529+
SGF, loc, arg, ManagedValue::ScopeKind::Lexical);
529530

530531
case SILArgumentConvention::Direct_Owned:
531532
return SGF.emitManagedRValueWithCleanup(arg);
@@ -712,7 +713,8 @@ ManagedValue SILGenBuilder::createUncheckedBitCast(SILLocation loc,
712713
// identity implying that we need a copy of the casted value to be returned so
713714
// that the inputs/outputs of the case have separate ownership.
714715
if (isa<UncheckedBitwiseCastInst>(cast)) {
715-
return ManagedValue::forUnmanaged(cast).copy(SGF, loc);
716+
return ManagedValue::forCopyOwnedObjectRValue(
717+
SGF, loc, cast, ManagedValue::ScopeKind::Lexical);
716718
}
717719

718720
// Otherwise, we forward the cleanup of the input value and place the cleanup

0 commit comments

Comments
 (0)