Skip to content

Commit 3f28159

Browse files
authored
Merge pull request #23748 from gottesmm/pr-f44e277b4644313c441523f68d8c2928247e1e26
2 parents 7626ea5 + f2d7dca commit 3f28159

File tree

3 files changed

+24
-25
lines changed

3 files changed

+24
-25
lines changed

include/swift/SIL/OwnershipUtils.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#define SWIFT_SIL_OWNERSHIPUTILS_H
1515

1616
#include "swift/Basic/LLVM.h"
17+
#include "swift/SIL/SILArgument.h"
18+
#include "swift/SIL/SILInstruction.h"
1719
#include "swift/SIL/SILValue.h"
1820
#include "llvm/ADT/SmallPtrSet.h"
1921
#include "llvm/ADT/SmallVector.h"
@@ -124,6 +126,27 @@ class LinearLifetimeError {
124126
}
125127
};
126128

129+
struct UseToEndBorrow {
130+
Optional<EndBorrowInst *> operator()(Operand *use) const {
131+
if (auto *ebi = dyn_cast<EndBorrowInst>(use->getUser())) {
132+
return ebi;
133+
}
134+
return None;
135+
}
136+
};
137+
138+
using EndBorrowRange =
139+
OptionalTransformRange<ValueBase::use_range, UseToEndBorrow,
140+
ValueBase::use_iterator>;
141+
142+
/// Given a value \p v that is a "borrow" introducer, return its associated
143+
/// end_borrow users.
144+
inline auto makeEndBorrowRange(SILValue v) -> EndBorrowRange {
145+
assert((isa<BeginBorrowInst>(v) || isa<LoadBorrowInst>(v)) &&
146+
"Unhandled borrow introducer");
147+
return EndBorrowRange(v->getUses(), UseToEndBorrow());
148+
}
149+
127150
/// Returns true if:
128151
///
129152
/// 1. No consuming uses are reachable from any other consuming use, from any

include/swift/SIL/SILInstruction.h

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3255,32 +3255,8 @@ class BeginBorrowInst
32553255
BeginBorrowInst(SILDebugLocation DebugLoc, SILValue LValue)
32563256
: UnaryInstructionBase(DebugLoc, LValue,
32573257
LValue->getType().getObjectType()) {}
3258-
3259-
private:
3260-
/// Predicate used to filer EndBorrowRange.
3261-
struct UseToEndBorrow;
3262-
3263-
public:
3264-
using EndBorrowRange =
3265-
OptionalTransformRange<use_range, UseToEndBorrow, use_iterator>;
3266-
3267-
/// Find all associated end_borrow instructions for this begin_borrow.
3268-
EndBorrowRange getEndBorrows() const;
3269-
};
3270-
3271-
struct BeginBorrowInst::UseToEndBorrow {
3272-
Optional<EndBorrowInst *> operator()(Operand *use) const {
3273-
if (auto *ebi = dyn_cast<EndBorrowInst>(use->getUser())) {
3274-
return ebi;
3275-
}
3276-
return None;
3277-
}
32783258
};
32793259

3280-
inline auto BeginBorrowInst::getEndBorrows() const -> EndBorrowRange {
3281-
return EndBorrowRange(getUses(), UseToEndBorrow());
3282-
}
3283-
32843260
/// Represents a store of a borrowed value into an address. Returns the borrowed
32853261
/// address. Must be paired with an end_borrow in its use-def list.
32863262
class StoreBorrowInst

lib/SIL/SILOwnershipVerifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ bool SILValueOwnershipChecker::gatherUsers(
331331
for (unsigned i : indices(nonLifetimeEndingUsers)) {
332332
if (auto *bbi = dyn_cast<BeginBorrowInst>(
333333
nonLifetimeEndingUsers[i].getInst())) {
334-
copy(bbi->getEndBorrows(),
334+
copy(makeEndBorrowRange(bbi),
335335
std::back_inserter(implicitRegularUsers));
336336
}
337337
}

0 commit comments

Comments
 (0)