Skip to content

Commit 8064e45

Browse files
committed
[OwnershipUtils] Match complex nested borrows.
Recognize lexical borrows as nested when their borrowee's guaranteed reference roots are all lexical borrows. Addresses the following regressions Breadcrumbs.MutatedUTF16ToIdx.Mixed 188 882 +369.1% **0.21x** Breadcrumbs.MutatedIdxToUTF16.Mixed 230 926 +302.6% **0.25x** seen when enabling lexical lifetimes in the standard library.
1 parent b76e8fe commit 8064e45

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

lib/SIL/Utils/OwnershipUtils.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,11 +1910,15 @@ void swift::visitTransitiveEndBorrows(
19101910
bool swift::isNestedLexicalBeginBorrow(BeginBorrowInst *bbi) {
19111911
assert(bbi->isLexical());
19121912
auto value = bbi->getOperand();
1913-
if (auto *outerBBI = dyn_cast<BeginBorrowInst>(value)) {
1914-
return outerBBI->isLexical();
1915-
}
1916-
if (auto *arg = dyn_cast<SILFunctionArgument>(value)) {
1917-
return arg->getOwnershipKind() == OwnershipKind::Guaranteed;
1918-
}
1919-
return false;
1913+
SmallVector<SILValue, 8> roots;
1914+
findGuaranteedReferenceRoots(value, roots);
1915+
return llvm::all_of(roots, [](auto root) {
1916+
if (auto *outerBBI = dyn_cast<BeginBorrowInst>(root)) {
1917+
return outerBBI->isLexical();
1918+
}
1919+
if (auto *arg = dyn_cast<SILFunctionArgument>(root)) {
1920+
return arg->getOwnershipKind() == OwnershipKind::Guaranteed;
1921+
}
1922+
return false;
1923+
});
19201924
}

0 commit comments

Comments
 (0)