@@ -732,12 +732,8 @@ namespace {
732
732
// Essentially RC identity where the starting point is already a reference.
733
733
class FindReferenceRoot {
734
734
SmallPtrSet<SILPhiArgument *, 4 > visitedPhis;
735
- bool preserveOwnership;
736
735
737
736
public:
738
- FindReferenceRoot (bool preserveOwnership)
739
- : preserveOwnership(preserveOwnership) {}
740
-
741
737
SILValue findRoot (SILValue ref) && {
742
738
SILValue root = recursiveFindRoot (ref);
743
739
assert (root && " all phi inputs must be reachable" );
@@ -749,14 +745,8 @@ class FindReferenceRoot {
749
745
SILValue recursiveFindRoot (SILValue ref) {
750
746
while (auto *svi = dyn_cast<SingleValueInstruction>(ref)) {
751
747
// If preserveOwnership is true, stop at the first owned root
752
- if (preserveOwnership) {
753
- if (!isIdentityAndOwnershipPreservingRefCast (svi)) {
754
- break ;
755
- }
756
- } else {
757
- if (!isIdentityPreservingRefCast (svi)) {
758
- break ;
759
- }
748
+ if (!isIdentityPreservingRefCast (svi)) {
749
+ break ;
760
750
}
761
751
ref = svi->getOperand (0 );
762
752
};
@@ -792,11 +782,22 @@ class FindReferenceRoot {
792
782
} // end anonymous namespace
793
783
794
784
SILValue swift::findReferenceRoot (SILValue ref) {
795
- return FindReferenceRoot (false /* preserveOwnership */ ).findRoot (ref);
785
+ return FindReferenceRoot ().findRoot (ref);
796
786
}
797
787
788
+ // This does not handle phis because a phis is either a consume or a
789
+ // reborrow. In either case, the phi argument's ownership is independent from
790
+ // the phi itself. The client assumes that the returned root is in the same
791
+ // lifetime or borrow scope of the access.
798
792
SILValue swift::findOwnershipReferenceRoot (SILValue ref) {
799
- return FindReferenceRoot (true /* preserveOwnership*/ ).findRoot (ref);
793
+ while (auto *svi = dyn_cast<SingleValueInstruction>(ref)) {
794
+ if (isIdentityAndOwnershipPreservingRefCast (svi)) {
795
+ ref = svi->getOperand (0 );
796
+ continue ;
797
+ }
798
+ break ;
799
+ }
800
+ return ref;
800
801
}
801
802
802
803
// / Find the first owned aggregate containing the reference, or simply the
0 commit comments