Skip to content

Commit ea7b805

Browse files
committed
Rewrite some isPlusOne calls to isPlusOneOrTrivial.
Whenever we want to forward to a +1 value but don't need to destroy the original memory, use isPlusOneOrTrivial. This follows the existing naming scheme. Fixes rdar://108001491 (SIL verification failed: Found mutating or consuming use of an in_guaranteed parameter?!: !ImmutableAddressUseVerifier().isMutatingOrConsuming(fArg))
1 parent dc95b11 commit ea7b805

File tree

9 files changed

+24
-21
lines changed

9 files changed

+24
-21
lines changed

lib/SILGen/ManagedValue.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,22 +155,22 @@ SILValue ManagedValue::forward(SILGenFunction &SGF) const {
155155

156156
void ManagedValue::forwardInto(SILGenFunction &SGF, SILLocation loc,
157157
SILValue address) {
158-
assert(isPlusOne(SGF));
158+
assert(isPlusOneOrTrivial(SGF));
159159
auto &addrTL = SGF.getTypeLowering(address->getType());
160160
SGF.emitSemanticStore(loc, forward(SGF), address, addrTL, IsInitialization);
161161
}
162162

163163
void ManagedValue::assignInto(SILGenFunction &SGF, SILLocation loc,
164164
SILValue address) {
165-
assert(isPlusOne(SGF));
165+
assert(isPlusOneOrTrivial(SGF));
166166
auto &addrTL = SGF.getTypeLowering(address->getType());
167167
SGF.emitSemanticStore(loc, forward(SGF), address, addrTL,
168168
IsNotInitialization);
169169
}
170170

171171
void ManagedValue::forwardInto(SILGenFunction &SGF, SILLocation loc,
172172
Initialization *dest) {
173-
assert(isPlusOne(SGF));
173+
assert(isPlusOneOrTrivial(SGF));
174174
dest->copyOrInitValueInto(SGF, loc, *this, /*isInit*/ true);
175175
dest->finishInitialization(SGF);
176176
}
@@ -281,7 +281,7 @@ ManagedValue ManagedValue::ensurePlusOne(SILGenFunction &SGF,
281281
if (isa<SILUndef>(getValue()))
282282
return *this;
283283

284-
if (!isPlusOne(SGF)) {
284+
if (!isPlusOneOrTrivial(SGF)) {
285285
return copy(SGF, loc);
286286
}
287287
return *this;

lib/SILGen/RValue.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ SILValue RValue::forwardAsSingleStorageValue(SILGenFunction &SGF,
550550
void RValue::forwardInto(SILGenFunction &SGF, SILLocation loc,
551551
Initialization *I) && {
552552
assert(isComplete() && "rvalue is not complete");
553-
assert(isPlusOne(SGF) && "Can not forward borrowed RValues");
553+
assert(isPlusOneOrTrivial(SGF) && "Can not forward borrowed RValues");
554554
ArrayRef<ManagedValue> elts = values;
555555
copyOrInitValuesInto<ImplodeKind::Forward>(I, elts, type, loc, SGF);
556556
}
@@ -588,7 +588,7 @@ static void assignRecursive(SILGenFunction &SGF, SILLocation loc,
588588
void RValue::assignInto(SILGenFunction &SGF, SILLocation loc,
589589
SILValue destAddr) && {
590590
assert(isComplete() && "rvalue is not complete");
591-
assert(isPlusOne(SGF) && "Can not assign borrowed RValues");
591+
assert(isPlusOneOrTrivial(SGF) && "Can not assign borrowed RValues");
592592
ArrayRef<ManagedValue> srcValues = values;
593593
assignRecursive(SGF, loc, type, srcValues, destAddr);
594594
assert(srcValues.empty() && "didn't claim all elements!");
@@ -734,7 +734,7 @@ RValue RValue::copy(SILGenFunction &SGF, SILLocation loc) const & {
734734
}
735735

736736
RValue RValue::ensurePlusOne(SILGenFunction &SGF, SILLocation loc) && {
737-
if (!isPlusOne(SGF))
737+
if (!isPlusOneOrTrivial(SGF))
738738
return copy(SGF, loc);
739739
return std::move(*this);
740740
}
@@ -751,7 +751,8 @@ RValue RValue::borrow(SILGenFunction &SGF, SILLocation loc) const & {
751751
}
752752

753753
ManagedValue RValue::materialize(SILGenFunction &SGF, SILLocation loc) && {
754-
assert(isPlusOne(SGF) && "Can not materialize a non-plus one RValue");
754+
assert(isPlusOneOrTrivial(SGF) &&
755+
"Can not materialize a non-plus one RValue");
755756
auto &paramTL = SGF.getTypeLowering(getType());
756757

757758
// If we're already materialized, we're done.

lib/SILGen/SILGenConvert.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ ManagedValue SILGenFunction::manageOpaqueValue(ManagedValue value,
999999
SGFContext C) {
10001000
// If the opaque value is consumable, we can just return the
10011001
// value with a cleanup. There is no need to retain it separately.
1002-
if (value.isPlusOne(*this))
1002+
if (value.isPlusOneOrTrivial(*this))
10031003
return value;
10041004

10051005
// If the context wants a +0 value, guaranteed or immediate, we can

lib/SILGen/SILGenDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ void TupleInitialization::copyOrInitValueInto(SILGenFunction &SGF,
145145
// In the address case, we forward the underlying value and store it
146146
// into memory and then create a +1 cleanup. since we assume here
147147
// that we have a +1 value since we are forwarding into memory.
148-
assert(value.isPlusOne(SGF) && "Can not store a +0 value into memory?!");
148+
assert(value.isPlusOneOrTrivial(SGF) &&
149+
"Can not store a +0 value into memory?!");
149150
CleanupCloner cloner(SGF, value);
150151
SILValue v = value.forward(SGF);
151152

lib/SILGen/SILGenLValue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4679,7 +4679,7 @@ RValue SILGenFunction::emitLoadOfLValue(SILLocation loc, LValue &&src,
46794679
emitLoad(loc, projection.getValue(), origFormalType,
46804680
substFormalType, rvalueTL, C, IsNotTake, isBaseGuaranteed);
46814681
} else if (isReadAccessResultOwned(src.getAccessKind()) &&
4682-
!projection.isPlusOne(*this)) {
4682+
!projection.isPlusOneOrTrivial(*this)) {
46834683

46844684
// Before we copy, if we have a move only wrapped value, unwrap the
46854685
// value using a guaranteed moveonlywrapper_to_copyable.

lib/SILGen/SILGenPack.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -860,14 +860,14 @@ SILGenFunction::emitPackTransform(SILLocation loc,
860860
CanPackType outputFormalPackType,
861861
unsigned outputComponentIndex,
862862
bool isSimpleProjection,
863-
bool outputIsPlusOne,
863+
bool canForwardOutput,
864864
llvm::function_ref<ManagedValue(ManagedValue input,
865865
SILType outputEltTy,
866866
SGFContext context)> emitBody) {
867867

868868
// This is an inherent limitation of the representation; we need pack
869869
// coroutines to get around it.
870-
assert((isSimpleProjection || outputIsPlusOne) &&
870+
assert((isSimpleProjection || canForwardOutput) &&
871871
"we cannot support complex transformations that yield borrows");
872872

873873
CleanupCloner inputCloner(*this, inputPackMV);
@@ -890,7 +890,7 @@ SILGenFunction::emitPackTransform(SILLocation loc,
890890
{&inputEltTy, &outputEltTy});
891891

892892
auto &outputEltTL = getTypeLowering(outputEltTy);
893-
bool outputNeedsCleanup = (outputIsPlusOne && !outputEltTL.isTrivial());
893+
bool outputNeedsCleanup = (canForwardOutput && !outputEltTL.isTrivial());
894894

895895
// If the transformation is not a simple projection, we need to
896896
// create a tuple to hold the transformed values.
@@ -947,10 +947,10 @@ SILGenFunction::emitPackTransform(SILLocation loc,
947947
// Apply the transform.
948948
ManagedValue outputElt =
949949
emitBody(inputElt, outputEltTy,
950-
outputIsPlusOne ? SGFContext(outputEltInit.get())
950+
canForwardOutput ? SGFContext(outputEltInit.get())
951951
: SGFContext::AllowGuaranteedPlusZero);
952-
assert(outputIsPlusOne == (outputElt.isInContext() ||
953-
outputElt.isPlusOne(*this)) &&
952+
assert(canForwardOutput == (outputElt.isInContext() ||
953+
outputElt.isPlusOneOrTrivial(*this)) &&
954954
"transformation produced a value of the wrong ownership");
955955
assert((outputElt.isInContext() ||
956956
outputElt.getType() == outputEltTy) &&
@@ -991,7 +991,7 @@ SILGenFunction::emitPackTransform(SILLocation loc,
991991
outputComponentIndex,
992992
/*limit*/ SILValue());
993993
return ManagedValue::forOwnedAddressRValue(outputPackAddr, cleanup);
994-
} else if (outputIsPlusOne) {
994+
} else if (canForwardOutput) {
995995
return ManagedValue::forTrivialAddressRValue(outputPackAddr);
996996
} else {
997997
return ManagedValue::forBorrowedAddressRValue(outputPackAddr);

lib/SILGen/SILGenPattern.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1679,7 +1679,7 @@ emitCastOperand(SILGenFunction &SGF, SILLocation loc,
16791679
finalValue =
16801680
SGF.emitSubstToOrigValue(loc, finalValue, abstraction, sourceType, ctx);
16811681
}
1682-
assert(finalValue.isPlusOne(SGF));
1682+
assert(finalValue.isPlusOneOrTrivial(SGF));
16831683

16841684
// If we at this point do not require an address, return final value. We know
16851685
// that it is a +1 take always value.

lib/SILGen/SILGenProlog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ class EmitBBArguments : public CanTypeVisitor<EmitBBArguments,
295295
}
296296

297297
if (emitInto) {
298-
if (mv.isPlusOne(SGF))
298+
if (mv.isPlusOneOrTrivial(SGF))
299299
mv.forwardInto(SGF, loc, emitInto);
300300
else
301301
mv.copyInto(SGF, loc, emitInto);

lib/SILGen/Scope.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ static void lifetimeExtendAddressOnlyRValueSubValues(
7777

7878
RValue Scope::popPreservingValue(RValue &&rv) {
7979
auto &SGF = cleanups.SGF;
80-
assert(rv.isPlusOne(SGF) && "Can only push plus one rvalues through a scope");
80+
assert(rv.isPlusOneOrTrivial(SGF) &&
81+
"Can only push plus one rvalues through a scope");
8182

8283
// Perform a quick check if we have an incontext value. If so, just pop and
8384
// return rv.

0 commit comments

Comments
 (0)