@@ -1169,7 +1169,7 @@ final public class BridgeObjectToRefInst : SingleValueInstruction, UnaryInstruct
1169
1169
1170
1170
final public class BridgeObjectToWordInst : SingleValueInstruction , UnaryInstruction { }
1171
1171
1172
- final public class BorrowedFromInst : SingleValueInstruction , BorrowIntroducingInstruction {
1172
+ final public class BorrowedFromInst : SingleValueInstruction , BeginBorrowInstruction {
1173
1173
public var borrowedValue : Value { operands [ 0 ] . value }
1174
1174
public var borrowedPhi : Phi { Phi ( borrowedValue) ! }
1175
1175
public var enclosingOperands : OperandArray {
@@ -1179,6 +1179,8 @@ final public class BorrowedFromInst : SingleValueInstruction, BorrowIntroducingI
1179
1179
public var enclosingValues : LazyMapSequence < LazySequence < OperandArray > . Elements , Value > {
1180
1180
enclosingOperands. values
1181
1181
}
1182
+
1183
+ public var scopeEndingOperands : LazyFilterSequence < UseList > { uses. endingLifetime }
1182
1184
}
1183
1185
1184
1186
final public class ProjectBoxInst : SingleValueInstruction , UnaryInstruction {
@@ -1415,10 +1417,8 @@ final public class AllocExistentialBoxInst : SingleValueInstruction, Allocation
1415
1417
/// An instruction whose side effects extend across a scope including other instructions. These are always paired with a
1416
1418
/// scope ending instruction such as `begin_access` (ending with `end_access`) and `begin_borrow` (ending with
1417
1419
/// `end_borrow`).
1418
- public protocol ScopedInstruction {
1419
- var instruction : Instruction { get }
1420
-
1421
- var endOperands : LazyFilterSequence < UseList > { get }
1420
+ public protocol ScopedInstruction : Instruction {
1421
+ var scopeEndingOperands : LazyFilterSequence < UseList > { get }
1422
1422
1423
1423
var endInstructions : EndInstructions { get }
1424
1424
}
@@ -1427,53 +1427,44 @@ extension Instruction {
1427
1427
/// Return the sequence of use points of any instruction.
1428
1428
public var endInstructions : EndInstructions {
1429
1429
if let scopedInst = self as? ScopedInstruction {
1430
- return . scoped( scopedInst. endOperands . users)
1430
+ return . scoped( scopedInst. scopeEndingOperands . users)
1431
1431
}
1432
1432
return . single( self )
1433
1433
}
1434
1434
}
1435
1435
1436
- /// Instructions beginning a borrow-scope which must be ended by `end_borrow`.
1437
- public protocol BorrowIntroducingInstruction : SingleValueInstruction , ScopedInstruction {
1438
- }
1439
-
1440
- extension BorrowIntroducingInstruction {
1441
- public var instruction : Instruction { get { self } }
1436
+ /// Single-value instructions beginning a borrow-scope which end with an `end_borrow` or a branch to a re-borrow phi.
1437
+ /// See also `BeginBorrowValue` which represents all kind of `Value`s which begin a borrow scope.
1438
+ public protocol BeginBorrowInstruction : SingleValueInstruction , ScopedInstruction {
1442
1439
}
1443
1440
1444
1441
final public class EndBorrowInst : Instruction , UnaryInstruction {
1445
1442
public var borrow : Value { operand. value }
1446
1443
}
1447
1444
1448
- extension BorrowIntroducingInstruction {
1449
- public var endOperands : LazyFilterSequence < UseList > {
1450
- return uses. lazy. filter { $0. instruction is EndBorrowInst }
1451
- }
1452
- }
1453
-
1454
- final public class BeginBorrowInst : SingleValueInstruction , UnaryInstruction , BorrowIntroducingInstruction {
1445
+ final public class BeginBorrowInst : SingleValueInstruction , UnaryInstruction , BeginBorrowInstruction {
1455
1446
public var borrowedValue : Value { operand. value }
1456
1447
1457
1448
public override var isLexical : Bool { bridged. BeginBorrow_isLexical ( ) }
1458
1449
public var hasPointerEscape : Bool { bridged. BeginBorrow_hasPointerEscape ( ) }
1459
1450
public var isFromVarDecl : Bool { bridged. BeginBorrow_isFromVarDecl ( ) }
1460
1451
1461
- public var endOperands : LazyFilterSequence < UseList > {
1462
- return uses. endingLifetime
1463
- }
1452
+ public var scopeEndingOperands : LazyFilterSequence < UseList > { uses. endingLifetime }
1464
1453
}
1465
1454
1466
- final public class LoadBorrowInst : SingleValueInstruction , LoadInstruction , BorrowIntroducingInstruction {
1455
+ final public class LoadBorrowInst : SingleValueInstruction , LoadInstruction , BeginBorrowInstruction {
1467
1456
1468
1457
// True if the invariants on `load_borrow` have not been checked and should not be strictly enforced.
1469
1458
//
1470
1459
// This can only occur during raw SIL before move-only checking occurs. Developers can write incorrect
1471
1460
// code using noncopyable types that consumes or mutates a memory location while that location is borrowed,
1472
1461
// but the move-only checker must diagnose those problems before canonical SIL is formed.
1473
1462
public var isUnchecked : Bool { bridged. LoadBorrowInst_isUnchecked ( ) }
1463
+
1464
+ public var scopeEndingOperands : LazyFilterSequence < UseList > { uses. endingLifetime }
1474
1465
}
1475
1466
1476
- final public class StoreBorrowInst : SingleValueInstruction , StoringInstruction , BorrowIntroducingInstruction {
1467
+ final public class StoreBorrowInst : SingleValueInstruction , StoringInstruction , BeginBorrowInstruction {
1477
1468
public var allocStack : AllocStackInst {
1478
1469
var dest = destination
1479
1470
if let mark = dest as? MarkUnresolvedNonCopyableValueInst {
@@ -1482,7 +1473,13 @@ final public class StoreBorrowInst : SingleValueInstruction, StoringInstruction,
1482
1473
return dest as! AllocStackInst
1483
1474
}
1484
1475
1476
+ public var scopeEndingOperands : LazyFilterSequence < UseList > {
1477
+ return self . uses. lazy. filter { $0. instruction is EndBorrowInst }
1478
+ }
1479
+
1485
1480
public var endBorrows : LazyMapSequence < LazyFilterSequence < UseList > , Instruction > {
1481
+ // A `store_borrow` is an address value.
1482
+ // Only `end_borrow`s (with this address operand) can end such a borrow scope.
1486
1483
uses. users ( ofType: EndBorrowInst . self)
1487
1484
}
1488
1485
}
@@ -1507,7 +1504,7 @@ final public class BeginAccessInst : SingleValueInstruction, UnaryInstruction {
1507
1504
public typealias EndAccessInstructions = LazyMapSequence < LazyFilterSequence < UseList > , EndAccessInst >
1508
1505
1509
1506
public var endAccessInstructions : EndAccessInstructions {
1510
- endOperands . map { $0. instruction as! EndAccessInst }
1507
+ scopeEndingOperands . map { $0. instruction as! EndAccessInst }
1511
1508
}
1512
1509
}
1513
1510
@@ -1518,9 +1515,7 @@ final public class EndAccessInst : Instruction, UnaryInstruction {
1518
1515
}
1519
1516
1520
1517
extension BeginAccessInst : ScopedInstruction {
1521
- public var instruction : Instruction { get { self } }
1522
-
1523
- public var endOperands : LazyFilterSequence < UseList > {
1518
+ public var scopeEndingOperands : LazyFilterSequence < UseList > {
1524
1519
return uses. lazy. filter { $0. instruction is EndAccessInst }
1525
1520
}
1526
1521
}
@@ -1556,9 +1551,7 @@ final public class AbortApplyInst : Instruction, UnaryInstruction {
1556
1551
}
1557
1552
1558
1553
extension BeginApplyInst : ScopedInstruction {
1559
- public var instruction : Instruction { get { self } }
1560
-
1561
- public var endOperands : LazyFilterSequence < UseList > {
1554
+ public var scopeEndingOperands : LazyFilterSequence < UseList > {
1562
1555
return token. uses. lazy. filter { $0. isScopeEndingUse }
1563
1556
}
1564
1557
}
0 commit comments