Skip to content

Commit 38137c5

Browse files
committed
OwnershipLiveness.swift: add comments
and rename visitOwnedDependentUses
1 parent 406afc7 commit 38137c5

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/OwnershipLiveness.swift

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ struct InteriorLivenessResult: CustomDebugStringConvertible {
200200
/// entry points. Additionally, the implementation may recurse into inner
201201
/// borrow scopes, skipping over the uses within inner scopes using:
202202
/// - `visitInnerBorrowUses(of: BorrowingInstruction, operand:)`
203-
/// - `visitDependentUses(of: Value)`
203+
/// - `visitOwnedDependentUses(of: Value)`
204204
///
205205
/// Visitors implement:
206206
///
@@ -311,13 +311,20 @@ extension OwnershipUseVisitor {
311311

312312
/// Handle an owned dependent value, such as a closure capture or owned mark_dependence.
313313
///
314+
/// Called by walkDownUses(of:) for owned values.
315+
///
314316
/// When a borrow introduces an owned value, each OSSA lifetime is effectively a separate borrow scope. A destroy or
315317
/// consumes ends that borrow scope, while a forwarding consume effectively "reborrows".
318+
///
319+
/// %dependent = mark_dependence [nonescaping] %owned on %base // borrow 'owned'
320+
/// // visit uses of owned 'dependent' value
321+
/// %forwarded = move_value %dependent
322+
/// destroy_value %forwarded // ends the inner borrow scope
316323
///
317324
/// Preconditions:
318325
/// - value.ownership == .owned
319326
/// - value.type.isEscapable
320-
mutating func visitDependentUses(of value: Value) -> WalkResult {
327+
mutating func visitOwnedDependentUses(of value: Value) -> WalkResult {
321328
assert(value.ownership == .owned, "inner value must be a reborrow or owned forward")
322329
assert(value.type.isEscapable(in: value.parentFunction), "cannot handle non-escapable dependent values")
323330
return value.uses.endingLifetime.walk {
@@ -332,8 +339,13 @@ extension OwnershipUseVisitor {
332339
}
333340
}
334341

335-
// Visit uses of borrowing instruction (operandOwnerhip == .borrow),
336-
// skipping uses within the borrow scope.
342+
/// Visit uses of borrowing instruction (operandOwnerhip == .borrow),
343+
/// skipping uses within the borrow scope.
344+
///
345+
/// %borrow = begin_borrow %def // visitInnerBorrowUses is called on this BorrowingInstruction
346+
/// %address = ref_element_addr %borrow // ignored
347+
/// end_borrow %borrow // visited as a leaf use of as inner lifetime.
348+
///
337349
mutating func visitInnerBorrowUses(of borrowInst: BorrowingInstruction, operand: Operand) -> WalkResult {
338350
if let dependent = borrowInst.dependentValue {
339351
if dependent.ownership == .guaranteed {
@@ -743,8 +755,9 @@ extension InteriorUseWalker {
743755
if handleInner(borrowed: value) == .abortWalk {
744756
return .abortWalk
745757
}
746-
return visitDependentUses(of: value)
758+
return visitOwnedDependentUses(of: value)
747759
case .guaranteed:
760+
// Handle a forwarded guaranteed value exactly like the outer borrow.
748761
return visitAllUses(of: value)
749762
default:
750763
fatalError("ownership requires a lifetime")

0 commit comments

Comments
 (0)