Skip to content

Commit 7dbcdfb

Browse files
committed
[silgen] Rename forTrivialObjectRValue -> forObjectRValueWithoutOwnership.
The reason to do this rename is that this is also used for objects that while non-trivial have .none ownership. Example: enum instance without a case.
1 parent c9be4bd commit 7dbcdfb

File tree

5 files changed

+36
-26
lines changed

5 files changed

+36
-26
lines changed

lib/SILGen/ManagedValue.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ class ManagedValue {
165165
}
166166

167167
/// Create a managed value for a +0 trivial object rvalue.
168-
static ManagedValue forTrivialObjectRValue(SILValue value) {
168+
static ManagedValue forObjectRValueWithoutOwnership(SILValue value) {
169169
assert(value->getType().isObject() && "Expected an object");
170170
assert(value->getOwnershipKind() == OwnershipKind::None);
171171
return ManagedValue(value, false, CleanupHandle::invalid());
@@ -181,7 +181,7 @@ class ManagedValue {
181181
/// Create a managed value for a +0 trivial rvalue.
182182
static ManagedValue forTrivialRValue(SILValue value) {
183183
if (value->getType().isObject())
184-
return ManagedValue::forTrivialObjectRValue(value);
184+
return ManagedValue::forObjectRValueWithoutOwnership(value);
185185
return ManagedValue::forTrivialAddressRValue(value);
186186
}
187187

lib/SILGen/SILGenApply.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6967,11 +6967,12 @@ ManagedValue SILGenFunction::emitReadAsyncLetBinding(SILLocation loc,
69676967

69686968
// The intrinsic returns a pointer to the address of the result value inside
69696969
// the async let task context.
6970-
emitApplyOfLibraryIntrinsic(loc, asyncLetGet, {},
6971-
{ManagedValue::forTrivialObjectRValue(childTask.asyncLet),
6972-
ManagedValue::forTrivialObjectRValue(childTask.resultBuf)},
6973-
SGFContext());
6974-
6970+
emitApplyOfLibraryIntrinsic(
6971+
loc, asyncLetGet, {},
6972+
{ManagedValue::forObjectRValueWithoutOwnership(childTask.asyncLet),
6973+
ManagedValue::forObjectRValueWithoutOwnership(childTask.resultBuf)},
6974+
SGFContext());
6975+
69756976
auto resultAddr = B.createPointerToAddress(loc, childTask.resultBuf,
69766977
loweredOpaquePatternType.getAddressType(),
69776978
/*strict*/ true,
@@ -7054,10 +7055,11 @@ void SILGenFunction::emitFinishAsyncLet(
70547055
SILLocation loc, SILValue asyncLet, SILValue resultPtr) {
70557056
// This runtime function cancels the task, awaits its completion, and
70567057
// destroys the value in the result buffer if necessary.
7057-
emitApplyOfLibraryIntrinsic(loc, SGM.getFinishAsyncLet(), {},
7058-
{ManagedValue::forTrivialObjectRValue(asyncLet),
7059-
ManagedValue::forTrivialObjectRValue(resultPtr)},
7060-
SGFContext());
7058+
emitApplyOfLibraryIntrinsic(
7059+
loc, SGM.getFinishAsyncLet(), {},
7060+
{ManagedValue::forObjectRValueWithoutOwnership(asyncLet),
7061+
ManagedValue::forObjectRValueWithoutOwnership(resultPtr)},
7062+
SGFContext());
70617063
// This builtin ends the lifetime of the allocation for the async let.
70627064
auto &ctx = getASTContext();
70637065
B.createBuiltin(loc,

lib/SILGen/SILGenBuiltin.cpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,12 +1540,16 @@ ManagedValue emitBuiltinCreateAsyncTask(SILGenFunction &SGF, SILLocation loc,
15401540
ProtocolCompositionType::get(ctx, { }, false))->getCanonicalType();
15411541
auto &anyTypeTL = SGF.getTypeLowering(anyTypeType);
15421542
auto &futureResultTL = SGF.getTypeLowering(futureResultType);
1543-
auto futureResultMetadata = SGF.emitExistentialErasure(
1544-
loc, futureResultType, futureResultTL, anyTypeTL, { }, C,
1545-
[&](SGFContext C) -> ManagedValue {
1546-
return ManagedValue::forTrivialObjectRValue(
1547-
SGF.B.createMetatype(loc, SGF.getLoweredType(futureResultType)));
1548-
}).borrow(SGF, loc).forward(SGF);
1543+
auto futureResultMetadata =
1544+
SGF.emitExistentialErasure(
1545+
loc, futureResultType, futureResultTL, anyTypeTL, {}, C,
1546+
[&](SGFContext C) -> ManagedValue {
1547+
return ManagedValue::forObjectRValueWithoutOwnership(
1548+
SGF.B.createMetatype(loc,
1549+
SGF.getLoweredType(futureResultType)));
1550+
})
1551+
.borrow(SGF, loc)
1552+
.forward(SGF);
15491553

15501554
// Ensure that the closure has the appropriate type.
15511555
auto extInfo =
@@ -1598,12 +1602,16 @@ static ManagedValue emitBuiltinCreateAsyncTaskInGroup(
15981602
ProtocolCompositionType::get(ctx, { }, false))->getCanonicalType();
15991603
auto &anyTypeTL = SGF.getTypeLowering(anyTypeType);
16001604
auto &futureResultTL = SGF.getTypeLowering(futureResultType);
1601-
auto futureResultMetadata = SGF.emitExistentialErasure(
1602-
loc, futureResultType, futureResultTL, anyTypeTL, { }, C,
1603-
[&](SGFContext C) -> ManagedValue {
1604-
return ManagedValue::forTrivialObjectRValue(
1605-
SGF.B.createMetatype(loc, SGF.getLoweredType(futureResultType)));
1606-
}).borrow(SGF, loc).forward(SGF);
1605+
auto futureResultMetadata =
1606+
SGF.emitExistentialErasure(
1607+
loc, futureResultType, futureResultTL, anyTypeTL, {}, C,
1608+
[&](SGFContext C) -> ManagedValue {
1609+
return ManagedValue::forObjectRValueWithoutOwnership(
1610+
SGF.B.createMetatype(loc,
1611+
SGF.getLoweredType(futureResultType)));
1612+
})
1613+
.borrow(SGF, loc)
1614+
.forward(SGF);
16071615

16081616
auto function = emitFunctionArgumentForAsyncTaskEntryPoint(SGF, loc, args[2],
16091617
futureResultType);

lib/SILGen/SILGenExpr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5955,7 +5955,7 @@ SILGenFunction::emitArrayToPointer(SILLocation loc, ManagedValue array,
59555955
pointer = B.createMarkDependence(loc, pointer, owner.getValue());
59565956

59575957
// The owner's already in its own cleanup. Return the pointer.
5958-
return {ManagedValue::forTrivialObjectRValue(pointer), owner};
5958+
return {ManagedValue::forObjectRValueWithoutOwnership(pointer), owner};
59595959
}
59605960

59615961
RValue RValueEmitter::visitStringToPointerExpr(StringToPointerExpr *E,
@@ -5989,7 +5989,7 @@ SILGenFunction::emitStringToPointer(SILLocation loc, ManagedValue stringValue,
59895989
auto pointer = results[1].forward(*this);
59905990
pointer = B.createMarkDependence(loc, pointer, owner.getValue());
59915991

5992-
return {ManagedValue::forTrivialObjectRValue(pointer), owner};
5992+
return {ManagedValue::forObjectRValueWithoutOwnership(pointer), owner};
59935993
}
59945994

59955995
RValue RValueEmitter::visitPointerToPointerExpr(PointerToPointerExpr *E,

lib/SILGen/SILGenPoly.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2374,7 +2374,7 @@ static ManagedValue manageYield(SILGenFunction &SGF, SILValue value,
23742374
return ManagedValue::forBorrowedAddressRValue(value);
23752375
}
23762376
if (value->getType().isTrivial(SGF.F)) {
2377-
return ManagedValue::forTrivialObjectRValue(value);
2377+
return ManagedValue::forObjectRValueWithoutOwnership(value);
23782378
}
23792379
return ManagedValue::forBorrowedObjectRValue(value);
23802380
}

0 commit comments

Comments
 (0)