Skip to content

Commit cece84f

Browse files
committed
[silgen] Rename forTrivialRValue -> forRValueWithoutOwnership and use it in a few places to eliminate more forUnmanaged.
With this commit, we have now eliminated ~55% of all forUnmanaged in the code base.
1 parent 2faa819 commit cece84f

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

lib/SILGen/ManagedValue.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,9 @@ class ManagedValue {
196196
return ManagedValue(value, false, CleanupHandle::invalid());
197197
}
198198

199-
/// Create a managed value for a +0 trivial rvalue.
200-
static ManagedValue forTrivialRValue(SILValue value) {
199+
/// Create a managed value for a trivial address rvalue or an object rvalue
200+
/// that has .none ownership.
201+
static ManagedValue forRValueWithoutOwnership(SILValue value) {
201202
if (value->getType().isObject())
202203
return ManagedValue::forObjectRValueWithoutOwnership(value);
203204
return ManagedValue::forTrivialAddressRValue(value);

lib/SILGen/SILGenApply.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4915,14 +4915,14 @@ SILGenFunction::emitBeginApply(SILLocation loc, ManagedValue fn,
49154915
yields.push_back(ManagedValue::forLValue(value));
49164916
} else if (info.isConsumed()) {
49174917
!useLoweredAddresses && value->getType().isTrivial(getFunction())
4918-
? yields.push_back(ManagedValue::forTrivialRValue(value))
4918+
? yields.push_back(ManagedValue::forRValueWithoutOwnership(value))
49194919
: yields.push_back(emitManagedRValueWithCleanup(value));
49204920
} else if (info.isGuaranteed()) {
49214921
!useLoweredAddresses && value->getType().isTrivial(getFunction())
4922-
? yields.push_back(ManagedValue::forTrivialRValue(value))
4922+
? yields.push_back(ManagedValue::forRValueWithoutOwnership(value))
49234923
: yields.push_back(ManagedValue::forBorrowedRValue(value));
49244924
} else {
4925-
yields.push_back(ManagedValue::forTrivialRValue(value));
4925+
yields.push_back(ManagedValue::forRValueWithoutOwnership(value));
49264926
}
49274927
}
49284928

lib/SILGen/SILGenBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ ManagedValue SILGenBuilder::createOpenExistentialMetatype(SILLocation loc,
764764
SILType openedType) {
765765
SILValue result = SILGenBuilder::createOpenExistentialMetatype(
766766
loc, value.getValue(), openedType);
767-
return ManagedValue::forTrivialRValue(result);
767+
return ManagedValue::forRValueWithoutOwnership(result);
768768
}
769769

770770
ManagedValue SILGenBuilder::createStore(SILLocation loc, ManagedValue value,

lib/SILGen/SILGenExpr.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,10 @@ SILGenFunction::emitManagedBeginBorrow(SILLocation loc, SILValue v,
152152
assert(lowering.getLoweredType().getObjectType() ==
153153
v->getType().getObjectType());
154154
if (lowering.isTrivial())
155-
return ManagedValue::forUnmanaged(v);
155+
return ManagedValue::forRValueWithoutOwnership(v);
156156

157157
if (v->getOwnershipKind() == OwnershipKind::None)
158-
return ManagedValue::forUnmanaged(v);
158+
return ManagedValue::forRValueWithoutOwnership(v);
159159

160160
if (v->getOwnershipKind() == OwnershipKind::Guaranteed)
161161
return ManagedValue::forUnmanaged(v);
@@ -2867,7 +2867,7 @@ emitKeyPathRValueBase(SILGenFunction &subSGF,
28672867
return ManagedValue();
28682868

28692869
auto paramOrigValue = paramArg->getType().isTrivial(subSGF.F)
2870-
? ManagedValue::forTrivialRValue(paramArg)
2870+
? ManagedValue::forRValueWithoutOwnership(paramArg)
28712871
: ManagedValue::forBorrowedRValue(paramArg);
28722872
paramOrigValue = paramOrigValue.copy(subSGF, loc);
28732873
auto paramSubstValue = subSGF.emitOrigToSubstValue(loc, paramOrigValue,
@@ -3273,7 +3273,7 @@ static SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
32733273
indexes, indexPtrArg);
32743274

32753275
auto valueOrig = valueArgTy.isTrivial(subSGF.F)
3276-
? ManagedValue::forTrivialRValue(valueArg)
3276+
? ManagedValue::forRValueWithoutOwnership(valueArg)
32773277
: ManagedValue::forBorrowedRValue(valueArg);
32783278
valueOrig = valueOrig.copy(subSGF, loc);
32793279
auto valueSubst = subSGF.emitOrigToSubstValue(loc, valueOrig,

0 commit comments

Comments
 (0)