Skip to content

Commit d80f7a3

Browse files
committed
SIL: make BeginBorrowInstruction.endOperands and BeginBorrowValue.scopeEndingOperands consistent.
* rename `ScopedInstruction.endOperands` -> `scopeEndingOperands` * let them behave the same way. For `load_borrow` there was a difference because `endOperands` didn't consider branches to re-borrow phis.
1 parent cbf5c19 commit d80f7a3

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/LifetimeDependenceScopeFixup.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ private struct ExtendableScope {
298298
var endInstructions: LazyMapSequence<LazyFilterSequence<UseList>, Instruction> {
299299
switch introducer {
300300
case let .scoped(scopedInst):
301-
return scopedInst.endOperands.users
301+
return scopedInst.scopeEndingOperands.users
302302
case let .owned(value):
303303
return value.uses.endingLifetime.users
304304
}

SwiftCompilerSources/Sources/Optimizer/Utilities/OwnershipLiveness.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ extension InteriorUseWalker: AddressUseVisitor {
685685
if handleInner(borrowed: ba) == .abortWalk {
686686
return .abortWalk
687687
}
688-
return ba.endOperands.walk { useVisitor($0) }
688+
return ba.scopeEndingOperands.walk { useVisitor($0) }
689689
case let ba as BeginApplyInst:
690690
if handleInner(borrowed: ba.token) == .abortWalk {
691691
return .abortWalk

SwiftCompilerSources/Sources/SIL/Instruction.swift

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,8 @@ final public class BorrowedFromInst : SingleValueInstruction, BeginBorrowInstruc
11791179
public var enclosingValues: LazyMapSequence<LazySequence<OperandArray>.Elements, Value> {
11801180
enclosingOperands.values
11811181
}
1182+
1183+
public var scopeEndingOperands: LazyFilterSequence<UseList> { uses.endingLifetime }
11821184
}
11831185

11841186
final public class ProjectBoxInst : SingleValueInstruction, UnaryInstruction {
@@ -1416,7 +1418,7 @@ final public class AllocExistentialBoxInst : SingleValueInstruction, Allocation
14161418
/// scope ending instruction such as `begin_access` (ending with `end_access`) and `begin_borrow` (ending with
14171419
/// `end_borrow`).
14181420
public protocol ScopedInstruction: Instruction {
1419-
var endOperands: LazyFilterSequence<UseList> { get }
1421+
var scopeEndingOperands: LazyFilterSequence<UseList> { get }
14201422

14211423
var endInstructions: EndInstructions { get }
14221424
}
@@ -1425,7 +1427,7 @@ extension Instruction {
14251427
/// Return the sequence of use points of any instruction.
14261428
public var endInstructions: EndInstructions {
14271429
if let scopedInst = self as? ScopedInstruction {
1428-
return .scoped(scopedInst.endOperands.users)
1430+
return .scoped(scopedInst.scopeEndingOperands.users)
14291431
}
14301432
return .single(self)
14311433
}
@@ -1440,22 +1442,14 @@ final public class EndBorrowInst : Instruction, UnaryInstruction {
14401442
public var borrow: Value { operand.value }
14411443
}
14421444

1443-
extension BeginBorrowInstruction {
1444-
public var endOperands: LazyFilterSequence<UseList> {
1445-
return self.uses.lazy.filter { $0.instruction is EndBorrowInst }
1446-
}
1447-
}
1448-
14491445
final public class BeginBorrowInst : SingleValueInstruction, UnaryInstruction, BeginBorrowInstruction {
14501446
public var borrowedValue: Value { operand.value }
14511447

14521448
public override var isLexical: Bool { bridged.BeginBorrow_isLexical() }
14531449
public var hasPointerEscape: Bool { bridged.BeginBorrow_hasPointerEscape() }
14541450
public var isFromVarDecl: Bool { bridged.BeginBorrow_isFromVarDecl() }
14551451

1456-
public var endOperands: LazyFilterSequence<UseList> {
1457-
return uses.endingLifetime
1458-
}
1452+
public var scopeEndingOperands: LazyFilterSequence<UseList> { uses.endingLifetime }
14591453
}
14601454

14611455
final public class LoadBorrowInst : SingleValueInstruction, LoadInstruction, BeginBorrowInstruction {
@@ -1466,6 +1460,8 @@ final public class LoadBorrowInst : SingleValueInstruction, LoadInstruction, Beg
14661460
// code using noncopyable types that consumes or mutates a memory location while that location is borrowed,
14671461
// but the move-only checker must diagnose those problems before canonical SIL is formed.
14681462
public var isUnchecked: Bool { bridged.LoadBorrowInst_isUnchecked() }
1463+
1464+
public var scopeEndingOperands: LazyFilterSequence<UseList> { uses.endingLifetime }
14691465
}
14701466

14711467
final public class StoreBorrowInst : SingleValueInstruction, StoringInstruction, BeginBorrowInstruction {
@@ -1477,7 +1473,13 @@ final public class StoreBorrowInst : SingleValueInstruction, StoringInstruction,
14771473
return dest as! AllocStackInst
14781474
}
14791475

1476+
public var scopeEndingOperands: LazyFilterSequence<UseList> {
1477+
return self.uses.lazy.filter { $0.instruction is EndBorrowInst }
1478+
}
1479+
14801480
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.
14811483
uses.users(ofType: EndBorrowInst.self)
14821484
}
14831485
}
@@ -1502,7 +1504,7 @@ final public class BeginAccessInst : SingleValueInstruction, UnaryInstruction {
15021504
public typealias EndAccessInstructions = LazyMapSequence<LazyFilterSequence<UseList>, EndAccessInst>
15031505

15041506
public var endAccessInstructions: EndAccessInstructions {
1505-
endOperands.map { $0.instruction as! EndAccessInst }
1507+
scopeEndingOperands.map { $0.instruction as! EndAccessInst }
15061508
}
15071509
}
15081510

@@ -1513,7 +1515,7 @@ final public class EndAccessInst : Instruction, UnaryInstruction {
15131515
}
15141516

15151517
extension BeginAccessInst : ScopedInstruction {
1516-
public var endOperands: LazyFilterSequence<UseList> {
1518+
public var scopeEndingOperands: LazyFilterSequence<UseList> {
15171519
return uses.lazy.filter { $0.instruction is EndAccessInst }
15181520
}
15191521
}
@@ -1549,7 +1551,7 @@ final public class AbortApplyInst : Instruction, UnaryInstruction {
15491551
}
15501552

15511553
extension BeginApplyInst : ScopedInstruction {
1552-
public var endOperands: LazyFilterSequence<UseList> {
1554+
public var scopeEndingOperands: LazyFilterSequence<UseList> {
15531555
return token.uses.lazy.filter { $0.isScopeEndingUse }
15541556
}
15551557
}

0 commit comments

Comments
 (0)