Skip to content

Commit dbd66d8

Browse files
committed
[ownership] Change BorrowingOperand to no longer be convertable to Operand * and provide a conversion to bool instead.
A few notes: 1. We already have provide an operator* that does this and even better makes the conversion explicit in the source. 2. The bool operator checks both that kind is not invalid and that the operand is non-null. This ensures we can use an `if` to properly check for a valid BorrowingOperand.
1 parent c32df33 commit dbd66d8

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

include/swift/SIL/OwnershipUtils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,13 @@ struct BorrowingOperand {
189189

190190
// A set of operators so that a BorrowingOperand can be used like a normal
191191
// operand in a light weight way.
192-
operator const Operand *() const { return op; }
193-
operator Operand *() { return op; }
194192
const Operand *operator*() const { return op; }
195193
Operand *operator*() { return op; }
196194
const Operand *operator->() const { return op; }
197195
Operand *operator->() { return op; }
198196

197+
operator bool() const { return kind != BorrowingOperandKind::Invalid && op; }
198+
199199
/// If \p op is a borrow introducing operand return it after doing some
200200
/// checks.
201201
static BorrowingOperand get(Operand *op) {

lib/SILOptimizer/Utils/OwnershipOptUtils.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ static void eliminateReborrowsOfRecursiveBorrows(
546546
// Then check if in our destination block, we have further reborrows. If we
547547
// do, we need to recursively process them.
548548
auto *borrowedArg =
549-
const_cast<SILPhiArgument *>(bi->getArgForOperand(borrowingOperand));
549+
const_cast<SILPhiArgument *>(bi->getArgForOperand(*borrowingOperand));
550550
auto *baseArg =
551551
insertOwnedBaseValueAlongBranchEdge(bi, innerCopy, callbacks);
552552
baseBorrowedValuePair.emplace_back(baseArg, borrowedArg);
@@ -574,7 +574,7 @@ static void eliminateReborrowsOfRecursiveBorrows(
574574
// edge and undef along all other edges.
575575
auto borrowingOp = BorrowingOperand::get(use);
576576
auto *brInst = cast<BranchInst>(borrowingOp.op->getUser());
577-
auto *newBorrowedPhi = brInst->getArgForOperand(borrowingOp);
577+
auto *newBorrowedPhi = brInst->getArgForOperand(*borrowingOp);
578578
auto *newBasePhi =
579579
insertOwnedBaseValueAlongBranchEdge(brInst, baseArg, callbacks);
580580
baseBorrowedValuePair.emplace_back(newBasePhi, newBorrowedPhi);
@@ -639,7 +639,7 @@ rewriteReborrows(SILValue newBorrowedValue,
639639
// edge and undef along all other edges.
640640
auto borrowingOp = BorrowingOperand::get(use);
641641
auto *brInst = cast<BranchInst>(borrowingOp.op->getUser());
642-
auto *newBorrowedPhi = brInst->getArgForOperand(borrowingOp);
642+
auto *newBorrowedPhi = brInst->getArgForOperand(*borrowingOp);
643643
auto *newBasePhi =
644644
insertOwnedBaseValueAlongBranchEdge(brInst, baseArg, callbacks);
645645
baseBorrowedValuePair.emplace_back(newBasePhi, newBorrowedPhi);

0 commit comments

Comments
 (0)