@@ -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
- /// - `visitInnerScopeUses (of: Value)`
203
+ /// - `visitDependentUses (of: Value)`
204
204
///
205
205
/// Visitors implement:
206
206
///
@@ -210,12 +210,9 @@ struct InteriorLivenessResult: CustomDebugStringConvertible {
210
210
/// - pointerEscapingUse(of:)
211
211
/// - dependentUse(of:into:)
212
212
/// - borrowingUse(of:by:)
213
- /// - reborrowingUse(of:isInnerlifetime:)
214
213
///
215
- /// This only visits the first level of uses. The implementation may
216
- /// transitively visit forwarding operations in its implementation of
217
- /// `forwardingUse(of:isInnerlifetime:)` and
218
- /// `reborrowingUse(of:isInnerlifetime:)`.
214
+ /// This only visits the first level of uses. The implementation may transitively visit forwarded, borrowed, dependent,
215
+ /// or address values in the overrides listed above.
219
216
///
220
217
/// `isInnerlifetime` indicates whether the value being used is
221
218
/// defined by the "outer" OSSA lifetime or an inner borrow scope.
@@ -275,16 +272,7 @@ protocol OwnershipUseVisitor {
275
272
mutating func dependentUse( of operand: Operand , into value: Value ) -> WalkResult
276
273
277
274
/// A use that is scoped to an inner borrow scope.
278
- ///
279
- /// Call `visitInnerScopeUses(of:)` to recursively classify any
280
- /// scope-ending uses and forwarded dependent values.
281
275
mutating func borrowingUse( of operand: Operand , by borrowInst: BorrowingInstruction ) -> WalkResult
282
-
283
- /// A reborrow operand.
284
- ///
285
- /// Call `visitInnerBorrowUses(of:)` or `visitInnerScopeUses(of:)` to recursively classify scope-ending uses (such as
286
- /// reborrow and end_borrow).
287
- mutating func reborrowingUse( of operand: Operand , isInnerLifetime: Bool ) -> WalkResult
288
276
}
289
277
290
278
extension OwnershipUseVisitor {
@@ -321,31 +309,17 @@ extension OwnershipUseVisitor {
321
309
}
322
310
}
323
311
324
- /// Visit only those uses of a value within an inner borrow scope that may affect the outer lifetime. An inner borrow
325
- /// scope is one in which the borrowing operand is itself a use of the outer lifetime, including: begin_borrow,
326
- /// reborrow, borrowed_from, partial_apply, mark_dependence, or an inner adjacent phi (where original SSA def is a phi
327
- /// in the same block).
312
+ /// Handle an owned dependent value, such as a closure capture or owned mark_dependence.
328
313
///
329
- /// An owned lifetime may also be considered an inner borrow scope if it depends on a borrowed operand, such as a
330
- /// closure capture or owned mark_dependence .
314
+ /// When a borrow introduces an owned value, each OSSA lifetime is effectively a separate borrow scope. A destroy or
315
+ /// consumes ends that borrow scope, while a forwarding consume effectively "reborrows" .
331
316
///
332
- /// Precondition: BeginBorrowValue(value) != nil || value.ownership == .owned
333
- mutating func visitInnerScopeUses( of value: Value ) -> WalkResult {
334
- if let beginBorrow = BeginBorrowValue ( value) {
335
- return beginBorrow. scopeEndingOperands. walk {
336
- switch $0. ownership {
337
- case . endBorrow:
338
- return ownershipLeafUse ( of: $0, isInnerLifetime: true )
339
- case . reborrow:
340
- return reborrowingUse ( of: $0, isInnerLifetime: true )
341
- default :
342
- fatalError ( " invalid borrow scope ending operand ownership " )
343
- }
344
- }
345
- }
346
- // When a borrow introduces an owned value, each OSSA lifetime is effectively a separate borrow scope. A destroy
347
- // ends the borrow scope, while a forwarding consume effectively "reborrows".
317
+ /// Preconditions:
318
+ /// - value.ownership == .owned
319
+ /// - value.type.isEscapable
320
+ mutating func visitDependentUses( of value: Value ) -> WalkResult {
348
321
assert ( value. ownership == . owned, " inner value must be a reborrow or owned forward " )
322
+ assert ( value. type. isEscapable ( in: value. parentFunction) , " cannot handle non-escapable dependent values " )
349
323
return value. uses. endingLifetime. walk {
350
324
switch $0. ownership {
351
325
case . forwardingConsume:
@@ -361,10 +335,6 @@ extension OwnershipUseVisitor {
361
335
// Visit uses of borrowing instruction (operandOwnerhip == .borrow),
362
336
// skipping uses within the borrow scope.
363
337
mutating func visitInnerBorrowUses( of borrowInst: BorrowingInstruction , operand: Operand ) -> WalkResult {
364
- // Delegate begin_borrow to visitInnerScopeUses, because it dispatches to reborrowingUse.
365
- if let beginBorrow = BeginBorrowValue ( resultOf: borrowInst) {
366
- return visitInnerScopeUses ( of: beginBorrow. value)
367
- }
368
338
if let dependent = borrowInst. dependentValue {
369
339
if dependent. ownership == . guaranteed {
370
340
return visitAllUses ( of: dependent)
@@ -433,12 +403,9 @@ extension OwnershipUseVisitor {
433
403
}
434
404
return pointerEscapingUse ( of: operand)
435
405
436
- case . instantaneousUse, . forwardingUnowned, . unownedInstantaneousUse, . bitwiseEscape, . endBorrow:
406
+ case . instantaneousUse, . forwardingUnowned, . unownedInstantaneousUse, . bitwiseEscape, . endBorrow, . reborrow :
437
407
return ownershipLeafUse ( of: operand, isInnerLifetime: false )
438
408
439
- case . reborrow:
440
- return reborrowingUse ( of: operand, isInnerLifetime: false )
441
-
442
409
case . guaranteedForwarding:
443
410
return forwardingUse ( of: operand, isInnerLifetime: false )
444
411
@@ -647,13 +614,6 @@ extension InteriorUseWalker: OwnershipUseVisitor {
647
614
}
648
615
return visitInnerBorrowUses ( of: borrowInst, operand: operand)
649
616
}
650
-
651
- // Visit a reborrow operand. This ends an outer lifetime and extends
652
- // an inner lifetime.
653
- mutating func reborrowingUse( of operand: Operand , isInnerLifetime: Bool )
654
- -> WalkResult {
655
- return isInnerLifetime ? walkDown ( operand: operand) : useVisitor ( operand)
656
- }
657
617
}
658
618
659
619
extension InteriorUseWalker : AddressUseVisitor {
@@ -783,7 +743,7 @@ extension InteriorUseWalker {
783
743
if handleInner ( borrowed: value) == . abortWalk {
784
744
return . abortWalk
785
745
}
786
- return visitInnerScopeUses ( of: value)
746
+ return visitDependentUses ( of: value)
787
747
case . guaranteed:
788
748
return visitAllUses ( of: value)
789
749
default :
0 commit comments