File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -587,6 +587,11 @@ struct BorrowedValue {
587587 bool
588588 visitExtendedScopeEndingUses (function_ref<bool (Operand *)> visitor) const ;
589589
590+ // / Visit all lifetime ending operands of the entire borrow scope including
591+ // / reborrows
592+ bool
593+ visitTransitiveLifetimeEndingUses (function_ref<bool (Operand *)> func) const ;
594+
590595 void print (llvm::raw_ostream &os) const ;
591596 SWIFT_DEBUG_DUMP { print (llvm::dbgs ()); }
592597
Original file line number Diff line number Diff line change @@ -741,6 +741,38 @@ bool BorrowedValue::visitExtendedScopeEndingUses(
741741 return true ;
742742}
743743
744+ bool BorrowedValue::visitTransitiveLifetimeEndingUses (
745+ function_ref<bool (Operand *)> visitor) const {
746+ assert (isLocalScope ());
747+
748+ SmallPtrSetVector<SILValue, 4 > reborrows;
749+
750+ auto visitEnd = [&](Operand *scopeEndingUse) {
751+ if (scopeEndingUse->getOperandOwnership () == OperandOwnership::Reborrow) {
752+ BorrowingOperand (scopeEndingUse)
753+ .visitBorrowIntroducingUserResults ([&](BorrowedValue borrowedValue) {
754+ reborrows.insert (borrowedValue.value );
755+ return true ;
756+ });
757+ // visitor on the reborrow
758+ return visitor (scopeEndingUse);
759+ }
760+ // visitor on the end_borrow
761+ return visitor (scopeEndingUse);
762+ };
763+
764+ if (!visitLocalScopeEndingUses (visitEnd))
765+ return false ;
766+
767+ // reborrows grows in this loop.
768+ for (unsigned idx = 0 ; idx < reborrows.size (); ++idx) {
769+ if (!BorrowedValue (reborrows[idx]).visitLocalScopeEndingUses (visitEnd))
770+ return false ;
771+ }
772+
773+ return true ;
774+ }
775+
744776bool BorrowedValue::visitInteriorPointerOperandHelper (
745777 function_ref<void (InteriorPointerOperand)> func,
746778 BorrowedValue::InteriorPointerOperandVisitorKind kind) const {
You can’t perform that action at this time.
0 commit comments