Skip to content

Commit 75e84f1

Browse files
committed
Rename InteriorLiveness methods for clarity.
It was too easy to confuse the "inner" vs. "outer" value. Use less ambigous names: visitAllUses vs visitInnerScopeUses
1 parent 14dd14d commit 75e84f1

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/OwnershipLiveness.swift

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,13 @@ struct InteriorLivenessResult: CustomDebugStringConvertible {
199199
///
200200
/// The top-level entry points are:
201201
/// - `classify(operand:)`
202-
/// - `visitUsesOfOuter(value:)`
202+
/// - `visitAllUses(of:)`
203203
///
204204
/// The implementation may recursively call back to the top-level
205205
/// entry points. Additionally, the implementation may recurse into inner
206206
/// borrow scopes, skipping over the uses within inner scopes using:
207-
/// - `visitInnerBorrowUses(of:)`
208-
/// - `visitUsesOfInner(value:)`
207+
/// - `visitInnerBorrowUses(of: BorrowingInstruction)`
208+
/// - `visitInnerScopeUses(of: Value)`
209209
///
210210
/// Visitors implement:
211211
///
@@ -225,7 +225,7 @@ struct InteriorLivenessResult: CustomDebugStringConvertible {
225225
/// `isInnerlifetime` indicates whether the value being used is
226226
/// defined by the "outer" OSSA lifetime or an inner borrow scope.
227227
/// When the OwnershipUseVisitor is invoked on an outer value
228-
/// (visitUsesOfOuter(value:)), it visits all the uses of that value
228+
/// (visitAllUses(of:)), it visits all the uses of that value
229229
/// and also visits the lifetime-ending uses of any inner borrow
230230
/// scopes. This provides a complete set of liveness "use points":
231231
///
@@ -285,14 +285,14 @@ protocol OwnershipUseVisitor {
285285

286286
/// A use that is scoped to an inner borrow scope.
287287
///
288-
/// Call `visitInnerBorrowUses(of:)` to recursively classify any
288+
/// Call `visitInnerScopeUses(of:)` to recursively classify any
289289
/// scope-ending uses and forwarded dependent values.
290290
mutating func borrowingUse(of operand: Operand,
291291
by borrowInst: BorrowingInstruction) -> WalkResult
292292

293293
/// A reborrow operand.
294294
///
295-
/// Call `visitUsesOfInner()` to recursively classify scope-ending
295+
/// Call `visitInnerScopeUses()` to recursively classify scope-ending
296296
/// uses (reborrow and end_borrow).
297297
mutating func reborrowingUse(of operand: Operand, isInnerLifetime: Bool)
298298
-> WalkResult
@@ -320,7 +320,7 @@ extension OwnershipUseVisitor {
320320
/// adjacent phis and treat them like inner borrows.
321321
///
322322
/// This is only called for uses in the outer lifetime.
323-
mutating func visitUsesOfOuter(value: Value) -> WalkResult {
323+
mutating func visitAllUses(of: Value) -> WalkResult {
324324
switch value.ownership {
325325
case .owned:
326326
return value.uses.ignoreTypeDependence.walk { classifyOwned(operand: $0) }
@@ -338,7 +338,7 @@ extension OwnershipUseVisitor {
338338
/// lifetime, including: begin_borrow, reborrow, partial_apply,
339339
/// mark_dependence, or an inner adjacent phi (where original SSA
340340
/// def is a phi in the same block).
341-
mutating func visitUsesOfInner(value: Value) -> WalkResult {
341+
mutating func visitInnerScopeUses(of: Value) -> WalkResult {
342342
if let beginBorrow = BeginBorrowValue(value) {
343343
return beginBorrow.scopeEndingOperands.walk {
344344
switch $0.ownership {
@@ -370,11 +370,11 @@ extension OwnershipUseVisitor {
370370

371371
// Visit uses of borrowing instruction (operandOwnerhip == .borrow),
372372
// skipping uses within the borrow scope.
373-
mutating func visitInnerBorrowUses(of borrowInst: BorrowingInstruction)
373+
mutating func visitInnerScopeUses(of borrowInst: BorrowingInstruction)
374374
-> WalkResult {
375375
// If a borrowed value is introduced, then handle the inner scope.
376376
if let beginBorrow = BeginBorrowValue(resultOf: borrowInst) {
377-
return visitUsesOfInner(value: beginBorrow.value)
377+
return visitInnerScopeUses(of: beginBorrow.value)
378378
}
379379
// Otherwise, directly visit the scope ending uses.
380380
//
@@ -578,17 +578,17 @@ struct InteriorUseWalker {
578578
if handleInner(borrowed: innerPhi.value) == .abortWalk {
579579
return .abortWalk
580580
}
581-
return visitUsesOfInner(value: innerPhi.value)
581+
return visitInnerScopeUses(of: innerPhi.value)
582582
} else {
583583
// Inner adjacent guaranteed phis are uses of the outer borrow.
584-
return visitUsesOfOuter(value: innerPhi.value)
584+
return visitAllUses(of: innerPhi.value)
585585
}
586586
}
587587
if result == .abortWalk {
588588
return .abortWalk
589589
}
590590
}
591-
return visitUsesOfOuter(value: definingValue)
591+
return visitAllUses(of: definingValue)
592592
}
593593
}
594594

@@ -636,15 +636,15 @@ extension InteriorUseWalker: OwnershipUseVisitor {
636636
// Handle partial_apply [on_stack] and mark_dependence [nonescaping].
637637
//
638638
// TODO: Rather than walking down the owned uses, this could call
639-
// visitInnerBorrowUses, but we need to ensure all dependent values
639+
// visitInnerScopeUses, but we need to ensure all dependent values
640640
// are complete first:
641641
//
642642
// if let svi = borrowInst as! SingleValueInstruction,
643643
// svi.ownership == .owned {
644644
// if handleInner(borrowed: beginBorrow.value) == .abortWalk {
645645
// return .abortWalk
646646
// }
647-
// return visitInnerBorrowUses(of: borrowInst)
647+
// return visitInnerScopeUses(of: borrowInst)
648648
// }
649649
mutating func dependentUse(of operand: Operand, into value: Value)
650650
-> WalkResult {
@@ -667,18 +667,16 @@ extension InteriorUseWalker: OwnershipUseVisitor {
667667
}
668668

669669
// Call the innerScopeHandler before visiting the scope-ending uses.
670-
mutating func borrowingUse(of operand: Operand,
671-
by borrowInst: BorrowingInstruction)
672-
-> WalkResult {
670+
mutating func borrowingUse(of operand: Operand, by borrowInst: BorrowingInstruction) -> WalkResult {
673671
if let beginBorrow = BeginBorrowValue(resultOf: borrowInst) {
674672
if handleInner(borrowed: beginBorrow.value) == .abortWalk {
675673
return .abortWalk
676674
}
677675
if visitInnerUses {
678-
return visitUsesOfOuter(value: beginBorrow.value)
676+
return visitAllUses(of: beginBorrow.value)
679677
}
680678
}
681-
return visitInnerBorrowUses(of: borrowInst)
679+
return visitInnerScopeUses(of: borrowInst)
682680
}
683681

684682
// Visit a reborrow operand. This ends an outer lifetime and extends
@@ -824,9 +822,9 @@ extension InteriorUseWalker {
824822
}
825823
switch value.ownership {
826824
case .owned:
827-
return visitUsesOfInner(value: value)
825+
return visitInnerScopeUses(of: value)
828826
case .guaranteed:
829-
return visitUsesOfOuter(value: value)
827+
return visitAllUses(of: value)
830828
default:
831829
fatalError("ownership requires a lifetime")
832830
}
@@ -899,9 +897,9 @@ extension InteriorUseWalker {
899897
// Since definingValue dominates guaranteedPhi, this is a well-formed linear
900898
// lifetime, and liveness can proceed.
901899
if guaranteedPhi.isReborrow {
902-
return visitUsesOfInner(value: guaranteedPhi.value)
900+
return visitInnerScopeUses(of: guaranteedPhi.value)
903901
} else {
904-
return visitUsesOfOuter(value: guaranteedPhi.value)
902+
return visitAllUses(of: guaranteedPhi.value)
905903
}
906904
}
907905
}

0 commit comments

Comments
 (0)