File tree Expand file tree Collapse file tree 3 files changed +27
-19
lines changed Expand file tree Collapse file tree 3 files changed +27
-19
lines changed Original file line number Diff line number Diff line change @@ -1206,6 +1206,14 @@ void visitTransitiveEndBorrows(
1206
1206
BorrowedValue beginBorrow,
1207
1207
function_ref<void (EndBorrowInst *)> visitEndBorrow);
1208
1208
1209
+ // / Whether the specified lexical begin_borrow instruction is nested.
1210
+ // /
1211
+ // / A begin_borrow [lexical] is nested if the borrowed value's lifetime is
1212
+ // / guaranteed by another lexical scope. That happens if:
1213
+ // / - the value is a guaranteed argument to the function
1214
+ // / - the value is itself a begin_borrow [lexical]
1215
+ bool isNestedLexicalBeginBorrow (BeginBorrowInst *bbi);
1216
+
1209
1217
} // namespace swift
1210
1218
1211
1219
#endif
Original file line number Diff line number Diff line change @@ -1487,3 +1487,21 @@ void swift::visitTransitiveEndBorrows(
1487
1487
}
1488
1488
}
1489
1489
}
1490
+
1491
+ // / Whether the specified lexical begin_borrow instruction is nested.
1492
+ // /
1493
+ // / A begin_borrow [lexical] is nested if the borrowed value's lifetime is
1494
+ // / guaranteed by another lexical scope. That happens if:
1495
+ // / - the value is a guaranteed argument to the function
1496
+ // / - the value is itself a begin_borrow [lexical]
1497
+ bool swift::isNestedLexicalBeginBorrow (BeginBorrowInst *bbi) {
1498
+ assert (bbi->isLexical ());
1499
+ auto value = bbi->getOperand ();
1500
+ if (auto *outerBBI = dyn_cast<BeginBorrowInst>(value)) {
1501
+ return outerBBI->isLexical ();
1502
+ }
1503
+ if (auto *arg = dyn_cast<SILFunctionArgument>(value)) {
1504
+ return arg->getOwnershipKind () == OwnershipKind::Guaranteed;
1505
+ }
1506
+ return false ;
1507
+ }
Original file line number Diff line number Diff line change 24
24
using namespace swift ;
25
25
using namespace swift ::semanticarc;
26
26
27
- // / Whether the provided lexical begin_borrow instruction is redundant.
28
- // /
29
- // / A begin_borrow [lexical] is redundant if the borrowed value's lifetime is
30
- // / otherwise guaranteed. That happens if:
31
- // / - the value is a guaranteed argument to the function
32
- // / - the value is itself a begin_borrow [lexical]
33
- static bool isRedundantLexicalBeginBorrow (BeginBorrowInst *bbi) {
34
- assert (bbi->isLexical ());
35
- auto value = bbi->getOperand ();
36
- if (auto *outerBBI = dyn_cast<BeginBorrowInst>(value)) {
37
- return outerBBI->isLexical ();
38
- }
39
- if (auto *arg = dyn_cast<SILFunctionArgument>(value)) {
40
- return arg->getOwnershipKind () == OwnershipKind::Guaranteed;
41
- }
42
- return false ;
43
- }
44
-
45
27
bool SemanticARCOptVisitor::visitBeginBorrowInst (BeginBorrowInst *bbi) {
46
28
// Quickly check if we are supposed to perform this transformation.
47
29
if (!ctx.shouldPerform (ARCTransformKind::RedundantBorrowScopeElimPeephole))
48
30
return false ;
49
31
50
32
// Non-redundant, lexical borrow scopes must remain in order to ensure that
51
33
// value lifetimes are not observably shortened.
52
- if (bbi->isLexical () && !isRedundantLexicalBeginBorrow (bbi)) {
34
+ if (bbi->isLexical () && !isNestedLexicalBeginBorrow (bbi)) {
53
35
return false ;
54
36
}
55
37
You can’t perform that action at this time.
0 commit comments