@@ -1169,7 +1169,7 @@ final public class BridgeObjectToRefInst : SingleValueInstruction, UnaryInstruct
11691169
11701170final public class BridgeObjectToWordInst : SingleValueInstruction , UnaryInstruction { }
11711171
1172- final public class BorrowedFromInst : SingleValueInstruction , BorrowIntroducingInstruction {
1172+ final public class BorrowedFromInst : SingleValueInstruction , BeginBorrowInstruction {
11731173 public var borrowedValue : Value { operands [ 0 ] . value }
11741174 public var borrowedPhi : Phi { Phi ( borrowedValue) ! }
11751175 public var enclosingOperands : OperandArray {
@@ -1179,6 +1179,8 @@ final public class BorrowedFromInst : SingleValueInstruction, BorrowIntroducingI
11791179 public var enclosingValues : LazyMapSequence < LazySequence < OperandArray > . Elements , Value > {
11801180 enclosingOperands. values
11811181 }
1182+
1183+ public var scopeEndingOperands : LazyFilterSequence < UseList > { uses. endingLifetime }
11821184}
11831185
11841186final public class ProjectBoxInst : SingleValueInstruction , UnaryInstruction {
@@ -1415,10 +1417,8 @@ final public class AllocExistentialBoxInst : SingleValueInstruction, Allocation
14151417/// An instruction whose side effects extend across a scope including other instructions. These are always paired with a
14161418/// scope ending instruction such as `begin_access` (ending with `end_access`) and `begin_borrow` (ending with
14171419/// `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 }
14221422
14231423 var endInstructions : EndInstructions { get }
14241424}
@@ -1427,53 +1427,44 @@ extension Instruction {
14271427 /// Return the sequence of use points of any instruction.
14281428 public var endInstructions : EndInstructions {
14291429 if let scopedInst = self as? ScopedInstruction {
1430- return . scoped( scopedInst. endOperands . users)
1430+ return . scoped( scopedInst. scopeEndingOperands . users)
14311431 }
14321432 return . single( self )
14331433 }
14341434}
14351435
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 {
14421439}
14431440
14441441final public class EndBorrowInst : Instruction , UnaryInstruction {
14451442 public var borrow : Value { operand. value }
14461443}
14471444
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 {
14551446 public var borrowedValue : Value { operand. value }
14561447
14571448 public override var isLexical : Bool { bridged. BeginBorrow_isLexical ( ) }
14581449 public var hasPointerEscape : Bool { bridged. BeginBorrow_hasPointerEscape ( ) }
14591450 public var isFromVarDecl : Bool { bridged. BeginBorrow_isFromVarDecl ( ) }
14601451
1461- public var endOperands : LazyFilterSequence < UseList > {
1462- return uses. endingLifetime
1463- }
1452+ public var scopeEndingOperands : LazyFilterSequence < UseList > { uses. endingLifetime }
14641453}
14651454
1466- final public class LoadBorrowInst : SingleValueInstruction , LoadInstruction , BorrowIntroducingInstruction {
1455+ final public class LoadBorrowInst : SingleValueInstruction , LoadInstruction , BeginBorrowInstruction {
14671456
14681457 // True if the invariants on `load_borrow` have not been checked and should not be strictly enforced.
14691458 //
14701459 // This can only occur during raw SIL before move-only checking occurs. Developers can write incorrect
14711460 // code using noncopyable types that consumes or mutates a memory location while that location is borrowed,
14721461 // but the move-only checker must diagnose those problems before canonical SIL is formed.
14731462 public var isUnchecked : Bool { bridged. LoadBorrowInst_isUnchecked ( ) }
1463+
1464+ public var scopeEndingOperands : LazyFilterSequence < UseList > { uses. endingLifetime }
14741465}
14751466
1476- final public class StoreBorrowInst : SingleValueInstruction , StoringInstruction , BorrowIntroducingInstruction {
1467+ final public class StoreBorrowInst : SingleValueInstruction , StoringInstruction , BeginBorrowInstruction {
14771468 public var allocStack : AllocStackInst {
14781469 var dest = destination
14791470 if let mark = dest as? MarkUnresolvedNonCopyableValueInst {
@@ -1482,7 +1473,13 @@ final public class StoreBorrowInst : SingleValueInstruction, StoringInstruction,
14821473 return dest as! AllocStackInst
14831474 }
14841475
1476+ public var scopeEndingOperands : LazyFilterSequence < UseList > {
1477+ return self . uses. lazy. filter { $0. instruction is EndBorrowInst }
1478+ }
1479+
14851480 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.
14861483 uses. users ( ofType: EndBorrowInst . self)
14871484 }
14881485}
@@ -1507,7 +1504,7 @@ final public class BeginAccessInst : SingleValueInstruction, UnaryInstruction {
15071504 public typealias EndAccessInstructions = LazyMapSequence < LazyFilterSequence < UseList > , EndAccessInst >
15081505
15091506 public var endAccessInstructions : EndAccessInstructions {
1510- endOperands . map { $0. instruction as! EndAccessInst }
1507+ scopeEndingOperands . map { $0. instruction as! EndAccessInst }
15111508 }
15121509}
15131510
@@ -1518,9 +1515,7 @@ final public class EndAccessInst : Instruction, UnaryInstruction {
15181515}
15191516
15201517extension BeginAccessInst : ScopedInstruction {
1521- public var instruction : Instruction { get { self } }
1522-
1523- public var endOperands : LazyFilterSequence < UseList > {
1518+ public var scopeEndingOperands : LazyFilterSequence < UseList > {
15241519 return uses. lazy. filter { $0. instruction is EndAccessInst }
15251520 }
15261521}
@@ -1556,9 +1551,7 @@ final public class AbortApplyInst : Instruction, UnaryInstruction {
15561551}
15571552
15581553extension BeginApplyInst : ScopedInstruction {
1559- public var instruction : Instruction { get { self } }
1560-
1561- public var endOperands : LazyFilterSequence < UseList > {
1554+ public var scopeEndingOperands : LazyFilterSequence < UseList > {
15621555 return token. uses. lazy. filter { $0. isScopeEndingUse }
15631556 }
15641557}
0 commit comments