@@ -200,7 +200,7 @@ struct InteriorLivenessResult: CustomDebugStringConvertible {
200
200
/// entry points. Additionally, the implementation may recurse into inner
201
201
/// borrow scopes, skipping over the uses within inner scopes using:
202
202
/// - `visitInnerBorrowUses(of: BorrowingInstruction, operand:)`
203
- /// - `visitDependentUses (of: Value)`
203
+ /// - `visitOwnedDependentUses (of: Value)`
204
204
///
205
205
/// Visitors implement:
206
206
///
@@ -311,13 +311,20 @@ extension OwnershipUseVisitor {
311
311
312
312
/// Handle an owned dependent value, such as a closure capture or owned mark_dependence.
313
313
///
314
+ /// Called by walkDownUses(of:) for owned values.
315
+ ///
314
316
/// When a borrow introduces an owned value, each OSSA lifetime is effectively a separate borrow scope. A destroy or
315
317
/// 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
316
323
///
317
324
/// Preconditions:
318
325
/// - value.ownership == .owned
319
326
/// - value.type.isEscapable
320
- mutating func visitDependentUses ( of value: Value ) -> WalkResult {
327
+ mutating func visitOwnedDependentUses ( of value: Value ) -> WalkResult {
321
328
assert ( value. ownership == . owned, " inner value must be a reborrow or owned forward " )
322
329
assert ( value. type. isEscapable ( in: value. parentFunction) , " cannot handle non-escapable dependent values " )
323
330
return value. uses. endingLifetime. walk {
@@ -332,8 +339,13 @@ extension OwnershipUseVisitor {
332
339
}
333
340
}
334
341
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
+ ///
337
349
mutating func visitInnerBorrowUses( of borrowInst: BorrowingInstruction , operand: Operand ) -> WalkResult {
338
350
if let dependent = borrowInst. dependentValue {
339
351
if dependent. ownership == . guaranteed {
@@ -743,8 +755,9 @@ extension InteriorUseWalker {
743
755
if handleInner ( borrowed: value) == . abortWalk {
744
756
return . abortWalk
745
757
}
746
- return visitDependentUses ( of: value)
758
+ return visitOwnedDependentUses ( of: value)
747
759
case . guaranteed:
760
+ // Handle a forwarded guaranteed value exactly like the outer borrow.
748
761
return visitAllUses ( of: value)
749
762
default :
750
763
fatalError ( " ownership requires a lifetime " )
0 commit comments