@@ -1112,7 +1112,9 @@ void ElementUseCollector::collectClassSelfUses() {
1112
1112
// 4) Potential escapes after super.init, if self is closed over.
1113
1113
//
1114
1114
// Handle each of these in turn.
1115
- for (auto *Op : MUI->getUses ()) {
1115
+ SmallVector<Operand *, 8 > Uses (MUI->getUses ());
1116
+ while (!Uses.empty ()) {
1117
+ Operand *Op = Uses.pop_back_val ();
1116
1118
SILInstruction *User = Op->getUser ();
1117
1119
1118
1120
// Stores to self.
@@ -1150,6 +1152,14 @@ void ElementUseCollector::collectClassSelfUses() {
1150
1152
if (isa<EndBorrowInst>(User))
1151
1153
continue ;
1152
1154
1155
+ // Recurse through begin_access.
1156
+ if (auto *beginAccess = dyn_cast<BeginAccessInst>(User)) {
1157
+ Uses.append (beginAccess->getUses ().begin (), beginAccess->getUses ().end ());
1158
+ continue ;
1159
+ }
1160
+ if (isa<EndAccessInst>(User))
1161
+ continue ;
1162
+
1153
1163
// Loads of the box produce self, so collect uses from them.
1154
1164
if (isa<LoadInst>(User) || isa<LoadBorrowInst>(User)) {
1155
1165
auto load = cast<SingleValueInstruction>(User);
@@ -1379,8 +1389,8 @@ void ElementUseCollector::collectClassSelfUses(
1379
1389
continue ;
1380
1390
}
1381
1391
1382
- // Skip end_borrow.
1383
- if (isa<EndBorrowInst>(User))
1392
+ // Skip end_borrow and end_access .
1393
+ if (isa<EndBorrowInst>(User) || isa<EndAccessInst>(User) )
1384
1394
continue ;
1385
1395
1386
1396
// ref_element_addr P, #field lookups up a field.
@@ -1417,10 +1427,9 @@ void ElementUseCollector::collectClassSelfUses(
1417
1427
1418
1428
// Look through begin_borrow, upcast, unchecked_ref_cast
1419
1429
// and copy_value.
1420
- if (isa<BeginBorrowInst>(User) ||
1421
- isa<UpcastInst>(User) ||
1422
- isa<UncheckedRefCastInst>(User) ||
1423
- isa<CopyValueInst>(User)) {
1430
+ if (isa<BeginBorrowInst>(User) || isa<BeginAccessInst>(User)
1431
+ || isa<UpcastInst>(User) || isa<UncheckedRefCastInst>(User)
1432
+ || isa<CopyValueInst>(User)) {
1424
1433
auto value = cast<SingleValueInstruction>(User);
1425
1434
std::copy (value->use_begin (), value->use_end (),
1426
1435
std::back_inserter (Worklist));
@@ -1498,14 +1507,24 @@ void DelegatingInitElementUseCollector::collectClassInitSelfUses() {
1498
1507
// 4) Potential escapes after super.init, if self is closed over.
1499
1508
// Handle each of these in turn.
1500
1509
//
1501
- for (auto *Op : MUI->getUses ()) {
1510
+ SmallVector<Operand *, 8 > Uses (MUI->getUses ());
1511
+ while (!Uses.empty ()) {
1512
+ Operand *Op = Uses.pop_back_val ();
1502
1513
SILInstruction *User = Op->getUser ();
1503
1514
1504
1515
// Ignore end_borrow. If we see an end_borrow it can only come from a
1505
1516
// load_borrow from ourselves.
1506
1517
if (isa<EndBorrowInst>(User))
1507
1518
continue ;
1508
1519
1520
+ // Recurse through begin_access.
1521
+ if (auto *beginAccess = dyn_cast<BeginAccessInst>(User)) {
1522
+ Uses.append (beginAccess->getUses ().begin (), beginAccess->getUses ().end ());
1523
+ continue ;
1524
+ }
1525
+ if (isa<EndAccessInst>(User))
1526
+ continue ;
1527
+
1509
1528
// Stores to self.
1510
1529
if (auto *SI = dyn_cast<StoreInst>(User)) {
1511
1530
if (Op->getOperandNumber () == 1 ) {
0 commit comments