@@ -194,7 +194,7 @@ struct InteriorLivenessResult: CustomDebugStringConvertible {
194
194
///
195
195
/// The top-level entry points are:
196
196
/// - `classify(operand:)`
197
- /// - `visitAllUses (of:)`
197
+ /// - `visitOwnershipUses (of:)`
198
198
///
199
199
/// The implementation may recursively call back to the top-level
200
200
/// entry points. Additionally, the implementation may recurse into inner
@@ -217,7 +217,7 @@ struct InteriorLivenessResult: CustomDebugStringConvertible {
217
217
/// `isInnerlifetime` indicates whether the value being used is
218
218
/// defined by the "outer" OSSA lifetime or an inner borrow scope.
219
219
/// When the OwnershipUseVisitor is invoked on an outer value
220
- /// (visitAllUses (of:)), it visits all the uses of that value
220
+ /// (visitOwnershipUses (of:)), it visits all the uses of that value
221
221
/// and also visits the lifetime-ending uses of any inner borrow
222
222
/// scopes. This provides a complete set of liveness "use points":
223
223
///
@@ -297,7 +297,7 @@ extension OwnershipUseVisitor {
297
297
/// adjacent phis and treat them like inner borrows.
298
298
///
299
299
/// This is only called for uses in the outer lifetime.
300
- mutating func visitAllUses ( of value: Value ) -> WalkResult {
300
+ mutating func visitOwnershipUses ( of value: Value ) -> WalkResult {
301
301
switch value. ownership {
302
302
case . owned:
303
303
return value. uses. ignoreTypeDependence. walk { classifyOwned ( operand: $0) }
@@ -349,7 +349,7 @@ extension OwnershipUseVisitor {
349
349
mutating func visitInnerBorrowUses( of borrowInst: BorrowingInstruction , operand: Operand ) -> WalkResult {
350
350
if let dependent = borrowInst. dependentValue {
351
351
if dependent. ownership == . guaranteed {
352
- return visitAllUses ( of: dependent)
352
+ return visitOwnershipUses ( of: dependent)
353
353
}
354
354
return pointerEscapingUse ( of: operand)
355
355
}
@@ -544,7 +544,7 @@ struct InteriorUseWalker {
544
544
}
545
545
546
546
mutating func visitUses( ) -> WalkResult {
547
- return visitAllUses ( of: definingValue)
547
+ return visitOwnershipUses ( of: definingValue)
548
548
}
549
549
}
550
550
@@ -624,13 +624,21 @@ extension InteriorUseWalker: OwnershipUseVisitor {
624
624
if useVisitor ( operand) == . abortWalk {
625
625
return . abortWalk
626
626
}
627
- if visitInnerUses {
628
- guard let innerValue = borrowInst. innerValue else {
629
- return setPointerEscape ( of: operand)
630
- }
631
- return visitAllUses ( of: innerValue)
627
+ if visitInnerBorrowUses ( of: borrowInst, operand: operand) == . abortWalk {
628
+ return . abortWalk
629
+ }
630
+ if !visitInnerUses {
631
+ return . continueWalk
632
+ }
633
+ guard let innerValue = borrowInst. innerValue else {
634
+ return setPointerEscape ( of: operand)
635
+ }
636
+ // Call visitInnerBorrowUses before visitOwnershipUses because it will visit uses of tokens, such as
637
+ // the begin_apply token, which don't have ownership.
638
+ if innerValue. type. isAddress {
639
+ return interiorPointerUse ( of: operand, into: innerValue)
632
640
}
633
- return visitInnerBorrowUses ( of: borrowInst , operand : operand )
641
+ return visitOwnershipUses ( of: innerValue )
634
642
}
635
643
}
636
644
@@ -764,7 +772,7 @@ extension InteriorUseWalker {
764
772
return visitOwnedDependentUses ( of: value)
765
773
case . guaranteed:
766
774
// Handle a forwarded guaranteed value exactly like the outer borrow.
767
- return visitAllUses ( of: value)
775
+ return visitOwnershipUses ( of: value)
768
776
default :
769
777
fatalError ( " ownership requires a lifetime " )
770
778
}
0 commit comments