@@ -327,18 +327,19 @@ bool swift::findInnerTransitiveGuaranteedUses(
327327 //
328328 // FIXME: visit[Extended]ScopeEndingUses can't return false here once dead
329329 // borrows are disallowed.
330- if (!BorrowingOperand (use).visitScopeEndingUses ([&](Operand *endUse) {
331- if (endUse->getOperandOwnership () == OperandOwnership::Reborrow) {
332- foundPointerEscape = true ;
333- }
334- if (PhiOperand (endUse)) {
335- assert (endUse->getOperandOwnership () ==
336- OperandOwnership::ForwardingConsume);
330+ if (!BorrowingOperand (use).visitScopeEndingUses (
331+ [&](Operand *endUse) {
332+ if (endUse->getOperandOwnership () == OperandOwnership::Reborrow) {
333+ foundPointerEscape = true ;
334+ }
335+ leafUse (endUse);
336+ return true ;
337+ },
338+ [&](Operand *unknownUse) {
337339 foundPointerEscape = true ;
338- }
339- leafUse (endUse);
340- return true ;
341- })) {
340+ leafUse (unknownUse);
341+ return true ;
342+ })) {
342343 // Special case for dead borrows. This is dangerous because clients
343344 // don't expect a begin_borrow to be in the use list.
344345 leafUse (use);
@@ -451,16 +452,12 @@ bool swift::findExtendedUsesOfSimpleBorrowedValue(
451452 break ;
452453 }
453454 case OperandOwnership::Borrow:
454- // FIXME: visitExtendedScopeEndingUses can't return false here once dead
455- // borrows are disallowed.
456455 if (!BorrowingOperand (use).visitExtendedScopeEndingUses (
457456 [&](Operand *endUse) {
458457 recordUse (endUse);
459458 return true ;
460459 })) {
461- // Special case for dead borrows. This is dangerous because clients
462- // don't expect a begin_borrow to be in the use list.
463- recordUse (use);
460+ return false ;
464461 }
465462 break ;
466463 }
@@ -480,11 +477,6 @@ bool swift::findUsesOfSimpleValue(SILValue value,
480477 if (end->getOperandOwnership () == OperandOwnership::Reborrow) {
481478 return false ;
482479 }
483- if (PhiOperand (use)) {
484- assert (use->getOperandOwnership () ==
485- OperandOwnership::ForwardingConsume);
486- return false ;
487- }
488480 usePoints->push_back (end);
489481 return true ;
490482 })) {
@@ -694,7 +686,8 @@ bool BorrowingOperand::hasEmptyRequiredEndingUses() const {
694686}
695687
696688bool BorrowingOperand::visitScopeEndingUses (
697- function_ref<bool (Operand *)> func) const {
689+ function_ref<bool (Operand *)> visitScopeEnd,
690+ function_ref<bool(Operand *)> visitUnknownUse) const {
698691 switch (kind) {
699692 case BorrowingOperandKind::Invalid:
700693 llvm_unreachable (" Using invalid case" );
@@ -703,7 +696,7 @@ bool BorrowingOperand::visitScopeEndingUses(
703696 for (auto *use : cast<BeginBorrowInst>(op->getUser ())->getUses ()) {
704697 if (use->isLifetimeEnding ()) {
705698 deadBorrow = false ;
706- if (!func (use))
699+ if (!visitScopeEnd (use))
707700 return false ;
708701 }
709702 }
@@ -717,7 +710,7 @@ bool BorrowingOperand::visitScopeEndingUses(
717710 for (auto *use : cast<StoreBorrowInst>(op->getUser ())->getUses ()) {
718711 if (isa<EndBorrowInst>(use->getUser ())) {
719712 deadBorrow = false ;
720- if (!func (use))
713+ if (!visitScopeEnd (use))
721714 return false ;
722715 }
723716 }
@@ -731,7 +724,7 @@ bool BorrowingOperand::visitScopeEndingUses(
731724 auto *user = cast<BeginApplyInst>(op->getUser ());
732725 for (auto *use : user->getTokenResult ()->getUses ()) {
733726 deadApply = false ;
734- if (!func (use))
727+ if (!visitScopeEnd (use))
735728 return false ;
736729 }
737730 return !deadApply;
@@ -742,12 +735,12 @@ bool BorrowingOperand::visitScopeEndingUses(
742735 // The closure's borrow lifetimes end when the closure itself ends its
743736 // lifetime. That may happen transitively through conversions that forward
744737 // ownership of the closure.
745- return user->visitOnStackLifetimeEnds (func );
738+ return user->visitOnStackLifetimeEnds (visitScopeEnd );
746739 }
747740 case BorrowingOperandKind::MarkDependenceNonEscaping: {
748741 auto *user = cast<MarkDependenceInst>(op->getUser ());
749742 assert (user->isNonEscaping () && " escaping dependencies don't borrow" );
750- return user->visitNonEscapingLifetimeEnds (func );
743+ return user->visitNonEscapingLifetimeEnds (visitScopeEnd, visitUnknownUse );
751744 }
752745 case BorrowingOperandKind::BeginAsyncLet: {
753746 auto user = cast<BuiltinInst>(op->getUser ());
@@ -760,7 +753,7 @@ bool BorrowingOperand::visitScopeEndingUses(
760753 || builtinUser->getBuiltinKind () != BuiltinValueKind::EndAsyncLetLifetime)
761754 continue ;
762755
763- if (!func (use)) {
756+ if (!visitScopeEnd (use)) {
764757 return false ;
765758 }
766759 }
@@ -778,7 +771,7 @@ bool BorrowingOperand::visitScopeEndingUses(
778771 for (auto *use : br->getArgForOperand (op)->getUses ()) {
779772 if (use->isLifetimeEnding ()) {
780773 deadBranch = false ;
781- if (!func (use))
774+ if (!visitScopeEnd (use))
782775 return false ;
783776 }
784777 }
@@ -789,13 +782,14 @@ bool BorrowingOperand::visitScopeEndingUses(
789782}
790783
791784bool BorrowingOperand::visitExtendedScopeEndingUses (
792- function_ref<bool (Operand *)> visitor) const {
785+ function_ref<bool (Operand *)> visitor,
786+ function_ref<bool(Operand *)> visitUnknownUse) const {
793787
794788 if (hasBorrowIntroducingUser ()) {
795789 auto borrowedValue = getBorrowIntroducingUserResult ();
796790 return borrowedValue.visitExtendedScopeEndingUses (visitor);
797791 }
798- return visitScopeEndingUses (visitor);
792+ return visitScopeEndingUses (visitor, visitUnknownUse );
799793}
800794
801795BorrowedValue BorrowingOperand::getBorrowIntroducingUserResult () const {
@@ -857,10 +851,11 @@ void BorrowingOperand::getImplicitUses(
857851 SmallVectorImpl<Operand *> &foundUses) const {
858852 // FIXME: this visitScopeEndingUses should never return false once dead
859853 // borrows are disallowed.
860- if (! visitScopeEndingUses ( [&](Operand *endOp) {
854+ auto handleUse = [&](Operand *endOp) {
861855 foundUses.push_back (endOp);
862856 return true ;
863- })) {
857+ };
858+ if (!visitScopeEndingUses (handleUse, handleUse)) {
864859 // Special-case for dead borrows.
865860 foundUses.push_back (op);
866861 }
@@ -988,9 +983,6 @@ bool BorrowedValue::visitExtendedScopeEndingUses(
988983 reborrows.insert (borrowedValue.value );
989984 return true ;
990985 }
991- if (auto phiOp = PhiOperand (scopeEndingUse)) {
992- return false ;
993- }
994986 return visitor (scopeEndingUse);
995987 };
996988
0 commit comments