@@ -963,6 +963,9 @@ static bool useHasTransitiveOwnership(const SILInstruction *inst) {
963963 if (isa<ConvertEscapeToNoEscapeInst>(inst))
964964 return true ;
965965
966+ if (isa<MarkDependenceInst>(inst))
967+ return true ;
968+
966969 // Look through copy_value, begin_borrow, move_value. They are inert for our
967970 // purposes, but we need to look through it.
968971 return isa<CopyValueInst>(inst) || isa<BeginBorrowInst>(inst) ||
@@ -1095,13 +1098,16 @@ void swift::getConsumedPartialApplyArgs(PartialApplyInst *pai,
10951098 }
10961099}
10971100
1098- bool swift::collectDestroys (SingleValueInstruction *inst,
1099- SmallVectorImpl<Operand *> &destroys) {
1101+ static bool collectDestroysRecursively (SingleValueInstruction *inst,
1102+ SmallVectorImpl<Operand *> &destroys,
1103+ InstructionSet &visited) {
11001104 bool isDead = true ;
11011105 for (Operand *use : inst->getUses ()) {
11021106 SILInstruction *user = use->getUser ();
1107+ if (!visited.insert (user))
1108+ continue ;
11031109 if (useHasTransitiveOwnership (user)) {
1104- if (!collectDestroys (cast<SingleValueInstruction>(user), destroys))
1110+ if (!collectDestroysRecursively (cast<SingleValueInstruction>(user), destroys, visited ))
11051111 isDead = false ;
11061112 destroys.push_back (use);
11071113 } else if (useDoesNotKeepValueAlive (user)) {
@@ -1113,6 +1119,12 @@ bool swift::collectDestroys(SingleValueInstruction *inst,
11131119 return isDead;
11141120}
11151121
1122+ bool swift::collectDestroys (SingleValueInstruction *inst,
1123+ SmallVectorImpl<Operand *> &destroys) {
1124+ InstructionSet visited (inst->getFunction ());
1125+ return collectDestroysRecursively (inst, destroys, visited);
1126+ }
1127+
11161128// / Move the original arguments of the partial_apply into newly created
11171129// / temporaries to extend the lifetime of the arguments until the partial_apply
11181130// / is finally destroyed.
0 commit comments