mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[CanonicalizeInst] Remove redundant lexical bbis.
Previously, CanonicalizeInstruction::eliminateSimpleBorrows bailed out when encountering any any [lexical] begin_borrow. While generally such borrow scopes must be preserved, they may be removed if they are redundant (when the borrowed value is guaranteed by another means: an outer lexical borrow scope or a guaranteed function argument). Here, removing such redundant lexical borrow scopes is enabled.
This commit is contained in:
@@ -445,9 +445,13 @@ static SILBasicBlock::iterator
|
||||
eliminateSimpleBorrows(BeginBorrowInst *bbi, CanonicalizeInstruction &pass) {
|
||||
auto next = std::next(bbi->getIterator());
|
||||
|
||||
// Never eliminate lexical borrow scopes. They must be kept to ensure that
|
||||
// value lifetimes aren't observably shortened.
|
||||
if (bbi->isLexical())
|
||||
// Lexical borrow scopes can only be eliminated under certain circumstances:
|
||||
// (1) They can never be eliminated if the module is in the raw stage, because
|
||||
// they may be needed for diagnostic.
|
||||
// (2) They can never be eliminated if there is no enclosing lexical scope
|
||||
// which guarantees the lifetime of the value.
|
||||
if (bbi->isLexical() && (bbi->getModule().getStage() == SILStage::Raw ||
|
||||
!isNestedLexicalBeginBorrow(bbi)))
|
||||
return next;
|
||||
|
||||
// We know that our borrow is completely within the lifetime of its base value
|
||||
|
||||
Reference in New Issue
Block a user