Skip to content

Commit 4852aa0

Browse files
committed
silgen: eliminate ManagedValue::copyUnmanaged
There's no material difference between it and `ManagedValue::copy`, i.e., it doesn't actually produce something without a clean-up. SILGen grew a `ManagedValue::unmanagedCopy` for that purpose.
1 parent 5241583 commit 4852aa0

File tree

8 files changed

+14
-37
lines changed

8 files changed

+14
-37
lines changed

lib/SILGen/ManagedValue.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,18 +123,6 @@ void ManagedValue::copyInto(SILGenFunction &SGF, SILLocation loc,
123123
dest->finishInitialization(SGF);
124124
}
125125

126-
/// This is the same operation as 'copy', but works on +0 values that don't
127-
/// have cleanups. It returns a +1 value with one.
128-
ManagedValue ManagedValue::copyUnmanaged(SILGenFunction &SGF, SILLocation loc) {
129-
if (getType().isObject()) {
130-
return SGF.B.createCopyValue(loc, *this);
131-
}
132-
133-
SILValue result = SGF.emitTemporaryAllocation(loc, getType());
134-
SGF.B.createCopyAddr(loc, getValue(), result, IsNotTake, IsInitialization);
135-
return SGF.emitManagedRValueWithCleanup(result);
136-
}
137-
138126
/// This is the same operation as 'copy', but works on +0 values that don't
139127
/// have cleanups. It returns a +1 value with one.
140128
ManagedValue ManagedValue::formalAccessCopyUnmanaged(SILGenFunction &SGF,

lib/SILGen/ManagedValue.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,6 @@ class ManagedValue {
365365
/// formal evaluation scope.
366366
ManagedValue formalAccessCopy(SILGenFunction &SGF, SILLocation loc);
367367

368-
/// This is the same operation as 'copy', but works on +0 values that don't
369-
/// have cleanups. It returns a +1 value with one.
370-
ManagedValue copyUnmanaged(SILGenFunction &SGF, SILLocation loc);
371-
372368
/// This is the same operation as 'formalAccessCopy', but works on +0 values
373369
/// that don't have cleanups. It returns a +1 value with one.
374370
ManagedValue formalAccessCopyUnmanaged(SILGenFunction &SGF, SILLocation loc);

lib/SILGen/SILGenApply.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -272,14 +272,14 @@ static ManagedValue convertOwnershipConventionGivenParamInfo(
272272
if (isOwned && valueType.isMoveOnlyWrapped() &&
273273
valueType.removingMoveOnlyWrapper().isTrivial(SGF.F)) {
274274
if (value.getOwnershipKind() == OwnershipKind::Guaranteed) {
275-
value = value.copyUnmanaged(SGF, loc);
275+
value = value.copy(SGF, loc);
276276
return SGF.B.createOwnedMoveOnlyWrapperToCopyableValue(loc, value);
277277
}
278278
}
279279

280280
if (param.isConsumedInCaller() &&
281281
value.getOwnershipKind() == OwnershipKind::Guaranteed) {
282-
return value.copyUnmanaged(SGF, loc);
282+
return value.copy(SGF, loc);
283283
}
284284

285285
// If we are emitting arguments for a coroutine, we need to borrow owned
@@ -5982,18 +5982,13 @@ RValue SILGenFunction::emitApply(
59825982
case ParameterConvention::Direct_Owned:
59835983
// If the callee will consume the 'self' parameter, let's retain it so we
59845984
// can keep it alive.
5985-
lifetimeExtendedSelf =
5986-
B.emitCopyValueOperation(loc, lifetimeExtendedSelf);
5985+
lifetimeExtendedSelf = selfMV.copy(*this, loc).forward(*this);
59875986
break;
59885987
case ParameterConvention::Direct_Guaranteed:
59895988
case ParameterConvention::Direct_Unowned:
59905989
// We'll manually manage the argument's lifetime after the
59915990
// call. Disable its cleanup, forcing a copy if it was emitted +0.
5992-
if (selfMV.hasCleanup()) {
5993-
selfMV.forwardCleanup(*this);
5994-
} else {
5995-
lifetimeExtendedSelf = selfMV.copyUnmanaged(*this, loc).forward(*this);
5996-
}
5991+
lifetimeExtendedSelf = selfMV.ensurePlusOne(*this, loc).forward(*this);
59975992
break;
59985993

59995994
case ParameterConvention::Indirect_In_Guaranteed:
@@ -7361,7 +7356,7 @@ ArgumentSource AccessorBaseArgPreparer::prepareAccessorObjectBaseArg() {
73617356

73627357
// We need to produce the value at +1 if it's going to be consumed.
73637358
if (selfParam.isConsumedInCaller() && !base.hasCleanup()) {
7364-
base = base.copyUnmanaged(SGF, loc);
7359+
base = base.copy(SGF, loc);
73657360
}
73667361
// If the parameter is indirect, we'll need to drop the value into
73677362
// temporary memory. Make a copy scoped to the current formal access that

lib/SILGen/SILGenConvert.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ ManagedValue SILGenFunction::manageOpaqueValue(ManagedValue value,
10491049
}
10501050

10511051
// Otherwise, copy the value into a temporary.
1052-
return value.copyUnmanaged(*this, loc);
1052+
return value.copy(*this, loc);
10531053
}
10541054

10551055
ManagedValue SILGenFunction::emitAsOrig(SILLocation loc,

lib/SILGen/SILGenDecl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ class LetValueInitialization : public Initialization {
991991
// Disable the expression cleanup of the copy, since the let value
992992
// initialization has a cleanup that lives for the entire scope of the
993993
// let declaration.
994-
bindValue(value.copyUnmanaged(SGF, loc).forward(SGF), SGF, true, loc);
994+
bindValue(value.copy(SGF, loc).forward(SGF), SGF, true, loc);
995995
}
996996
}
997997

@@ -1298,13 +1298,13 @@ void EnumElementPatternInitialization::emitEnumMatch(
12981298
ManagedValue borrowedVal =
12991299
SGF.B.createLoadBorrow(loc, mvAccessAddress);
13001300
mv = loadScope.popPreservingValue(
1301-
borrowedVal.copyUnmanaged(SGF, loc));
1301+
borrowedVal.copy(SGF, loc));
13021302
}
13031303
access.endAccess(SGF);
13041304
} else {
13051305
// If we do not have a loadable value, just do a copy of the
13061306
// boxedValue.
1307-
mv = boxedValue.copyUnmanaged(SGF, loc);
1307+
mv = boxedValue.copy(SGF, loc);
13081308
}
13091309
}
13101310

lib/SILGen/SILGenLValue.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5581,7 +5581,7 @@ RValue SILGenFunction::emitRValueForStorageLoad(
55815581

55825582
// Otherwise, bring the component up to +1 so we can reabstract it.
55835583
result = std::move(loaded).getAsSingleValue(*this, loc)
5584-
.copyUnmanaged(*this, loc);
5584+
.copy(*this, loc);
55855585
} else if (!base.getType().isAddress()) {
55865586
// For non-address-only structs, we emit a struct_extract sequence.
55875587
result = B.createStructExtract(loc, base, field);
@@ -5600,7 +5600,7 @@ RValue SILGenFunction::emitRValueForStorageLoad(
56005600
// guaranteed consumer. Otherwise, since we do not have enough information
56015601
// to know if the base's lifetime last's as long as our use of the access,
56025602
// we can only emit at +0 for immediate clients.
5603-
result = result.copyUnmanaged(*this, loc);
5603+
result = result.copy(*this, loc);
56045604
}
56055605
} else {
56065606
// Create a tiny unenforced access scope around a load from local memory. No

lib/SILGen/SILGenPoly.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2109,7 +2109,7 @@ class TranslateArguments : public ExpanderBase<TranslateArguments, ParamInfo> {
21092109

21102110
// If our inner is guaranteed or unowned, we need to create a copy here.
21112111
if (inner.getOwnershipKind() != OwnershipKind::Owned)
2112-
inner = inner.copyUnmanaged(SGF, Loc);
2112+
inner = inner.copy(SGF, Loc);
21132113

21142114
return inner;
21152115
}
@@ -2190,7 +2190,7 @@ class TranslateArguments : public ExpanderBase<TranslateArguments, ParamInfo> {
21902190
if (outer.getType() == innerParam.getType()) {
21912191
if (isConsumedParameterInCaller(innerParam.getConvention()) &&
21922192
!outer.isPlusOne(SGF)) {
2193-
outer = outer.copyUnmanaged(SGF, Loc);
2193+
outer = outer.copy(SGF, Loc);
21942194
}
21952195

21962196
return outer;

lib/SILGen/SILGenProlog.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -498,9 +498,7 @@ class EmitBBArguments : public CanTypeVisitor<EmitBBArguments,
498498
} else {
499499
// Otherwise, we need to move or copy values into a +1 tuple.
500500
for (auto element : elements) {
501-
SILValue value = element.hasCleanup()
502-
? element.forward(SGF)
503-
: element.copyUnmanaged(SGF, loc).forward(SGF);
501+
SILValue value = element.ensurePlusOne(SGF, loc).forward(SGF);
504502
elementValues.push_back(value);
505503
}
506504
}

0 commit comments

Comments
 (0)