@@ -410,6 +410,18 @@ broadenSingleElementStores(StoreInst *storeInst,
410
410
// Simple ARC Peepholes
411
411
// ===----------------------------------------------------------------------===//
412
412
413
+ // / "dead" copies are removed in OSSA, but this may shorten object lifetimes,
414
+ // / changing program semantics in unexpected ways by releasing weak references
415
+ // / and running deinitializers early. This copy may be the only thing keeping a
416
+ // / variable's reference alive. But just because the copy's current SSA value
417
+ // / contains no other uses does not mean that there aren't other uses that still
418
+ // / correspond to the original variable whose lifetime is protected by this
419
+ // / copy. The only way to guarantee the lifetime of a variable is to use a
420
+ // / borrow scope--copy/destroy is insufficient by itself.
421
+ // /
422
+ // / FIXME: Technically this should be guarded by a compiler flag like
423
+ // / -enable-copy-propagation until SILGen protects scoped variables by borrow
424
+ // / scopes.
413
425
static SILBasicBlock::iterator
414
426
eliminateSimpleCopies (CopyValueInst *cvi, CanonicalizeInstruction &pass) {
415
427
auto next = std::next (cvi->getIterator ());
@@ -432,6 +444,8 @@ eliminateSimpleCopies(CopyValueInst *cvi, CanonicalizeInstruction &pass) {
432
444
return next;
433
445
}
434
446
447
+ // / Unlike dead copy elimination, dead borrows can be safely removed because the
448
+ // / semantics of a borrow scope
435
449
static SILBasicBlock::iterator
436
450
eliminateSimpleBorrows (BeginBorrowInst *bbi, CanonicalizeInstruction &pass) {
437
451
auto next = std::next (bbi->getIterator ());
0 commit comments