@@ -254,29 +254,16 @@ bool PartialApplyCombiner::processSingleApply(FullApplySite paiAI) {
254
254
255
255
// We also need to destroy the partial_apply instruction itself because it is
256
256
// consumed by the apply_instruction.
257
- if (auto *tai = dyn_cast<TryApplyInst>(paiAI)) {
258
- builder.setInsertionPoint (tai->getNormalBB ()->begin ());
257
+ auto loc = RegularLocation::getAutoGeneratedLocation ();
258
+ paiAI.insertAfterFullEvaluation ([&](SILBasicBlock::iterator insertPt) {
259
+ SILBuilderWithScope builder (insertPt);
259
260
for (auto arg : toBeDestroyedArgs) {
260
- builder.emitDestroyValueOperation (pai-> getLoc () , arg);
261
+ builder.emitDestroyValueOperation (loc , arg);
261
262
}
262
- if (!pai->hasCalleeGuaranteedContext ())
263
- builder.emitDestroyValueOperation (paiAI.getLoc (), pai);
264
- builder.setInsertionPoint (tai->getErrorBB ()->begin ());
265
- // Destroy the non-consumed parameters.
266
- for (auto arg : toBeDestroyedArgs) {
267
- builder.emitDestroyValueOperation (pai->getLoc (), arg);
268
- }
269
- if (!pai->hasCalleeGuaranteedContext ())
270
- builder.emitDestroyValueOperation (pai->getLoc (), pai);
271
- builder.setInsertionPoint (paiAI.getInstruction ());
272
- } else {
273
- // Destroy the non-consumed parameters.
274
- for (auto arg : toBeDestroyedArgs) {
275
- builder.emitDestroyValueOperation (pai->getLoc (), arg);
263
+ if (!pai->hasCalleeGuaranteedContext ()) {
264
+ builder.emitDestroyValueOperation (loc, pai);
276
265
}
277
- if (!pai->hasCalleeGuaranteedContext ())
278
- builder.emitDestroyValueOperation (pai->getLoc (), pai);
279
- }
266
+ });
280
267
281
268
if (auto *apply = dyn_cast<ApplyInst>(paiAI)) {
282
269
callbacks.replaceValueUsesWith (SILValue (apply),
0 commit comments