Skip to content

Commit 960cbcb

Browse files
gottesmmnate-chandler
authored andcommitted
[SILGenCleanup] Do not remove trivial lexical borrow scopes.
This ensures that while in OSSA, we have in the IR information about the lexical lifetime of let variables.
1 parent 127f2f5 commit 960cbcb

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

lib/SILOptimizer/Utils/CanonicalizeInstruction.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,11 @@ static SILBasicBlock::iterator
450450
eliminateSimpleBorrows(BeginBorrowInst *bbi, CanonicalizeInstruction &pass) {
451451
auto next = std::next(bbi->getIterator());
452452

453+
// Never eliminate lexical borrow scopes. They must be kept to ensure that
454+
// value lifetimes aren't observably shortened.
455+
if (bbi->isLexical())
456+
return next;
457+
453458
// We know that our borrow is completely within the lifetime of its base value
454459
// if the borrow is never reborrowed. We check for reborrows and do not
455460
// optimize such cases. Otherwise, we can eliminate our borrow and instead use

0 commit comments

Comments
 (0)