@@ -327,18 +327,19 @@ bool swift::findInnerTransitiveGuaranteedUses(
327
327
//
328
328
// FIXME: visit[Extended]ScopeEndingUses can't return false here once dead
329
329
// 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) {
337
339
foundPointerEscape = true ;
338
- }
339
- leafUse (endUse);
340
- return true ;
341
- })) {
340
+ leafUse (unknownUse);
341
+ return true ;
342
+ })) {
342
343
// Special case for dead borrows. This is dangerous because clients
343
344
// don't expect a begin_borrow to be in the use list.
344
345
leafUse (use);
@@ -451,16 +452,12 @@ bool swift::findExtendedUsesOfSimpleBorrowedValue(
451
452
break ;
452
453
}
453
454
case OperandOwnership::Borrow:
454
- // FIXME: visitExtendedScopeEndingUses can't return false here once dead
455
- // borrows are disallowed.
456
455
if (!BorrowingOperand (use).visitExtendedScopeEndingUses (
457
456
[&](Operand *endUse) {
458
457
recordUse (endUse);
459
458
return true ;
460
459
})) {
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 ;
464
461
}
465
462
break ;
466
463
}
@@ -480,11 +477,6 @@ bool swift::findUsesOfSimpleValue(SILValue value,
480
477
if (end->getOperandOwnership () == OperandOwnership::Reborrow) {
481
478
return false ;
482
479
}
483
- if (PhiOperand (use)) {
484
- assert (use->getOperandOwnership () ==
485
- OperandOwnership::ForwardingConsume);
486
- return false ;
487
- }
488
480
usePoints->push_back (end);
489
481
return true ;
490
482
})) {
@@ -694,7 +686,8 @@ bool BorrowingOperand::hasEmptyRequiredEndingUses() const {
694
686
}
695
687
696
688
bool BorrowingOperand::visitScopeEndingUses (
697
- function_ref<bool (Operand *)> func) const {
689
+ function_ref<bool (Operand *)> visitScopeEnd,
690
+ function_ref<bool(Operand *)> visitUnknownUse) const {
698
691
switch (kind) {
699
692
case BorrowingOperandKind::Invalid:
700
693
llvm_unreachable (" Using invalid case" );
@@ -703,7 +696,7 @@ bool BorrowingOperand::visitScopeEndingUses(
703
696
for (auto *use : cast<BeginBorrowInst>(op->getUser ())->getUses ()) {
704
697
if (use->isLifetimeEnding ()) {
705
698
deadBorrow = false ;
706
- if (!func (use))
699
+ if (!visitScopeEnd (use))
707
700
return false ;
708
701
}
709
702
}
@@ -717,7 +710,7 @@ bool BorrowingOperand::visitScopeEndingUses(
717
710
for (auto *use : cast<StoreBorrowInst>(op->getUser ())->getUses ()) {
718
711
if (isa<EndBorrowInst>(use->getUser ())) {
719
712
deadBorrow = false ;
720
- if (!func (use))
713
+ if (!visitScopeEnd (use))
721
714
return false ;
722
715
}
723
716
}
@@ -731,7 +724,7 @@ bool BorrowingOperand::visitScopeEndingUses(
731
724
auto *user = cast<BeginApplyInst>(op->getUser ());
732
725
for (auto *use : user->getTokenResult ()->getUses ()) {
733
726
deadApply = false ;
734
- if (!func (use))
727
+ if (!visitScopeEnd (use))
735
728
return false ;
736
729
}
737
730
return !deadApply;
@@ -742,12 +735,12 @@ bool BorrowingOperand::visitScopeEndingUses(
742
735
// The closure's borrow lifetimes end when the closure itself ends its
743
736
// lifetime. That may happen transitively through conversions that forward
744
737
// ownership of the closure.
745
- return user->visitOnStackLifetimeEnds (func );
738
+ return user->visitOnStackLifetimeEnds (visitScopeEnd );
746
739
}
747
740
case BorrowingOperandKind::MarkDependenceNonEscaping: {
748
741
auto *user = cast<MarkDependenceInst>(op->getUser ());
749
742
assert (user->isNonEscaping () && " escaping dependencies don't borrow" );
750
- return user->visitNonEscapingLifetimeEnds (func );
743
+ return user->visitNonEscapingLifetimeEnds (visitScopeEnd, visitUnknownUse );
751
744
}
752
745
case BorrowingOperandKind::BeginAsyncLet: {
753
746
auto user = cast<BuiltinInst>(op->getUser ());
@@ -760,7 +753,7 @@ bool BorrowingOperand::visitScopeEndingUses(
760
753
|| builtinUser->getBuiltinKind () != BuiltinValueKind::EndAsyncLetLifetime)
761
754
continue ;
762
755
763
- if (!func (use)) {
756
+ if (!visitScopeEnd (use)) {
764
757
return false ;
765
758
}
766
759
}
@@ -778,7 +771,7 @@ bool BorrowingOperand::visitScopeEndingUses(
778
771
for (auto *use : br->getArgForOperand (op)->getUses ()) {
779
772
if (use->isLifetimeEnding ()) {
780
773
deadBranch = false ;
781
- if (!func (use))
774
+ if (!visitScopeEnd (use))
782
775
return false ;
783
776
}
784
777
}
@@ -789,13 +782,14 @@ bool BorrowingOperand::visitScopeEndingUses(
789
782
}
790
783
791
784
bool BorrowingOperand::visitExtendedScopeEndingUses (
792
- function_ref<bool (Operand *)> visitor) const {
785
+ function_ref<bool (Operand *)> visitor,
786
+ function_ref<bool(Operand *)> visitUnknownUse) const {
793
787
794
788
if (hasBorrowIntroducingUser ()) {
795
789
auto borrowedValue = getBorrowIntroducingUserResult ();
796
790
return borrowedValue.visitExtendedScopeEndingUses (visitor);
797
791
}
798
- return visitScopeEndingUses (visitor);
792
+ return visitScopeEndingUses (visitor, visitUnknownUse );
799
793
}
800
794
801
795
BorrowedValue BorrowingOperand::getBorrowIntroducingUserResult () const {
@@ -857,10 +851,11 @@ void BorrowingOperand::getImplicitUses(
857
851
SmallVectorImpl<Operand *> &foundUses) const {
858
852
// FIXME: this visitScopeEndingUses should never return false once dead
859
853
// borrows are disallowed.
860
- if (! visitScopeEndingUses ( [&](Operand *endOp) {
854
+ auto handleUse = [&](Operand *endOp) {
861
855
foundUses.push_back (endOp);
862
856
return true ;
863
- })) {
857
+ };
858
+ if (!visitScopeEndingUses (handleUse, handleUse)) {
864
859
// Special-case for dead borrows.
865
860
foundUses.push_back (op);
866
861
}
@@ -988,9 +983,6 @@ bool BorrowedValue::visitExtendedScopeEndingUses(
988
983
reborrows.insert (borrowedValue.value );
989
984
return true ;
990
985
}
991
- if (auto phiOp = PhiOperand (scopeEndingUse)) {
992
- return false ;
993
- }
994
986
return visitor (scopeEndingUse);
995
987
};
996
988
0 commit comments