@@ -195,14 +195,9 @@ bool swift::findInnerTransitiveGuaranteedUses(
195195 return true ;
196196}
197197
198- // / Like findInnerTransitiveGuaranteedUses except that rather than it being a
199- // / precondition that the provided value not be a BorrowedValue, it is a [type-
200- // / system-enforced] precondition that the provided value be a BorrowedValue.
201- // /
202- // / TODO: Merge with findInnerTransitiveGuaranteedUses. Note that at the moment
203- // / the two are _almost_ identical, but not quite because the other has a
204- // / #if 0 and not just leaf uses but ALL uses are recorded.
205- bool swift::findInnerTransitiveGuaranteedUsesOfBorrowedValue (
198+ // / Find all uses in the extended lifetime (i.e. including copies) of a simple
199+ // / (i.e. not reborrowed) borrow scope and its transitive uses.
200+ bool swift::findExtendedUsesOfSimpleBorrowedValue (
206201 BorrowedValue borrowedValue, SmallVectorImpl<Operand *> *usePoints) {
207202
208203 auto recordUse = [&](Operand *use) {
@@ -220,21 +215,31 @@ bool swift::findInnerTransitiveGuaranteedUsesOfBorrowedValue(
220215 // membership check locally in this function (within a borrow scope) because
221216 // it isn't needed for the immediate uses, only the transitive uses.
222217 GraphNodeWorklist<Operand *, 8 > worklist;
223- for (Operand *use : borrowedValue.value ->getUses ()) {
224- if (use->getOperandOwnership () != OperandOwnership::NonUse)
225- worklist.insert (use);
226- }
218+ auto addUsesToWorklist = [&worklist](SILValue value) {
219+ for (Operand *use : value->getUses ()) {
220+ if (use->getOperandOwnership () != OperandOwnership::NonUse)
221+ worklist.insert (use);
222+ }
223+ };
224+
225+ addUsesToWorklist (borrowedValue.value );
227226
228227 // --- Transitively follow forwarded uses and look for escapes.
229228
230229 // usePoints grows in this loop.
231230 while (Operand *use = worklist.pop ()) {
231+ if (auto *cvi = dyn_cast<CopyValueInst>(use->getUser ())) {
232+ addUsesToWorklist (cvi);
233+ }
232234 switch (use->getOperandOwnership ()) {
233235 case OperandOwnership::NonUse:
236+ break ;
237+
234238 case OperandOwnership::TrivialUse:
235239 case OperandOwnership::ForwardingConsume:
236240 case OperandOwnership::DestroyingConsume:
237- llvm_unreachable (" this operand cannot handle an inner guaranteed use" );
241+ recordUse (use);
242+ break ;
238243
239244 case OperandOwnership::ForwardingUnowned:
240245 case OperandOwnership::PointerEscape:
@@ -264,6 +269,7 @@ bool swift::findInnerTransitiveGuaranteedUsesOfBorrowedValue(
264269 AddressUseKind::NonEscaping) {
265270 return false ;
266271 }
272+ recordUse (use);
267273 break ;
268274
269275 case OperandOwnership::ForwardingBorrow: {
0 commit comments