@@ -286,17 +286,13 @@ static void extendLifetimeToEndOfFunction(SILFunction &fn,
286
286
cvtUser->setOperand (cvtUse->getOperandNumber (), mdi);
287
287
}
288
288
289
- auto fixupSILForLifetimeExtension = [&](SILValue value) {
289
+ auto fixupSILForLifetimeExtension = [&](SILValue value, SILValue entryValue ) {
290
290
// Use SSAUpdater to find insertion points for lifetime ends.
291
291
updater.initialize (optionalEscapingClosureTy, value->getOwnershipKind ());
292
292
SmallVector<SILPhiArgument *, 8 > insertedPhis;
293
293
updater.setInsertedPhis (&insertedPhis);
294
294
295
- // Create an optional none at the function entry.
296
- auto *optionalNone =
297
- SILBuilderWithScope (fn.getEntryBlock ()->begin ())
298
- .createOptionalNone (loc, optionalEscapingClosureTy);
299
- updater.addAvailableValue (fn.getEntryBlock (), optionalNone);
295
+ updater.addAvailableValue (fn.getEntryBlock (), entryValue);
300
296
updater.addAvailableValue (value->getParentBlock (), value);
301
297
{
302
298
// Since value maybe in a loop, insert an extra lifetime end. Since we
@@ -316,12 +312,17 @@ static void extendLifetimeToEndOfFunction(SILFunction &fn,
316
312
// TODO: Should we sort inserted phis before or after we initialize
317
313
// the worklist or maybe backwards? We should investigate how the
318
314
// SSA updater adds phi nodes to this list to resolve this question.
319
- cleanupDeadTrivialPhiArgs (optionalNone , insertedPhis);
315
+ cleanupDeadTrivialPhiArgs (entryValue , insertedPhis);
320
316
};
321
317
318
+ // Create an optional none at the function entry.
319
+ auto *optionalNone = SILBuilderWithScope (fn.getEntryBlock ()->begin ())
320
+ .createOptionalNone (loc, optionalEscapingClosureTy);
321
+ auto *borrowNone = SILBuilderWithScope (optionalNone->getNextInstruction ())
322
+ .createBeginBorrow (loc, optionalNone);
322
323
// Use the SSAUpdater to create lifetime ends for the copy and the borrow.
323
- fixupSILForLifetimeExtension (borrow);
324
- fixupSILForLifetimeExtension (optionalSome);
324
+ fixupSILForLifetimeExtension (borrow, borrowNone );
325
+ fixupSILForLifetimeExtension (optionalSome, optionalNone );
325
326
}
326
327
327
328
static SILInstruction *lookThroughRebastractionUsers (
0 commit comments