Skip to content

Commit a3fe978

Browse files
committed
LifetimeDependenceUtils: handle borrowed ProjectBox
1 parent 5c956f7 commit a3fe978

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/LifetimeDependenceUtils.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func gatherVariableIntroducers(for value: Value, _ context: Context)
7575
return .continueWalk
7676
}
7777
defer { useDefVisitor.deinitialize() }
78-
_ = useDefVisitor.walkUp(value: value, nil)
78+
_ = useDefVisitor.walkUp(valueOrAddress: value)
7979
return introducers
8080
}
8181

@@ -330,7 +330,11 @@ extension LifetimeDependence.Scope {
330330
case let .base(accessBase):
331331
switch accessBase {
332332
case let .box(projectBox):
333-
self = .owned(projectBox.operand.value)
333+
// Note: the box may be in a borrow scope.
334+
if let scope = Self(base: projectBox.operand.value, context) {
335+
self = scope
336+
}
337+
return nil
334338
case let .stack(allocStack):
335339
if let scope = Self(allocation: allocStack, context) {
336340
self = scope
@@ -548,6 +552,9 @@ extension LifetimeDependence {
548552
/// that introduces an immutable variable: move_value [var_decl] or
549553
/// begin_borrow [var_decl], and to stop at an access of a mutable
550554
/// variable: begin_access.
555+
///
556+
/// Start walking:
557+
/// walkUp(valueOrAddress: Value) -> WalkResult
551558
struct VariableIntroducerUseDefWalker : LifetimeDependenceUseDefWalker {
552559
let context: Context
553560
// This visited set is only really needed for instructions with

0 commit comments

Comments
 (0)