Skip to content

Commit 19b8dde

Browse files
committed
Rename ForwardingBorrow -> GuaranteedForwarding
1 parent 36c01e8 commit 19b8dde

12 files changed

+46
-45
lines changed

include/swift/SIL/OwnershipUtils.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,19 @@ struct BorrowedValue;
7373
/// values?
7474
///
7575
/// This may be true even if the current instance of the instruction is not a
76-
/// ForwardingBorrow. If true, then the operation may be trivially rewritten
76+
/// GuaranteedForwarding. If true, then the operation may be trivially rewritten
7777
/// with Guaranteed ownership.
7878
bool canOpcodeForwardGuaranteedValues(SILValue value);
7979

8080
/// Is the opcode that consumes \p use capable of forwarding guaranteed values?
8181
///
82-
/// This may be true even if \p use is not a ForwardingBorrow. If true, then the
83-
/// operation may be trivially rewritten with Guaranteed ownership.
82+
/// This may be true even if \p use is not a GuaranteedForwarding. If true, then
83+
/// the operation may be trivially rewritten with Guaranteed ownership.
8484
bool canOpcodeForwardGuaranteedValues(Operand *use);
8585

8686
// This is the use-def equivalent of use->getOperandOwnership() ==
87-
// OperandOwnership::ForwardingBorrow.
88-
inline bool isForwardingBorrow(SILValue value) {
87+
// OperandOwnership::GuaranteedForwarding.
88+
inline bool isGuaranteedForwarding(SILValue value) {
8989
assert(value->getOwnershipKind() == OwnershipKind::Guaranteed);
9090
return canOpcodeForwardGuaranteedValues(value);
9191
}

include/swift/SIL/SILValue.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ struct OperandOwnership {
828828
/// Forwarded Borrow. Propagates the guaranteed value within the base's
829829
/// borrow scope.
830830
/// (tuple_extract, struct_extract, cast, switch)
831-
ForwardingBorrow,
831+
GuaranteedForwarding,
832832
/// End Borrow. End the borrow scope opened directly by the operand.
833833
/// The operand must be a begin_borrow, begin_apply, or function argument.
834834
/// (end_borrow, end_apply)
@@ -882,10 +882,11 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
882882
///
883883
/// Forwarding instructions that produce Owned or Guaranteed values always
884884
/// forward an operand of the same ownership kind. Each case has a distinct
885-
/// OperandOwnership (ForwardingConsume and ForwardingBorrow), which enforces a
886-
/// specific constraint on the operand's ownership. Forwarding instructions that
887-
/// produce an Unowned value, however, may forward an operand of any
888-
/// ownership. Therefore, ForwardingUnowned is mapped to OwnershipKind::Any.
885+
/// OperandOwnership (ForwardingConsume and GuaranteedForwarding), which
886+
/// enforces a specific constraint on the operand's ownership. Forwarding
887+
/// instructions that produce an Unowned value, however, may forward an operand
888+
/// of any ownership. Therefore, ForwardingUnowned is mapped to
889+
/// OwnershipKind::Any.
889890
///
890891
/// This design yields the following advantages:
891892
///
@@ -919,7 +920,7 @@ inline OwnershipConstraint OperandOwnership::getOwnershipConstraint() {
919920
case OperandOwnership::ForwardingConsume:
920921
return {OwnershipKind::Owned, UseLifetimeConstraint::LifetimeEnding};
921922
case OperandOwnership::InteriorPointer:
922-
case OperandOwnership::ForwardingBorrow:
923+
case OperandOwnership::GuaranteedForwarding:
923924
return {OwnershipKind::Guaranteed,
924925
UseLifetimeConstraint::NonLifetimeEnding};
925926
case OperandOwnership::EndBorrow:
@@ -947,7 +948,7 @@ inline bool canAcceptUnownedValue(OperandOwnership operandOwnership) {
947948
case OperandOwnership::DestroyingConsume:
948949
case OperandOwnership::ForwardingConsume:
949950
case OperandOwnership::InteriorPointer:
950-
case OperandOwnership::ForwardingBorrow:
951+
case OperandOwnership::GuaranteedForwarding:
951952
case OperandOwnership::EndBorrow:
952953
case OperandOwnership::Reborrow:
953954
return false;
@@ -986,7 +987,7 @@ ValueOwnershipKind::getForwardingOperandOwnership(bool allowUnowned) const {
986987
case OwnershipKind::None:
987988
return OperandOwnership::TrivialUse;
988989
case OwnershipKind::Guaranteed:
989-
return OperandOwnership::ForwardingBorrow;
990+
return OperandOwnership::GuaranteedForwarding;
990991
case OwnershipKind::Owned:
991992
return OperandOwnership::ForwardingConsume;
992993
}

lib/SIL/IR/OperandOwnership.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -297,14 +297,14 @@ OPERAND_OWNERSHIP(InteriorPointer, HopToExecutor)
297297
OPERAND_OWNERSHIP(InteriorPointer, ExtractExecutor)
298298

299299
// Instructions that propagate a value within a borrow scope.
300-
OPERAND_OWNERSHIP(ForwardingBorrow, TupleExtract)
301-
OPERAND_OWNERSHIP(ForwardingBorrow, StructExtract)
302-
OPERAND_OWNERSHIP(ForwardingBorrow, DifferentiableFunctionExtract)
303-
OPERAND_OWNERSHIP(ForwardingBorrow, LinearFunctionExtract)
300+
OPERAND_OWNERSHIP(GuaranteedForwarding, TupleExtract)
301+
OPERAND_OWNERSHIP(GuaranteedForwarding, StructExtract)
302+
OPERAND_OWNERSHIP(GuaranteedForwarding, DifferentiableFunctionExtract)
303+
OPERAND_OWNERSHIP(GuaranteedForwarding, LinearFunctionExtract)
304304
// FIXME: OpenExistential[Box]Value should be able to take owned values too by
305305
// using getForwardingOperandOwnership.
306-
OPERAND_OWNERSHIP(ForwardingBorrow, OpenExistentialValue)
307-
OPERAND_OWNERSHIP(ForwardingBorrow, OpenExistentialBoxValue)
306+
OPERAND_OWNERSHIP(GuaranteedForwarding, OpenExistentialValue)
307+
OPERAND_OWNERSHIP(GuaranteedForwarding, OpenExistentialBoxValue)
308308

309309
OPERAND_OWNERSHIP(EndBorrow, EndBorrow)
310310

@@ -335,7 +335,7 @@ OPERAND_OWNERSHIP(EndBorrow, AbortApply)
335335
#undef OPERAND_OWNERSHIP
336336

337337
// Forwarding operations are conditionally either ForwardingConsumes or
338-
// ForwardingBorrows, depending on the instruction's constant ownership
338+
// GuaranteedForwarding, depending on the instruction's constant ownership
339339
// attribute.
340340
#define FORWARDING_OWNERSHIP(INST) \
341341
OperandOwnership OperandOwnershipClassifier::visit##INST##Inst( \
@@ -376,7 +376,7 @@ FORWARDING_ANY_OWNERSHIP(CheckedCastBranch)
376376
// the meet of its operands' ownership. A destructured member has the same
377377
// ownership as its aggregate unless its type gives it None ownership.
378378
//
379-
// TODO: Aggregate operations should be Reborrows, not ForwardingBorrows,
379+
// TODO: Aggregate operations should be Reborrows, not GuaranteedForwarding,
380380
// because the borrowed value is different on either side of the operation and
381381
// the lifetimes of borrowed members could differ.
382382
#define AGGREGATE_OWNERSHIP(INST) \
@@ -422,15 +422,15 @@ OperandOwnershipClassifier::visitSelectEnumInst(SelectEnumInst *i) {
422422
OperandOwnership
423423
OperandOwnershipClassifier::visitSelectValueInst(SelectValueInst *i) {
424424
if (getValue() == i->getDefaultResult())
425-
return OperandOwnership::ForwardingBorrow;
425+
return OperandOwnership::GuaranteedForwarding;
426426

427427
for (unsigned idx = 0, endIdx = i->getNumCases(); idx < endIdx; ++idx) {
428428
SILValue casevalue;
429429
SILValue result;
430430
std::tie(casevalue, result) = i->getCase(idx);
431431

432432
if (getValue() == casevalue) {
433-
return OperandOwnership::ForwardingBorrow;
433+
return OperandOwnership::GuaranteedForwarding;
434434
}
435435
}
436436
return OperandOwnership::TrivialUse;

lib/SIL/IR/SILValue.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,8 @@ StringRef OperandOwnership::asString() const {
430430
return "forwarding-consume";
431431
case OperandOwnership::InteriorPointer:
432432
return "interior-pointer";
433-
case OperandOwnership::ForwardingBorrow:
434-
return "forwarding-borrow";
433+
case OperandOwnership::GuaranteedForwarding:
434+
return "guaranteed-forwarding";
435435
case OperandOwnership::EndBorrow:
436436
return "end-borrow";
437437
case OperandOwnership::Reborrow:

lib/SIL/Utils/OwnershipUtils.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ bool swift::hasPointerEscape(BorrowedValue value) {
6464
}
6565
break;
6666
}
67-
case OperandOwnership::ForwardingBorrow: {
67+
case OperandOwnership::GuaranteedForwarding: {
6868
ForwardingOperand(op).visitForwardedValues([&](SILValue result) {
6969
// Do not include transitive uses with 'none' ownership
7070
if (result->getOwnershipKind() == OwnershipKind::None)
@@ -218,7 +218,7 @@ bool swift::findInnerTransitiveGuaranteedUses(
218218
foundPointerEscape = true;
219219
break;
220220

221-
case OperandOwnership::ForwardingBorrow: {
221+
case OperandOwnership::GuaranteedForwarding: {
222222
bool nonLeaf = false;
223223
ForwardingOperand(use).visitForwardedValues([&](SILValue result) {
224224
// Do not include transitive uses with 'none' ownership
@@ -339,7 +339,7 @@ bool swift::findExtendedUsesOfSimpleBorrowedValue(
339339
recordUse(use);
340340
break;
341341

342-
case OperandOwnership::ForwardingBorrow: {
342+
case OperandOwnership::GuaranteedForwarding: {
343343
ForwardingOperand(use).visitForwardedValues([&](SILValue result) {
344344
// Do not include transitive uses with 'none' ownership
345345
if (result->getOwnershipKind() == OwnershipKind::None)
@@ -1181,7 +1181,7 @@ bool swift::getAllBorrowIntroducingValues(SILValue inputValue,
11811181

11821182
// Otherwise if v is an ownership forwarding value, add its defining
11831183
// instruction
1184-
if (isForwardingBorrow(value)) {
1184+
if (isGuaranteedForwarding(value)) {
11851185
if (auto *i = value->getDefiningInstruction()) {
11861186
llvm::copy(i->getNonTypeDependentOperandValues(),
11871187
std::back_inserter(worklist));
@@ -1226,7 +1226,7 @@ BorrowedValue swift::getSingleBorrowIntroducingValue(SILValue inputValue) {
12261226

12271227
// Otherwise if v is an ownership forwarding value, add its defining
12281228
// instruction
1229-
if (isForwardingBorrow(currentValue)) {
1229+
if (isGuaranteedForwarding(currentValue)) {
12301230
if (auto *i = currentValue->getDefiningInstruction()) {
12311231
auto instOps = i->getNonTypeDependentOperandValues();
12321232
// If we have multiple incoming values, return .None. We can't handle
@@ -1377,7 +1377,7 @@ ForwardingOperand::ForwardingOperand(Operand *use) {
13771377
switch (use->getOperandOwnership()) {
13781378
case OperandOwnership::ForwardingUnowned:
13791379
case OperandOwnership::ForwardingConsume:
1380-
case OperandOwnership::ForwardingBorrow:
1380+
case OperandOwnership::GuaranteedForwarding:
13811381
break;
13821382
case OperandOwnership::NonUse:
13831383
case OperandOwnership::TrivialUse:

lib/SIL/Utils/PrunedLiveness.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ SimpleLiveRangeSummary PrunedLiveRange<LivenessWithDefs>::updateForDef(SILValue
295295
case OperandOwnership::InteriorPointer:
296296
summary.meet(checkAndUpdateInteriorPointer(use));
297297
break;
298-
case OperandOwnership::ForwardingBorrow: {
298+
case OperandOwnership::GuaranteedForwarding: {
299299
ForwardingOperand(use).visitForwardedValues([&](SILValue result) {
300300
// Do not include transitive uses with 'none' ownership
301301
if (result->getOwnershipKind() != OwnershipKind::None) {

lib/SIL/Verifier/SILOwnershipVerifier.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ bool SILValueOwnershipChecker::gatherUsers(
286286
// this value forwards guaranteed ownership. In such a case, we are going to
287287
// validate it as part of the borrow introducer from which the forwarding
288288
// value originates. So we can just return true and continue.
289-
if (isForwardingBorrow(value))
289+
if (isGuaranteedForwarding(value))
290290
return true;
291291

292292
// Ok, we have some sort of borrow introducer. We need to recursively validate
@@ -322,7 +322,7 @@ bool SILValueOwnershipChecker::gatherUsers(
322322
// Example: A guaranteed parameter of a co-routine.
323323

324324
// Now check if we have a non guaranteed forwarding inst...
325-
if (op->getOperandOwnership() != OperandOwnership::ForwardingBorrow) {
325+
if (op->getOperandOwnership() != OperandOwnership::GuaranteedForwarding) {
326326
// First check if we are visiting an operand that is a consuming use...
327327
if (op->isLifetimeEnding()) {
328328
// If its underlying value is our original value, then this is a true
@@ -563,7 +563,7 @@ bool SILValueOwnershipChecker::checkValueWithoutLifetimeEndingUses(
563563
// have lifetime ending uses, since our lifetime is guaranteed by our
564564
// operand, so there is nothing further to do. So just return true.
565565
if (value->getOwnershipKind() == OwnershipKind::Guaranteed &&
566-
isForwardingBorrow(value))
566+
isGuaranteedForwarding(value))
567567
return true;
568568

569569
// If we have an unowned value, then again there is nothing left to do.
@@ -682,7 +682,7 @@ bool SILValueOwnershipChecker::checkUses() {
682682
// ownership. In such a case, we are a subobject projection. We should not
683683
// have any lifetime ending uses.
684684
if (value->getOwnershipKind() == OwnershipKind::Guaranteed &&
685-
isForwardingBorrow(value)) {
685+
isGuaranteedForwarding(value)) {
686686
if (!isSubobjectProjectionWithLifetimeEndingUses(value,
687687
lifetimeEndingUsers)) {
688688
return false;

lib/SILOptimizer/Mandatory/DiagnoseLifetimeIssues.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ visitUses(SILValue def, bool updateLivenessAndWeakStores, int callDepth) {
214214
if (updateLivenessAndWeakStores)
215215
liveness.updateForUse(user, /*lifetimeEnding*/ false);
216216
break;
217-
case OperandOwnership::ForwardingBorrow:
217+
case OperandOwnership::GuaranteedForwarding:
218218
case OperandOwnership::ForwardingConsume:
219219
// TermInst includes ReturnInst, which is generally an escape.
220220
// If this is called as part of getArgumentState, then it is not really

lib/SILOptimizer/Mandatory/MoveKillsCopyableValuesChecker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ bool CheckerLivenessInfo::compute() {
160160
}
161161
break;
162162
}
163-
case OperandOwnership::ForwardingBorrow:
163+
case OperandOwnership::GuaranteedForwarding:
164164
// A forwarding borrow is validated as part of its parent borrow. So
165165
// just mark it as extending liveness and look through it.
166166
liveness.updateForUse(user, /*lifetimeEnding*/ false);

lib/SILOptimizer/Utils/BasicBlockOptUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ static bool canBorrowGuaranteedResult(SILValue guaranteedResult) {
133133
bool swift::canCloneTerminator(TermInst *termInst) {
134134
// TODO: this is an awkward way to check for guaranteed terminator results.
135135
for (Operand &oper : termInst->getAllOperands()) {
136-
if (oper.getOperandOwnership() != OperandOwnership::ForwardingBorrow)
136+
if (oper.getOperandOwnership() != OperandOwnership::GuaranteedForwarding)
137137
continue;
138138

139139
if (!ForwardingOperand(&oper).visitForwardedValues(

lib/SILOptimizer/Utils/CanonicalizeBorrowScope.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ bool CanonicalizeBorrowScope::isRewritableOSSAForward(SILInstruction *inst) {
9898
if (operOwnership == OperandOwnership::TrivialUse)
9999
return false;
100100
// Don't mess with unowned conversions. They need to be copied immediately.
101-
if (operOwnership != OperandOwnership::ForwardingBorrow
102-
&& operOwnership != OperandOwnership::ForwardingConsume) {
101+
if (operOwnership != OperandOwnership::GuaranteedForwarding &&
102+
operOwnership != OperandOwnership::ForwardingConsume) {
103103
return false;
104104
}
105-
assert(operOwnership == OperandOwnership::ForwardingBorrow
106-
|| operOwnership == OperandOwnership::ForwardingConsume);
105+
assert(operOwnership == OperandOwnership::GuaranteedForwarding ||
106+
operOwnership == OperandOwnership::ForwardingConsume);
107107

108108
// Filter instructions that belong to a Forwarding*ValueInst mixin but
109109
// cannot be converted to forward owned value (struct_extract).
@@ -274,7 +274,7 @@ bool CanonicalizeBorrowScope::visitBorrowScopeUses(SILValue innerValue,
274274
}
275275
break;
276276

277-
case OperandOwnership::ForwardingBorrow:
277+
case OperandOwnership::GuaranteedForwarding:
278278
case OperandOwnership::ForwardingConsume:
279279
if (CanonicalizeBorrowScope::isRewritableOSSAForward(user)) {
280280
if (!visitor.visitForwardingUse(use)) {

lib/SILOptimizer/Utils/CanonicalizeOSSALifetime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ bool CanonicalizeOSSALifetime::computeCanonicalLiveness() {
185185
}
186186
break;
187187
case OperandOwnership::InteriorPointer:
188-
case OperandOwnership::ForwardingBorrow:
188+
case OperandOwnership::GuaranteedForwarding:
189189
case OperandOwnership::EndBorrow:
190190
// Guaranteed values are considered uses of the value when the value is
191191
// an owned phi and the guaranteed values are adjacent reborrow phis or

0 commit comments

Comments
 (0)