Skip to content

Commit 0bc5651

Browse files
committed
Fix OwnershipUseVisitor.dependentUse()
Check if the forwarded value is trivial, not the base value. Presumably, we won't call this visitor at all if the base is trivial. Record a dependent non-Escapable values as a pointer-escape. InteriorUseWalker does not handle lifetime dependencies. That requires LifetimeDependenceDefUseWalker.
1 parent d207b34 commit 0bc5651

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/OwnershipLiveness.swift

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -602,32 +602,24 @@ extension InteriorUseWalker: OwnershipUseVisitor {
602602
return .abortWalk
603603
}
604604
return walkDownAddressUses(of: address)
605-
}
605+
}
606606

607607
// Handle partial_apply [on_stack] and mark_dependence [nonescaping].
608-
//
609-
// TODO: Rather than walking down the owned uses, this could call
610-
// visitInnerScopeUses, but we need to ensure all dependent values
611-
// are complete first:
612-
//
613-
// if let svi = borrowInst as! SingleValueInstruction,
614-
// svi.ownership == .owned {
615-
// if handleInner(borrowed: beginBorrow.value) == .abortWalk {
616-
// return .abortWalk
617-
// }
618-
// return visitInnerScopeUses(of: borrowInst)
619-
// }
620-
mutating func dependentUse(of operand: Operand, into value: Value)
621-
-> WalkResult {
608+
mutating func dependentUse(of operand: Operand, into value: Value) -> WalkResult {
622609
// OSSA lifetime ignores trivial types.
623-
if operand.value.type.isTrivial(in: function) {
610+
if value.type.isTrivial(in: function) {
624611
return .continueWalk
625612
}
613+
guard value.type.isEscapable(in: function) else {
614+
// Non-escapable dependent values can be lifetime-extended by copying, which is not handled by
615+
// InteriorUseWalker. LifetimeDependenceDefUseWalker does this.
616+
return pointerEscapingUse(of: operand)
617+
}
626618
if useVisitor(operand) == .abortWalk {
627619
return .abortWalk
628620
}
629621
return walkDownUses(of: value)
630-
}
622+
}
631623

632624
mutating func pointerEscapingUse(of operand: Operand) -> WalkResult {
633625
if useVisitor(operand) == .abortWalk {

0 commit comments

Comments
 (0)