@@ -41,10 +41,11 @@ static bool canInlineBeginApply(BeginApplyInst *BA) {
4141 if (isa<EndApplyInst>(user)) {
4242 if (hasEndApply) return false ;
4343 hasEndApply = true ;
44- } else {
45- assert (isa<AbortApplyInst>(user));
44+ } else if (isa<AbortApplyInst>(user)) {
4645 if (hasAbortApply) return false ;
4746 hasAbortApply = true ;
47+ } else {
48+ assert (isa<EndBorrowInst>(user));
4849 }
4950 }
5051
@@ -95,6 +96,8 @@ class BeginApplySite {
9596 SILBasicBlock *AbortApplyBB = nullptr ;
9697 SILBasicBlock *AbortApplyReturnBB = nullptr ;
9798
99+ SmallVector<EndBorrowInst *, 2 > EndBorrows;
100+
98101public:
99102 BeginApplySite (BeginApplyInst *BeginApply, SILLocation Loc,
100103 SILBuilder *Builder)
@@ -112,7 +115,8 @@ class BeginApplySite {
112115 SmallVectorImpl<SILInstruction *> &endBorrowInsertPts) {
113116 SmallVector<EndApplyInst *, 1 > endApplyInsts;
114117 SmallVector<AbortApplyInst *, 1 > abortApplyInsts;
115- BeginApply->getCoroutineEndPoints (endApplyInsts, abortApplyInsts);
118+ BeginApply->getCoroutineEndPoints (endApplyInsts, abortApplyInsts,
119+ &EndBorrows);
116120 while (!endApplyInsts.empty ()) {
117121 auto *endApply = endApplyInsts.pop_back_val ();
118122 collectEndApply (endApply);
@@ -257,6 +261,8 @@ class BeginApplySite {
257261 EndApply->eraseFromParent ();
258262 if (AbortApply)
259263 AbortApply->eraseFromParent ();
264+ for (auto *EndBorrow : EndBorrows)
265+ EndBorrow->eraseFromParent ();
260266
261267 assert (!BeginApply->hasUsesOfAnyResult ());
262268 }
0 commit comments