@@ -492,9 +492,14 @@ struct OwnershipLifetimeExtender {
492
492
493
493
} // end anonymous namespace
494
494
495
- // Lifetime extend newValue over owned oldValue assuming that our copy will have
496
- // its lifetime ended by oldValue's lifetime ending uses after RAUWing by our
497
- // caller.
495
+ // / Lifetime extend \p value over \p consumingPoint, assuming that \p
496
+ // / consumingPoint will consume \p value after the client performs replacement
497
+ // / (this implicit destruction on the caller-side makes it a "plus-one"
498
+ // / copy). Destroy \p copy on all paths that don't reach \p consumingPoint.
499
+ // /
500
+ // / Precondition: \p value is owned
501
+ // /
502
+ // / Precondition: \p consumingPoint is dominated by \p value
498
503
CopyValueInst *
499
504
OwnershipLifetimeExtender::createPlusOneCopy (SILValue value,
500
505
SILInstruction *consumingPoint) {
@@ -507,28 +512,23 @@ OwnershipLifetimeExtender::createPlusOneCopy(SILValue value,
507
512
508
513
auto *result = copy;
509
514
findJointPostDominatingSet (
510
- copyPoint ->getParent (), consumingPoint->getParent (),
515
+ copy ->getParent (), consumingPoint->getParent (),
511
516
// inputBlocksFoundDuringWalk.
512
517
[&](SILBasicBlock *loopBlock) {
513
- // This must be consumingPoint->getParent() since we only have one
514
- // consuming use. In this case, we know that this is the consuming
515
- // point where we will need a control equivalent copy_value (and that
516
- // destroy_value will be put for the out of loop value as appropriate.
518
+ // Since copy dominates consumingPoint, it must be outside the
519
+ // loop. Otherwise backward traversal would have stopped at copyPoint.
520
+ //
521
+ // Create an extra copy when the consumingPoint is inside a loop and the
522
+ // original copy is outside the loop. The new copy will be consumed
523
+ // within the loop in the same block as the consume. The original copy
524
+ // will be destroyed on all paths exiting the loop.
517
525
assert (loopBlock == consumingPoint->getParent ());
518
526
auto front = loopBlock->begin ();
519
527
SILBuilderWithScope newBuilder (front);
520
-
521
- // Create an extra copy when the consuming point is inside a
522
- // loop and both copyPoint and the destroy points are outside the
523
- // loop. This copy will be consumed in the same block. The original
524
- // value will be destroyed on all paths exiting the loop.
525
- //
526
- // Since copyPoint dominates consumingPoint, it must be outside the
527
- // loop. Otherwise backward traversal would have stopped at copyPoint.
528
528
result = newBuilder.createCopyValue (front->getLoc (), copy);
529
529
callbacks.createdNewInst (result);
530
530
},
531
- // Input blocks in joint post dom set. We don't care about thse .
531
+ // Leaky blocks that never reach consumingPoint .
532
532
[&](SILBasicBlock *postDomBlock) {
533
533
auto front = postDomBlock->begin ();
534
534
SILBuilderWithScope newBuilder (front);
0 commit comments