Skip to content

Commit 6c99017

Browse files
committed
Minor comment cleanup and code formatting.
Extracted from the functional changes for clarity.
1 parent 75e84f1 commit 6c99017

File tree

4 files changed

+27
-44
lines changed

4 files changed

+27
-44
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/AddressUtils.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,8 @@ extension AddressOwnershipLiveRange {
554554
///
555555
/// For address values, use AccessBase.computeOwnershipRange.
556556
///
557-
/// FIXME: This should use computeLinearLiveness rather than computeKnownLiveness as soon as lifetime completion
558-
/// runs immediately after SILGen.
557+
/// FIXME: This should use computeLinearLiveness rather than computeKnownLiveness as soon as complete OSSA lifetimes
558+
/// are verified.
559559
private static func computeValueLiveRange(of value: Value, _ context: FunctionPassContext)
560560
-> AddressOwnershipLiveRange? {
561561
switch value.ownership {

SwiftCompilerSources/Sources/Optimizer/Utilities/BorrowUtils.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,11 @@ import SIL
134134

135135
/// A scoped instruction that borrows one or more operands.
136136
///
137-
/// If this instruction produces a borrowed value, then
138-
/// BeginBorrowValue(resultOf: self) != nil.
137+
/// If this instruction produces a borrowed value, then BeginBorrowValue(resultOf: self) != nil.
139138
///
140-
/// This does not include instructions like `apply` and `try_apply` that
141-
/// instantaneously borrow a value from the caller.
139+
/// This does not include instructions like `apply` and `try_apply` that instantaneously borrow a value from the caller.
142140
///
143-
/// This does not include `load_borrow` because it borrows a memory
144-
/// location, not the value of its operand.
141+
/// This does not include `load_borrow` because it borrows a memory location, not the value of its operand.
145142
///
146143
/// Note: This must handle all instructions with a .borrow operand ownership.
147144
///

SwiftCompilerSources/Sources/Optimizer/Utilities/OwnershipLiveness.swift

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ struct InteriorLivenessResult: CustomDebugStringConvertible {
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: BorrowingInstruction)`
207+
/// - `visitInnerBorrowUses(of: BorrowingInstruction, operand:)`
208208
/// - `visitInnerScopeUses(of: Value)`
209209
///
210210
/// Visitors implement:
@@ -251,21 +251,18 @@ protocol OwnershipUseVisitor {
251251
/// `isInnerLifetime` indicates whether `operand` uses the original
252252
/// OSSA lifetime. This use ends the original lifetime if
253253
/// (!isInnerLifetime && use.endsLifetime).
254-
mutating func ownershipLeafUse(of operand: Operand, isInnerLifetime: Bool)
255-
-> WalkResult
254+
mutating func ownershipLeafUse(of operand: Operand, isInnerLifetime: Bool) -> WalkResult
256255

257256
/// A forwarding operand.
258257
///
259258
/// Use ForwardingInstruction or ForwardingDefUseWalker to handle
260259
/// downstream uses.
261260
///
262261
/// If `isInnerLifetime` is true, then the value depends on an inner borrow.
263-
mutating func forwardingUse(of operand: Operand, isInnerLifetime: Bool)
264-
-> WalkResult
262+
mutating func forwardingUse(of operand: Operand, isInnerLifetime: Bool) -> WalkResult
265263

266264
/// A use that projects an address.
267-
mutating func interiorPointerUse(of: Operand, into address: Value)
268-
-> WalkResult
265+
mutating func interiorPointerUse(of: Operand, into address: Value) -> WalkResult
269266

270267
/// A use that escapes information from its operand's value.
271268
///
@@ -280,22 +277,19 @@ protocol OwnershipUseVisitor {
280277
/// there are no explicit scope-ending operations. Instead
281278
/// BorrowingInstruction.scopeEndingOperands will return the final
282279
/// consumes in the dependent value's forwarding chain.
283-
mutating func dependentUse(of operand: Operand, into value: Value)
284-
-> WalkResult
280+
mutating func dependentUse(of operand: Operand, into value: Value) -> WalkResult
285281

286282
/// A use that is scoped to an inner borrow scope.
287283
///
288284
/// Call `visitInnerScopeUses(of:)` to recursively classify any
289285
/// scope-ending uses and forwarded dependent values.
290-
mutating func borrowingUse(of operand: Operand,
291-
by borrowInst: BorrowingInstruction) -> WalkResult
286+
mutating func borrowingUse(of operand: Operand, by borrowInst: BorrowingInstruction) -> WalkResult
292287

293288
/// A reborrow operand.
294289
///
295-
/// Call `visitInnerScopeUses()` to recursively classify scope-ending
296-
/// uses (reborrow and end_borrow).
297-
mutating func reborrowingUse(of operand: Operand, isInnerLifetime: Bool)
298-
-> WalkResult
290+
/// Call `visitInnerBorrowUses(of:)` or `visitInnerScopeUses(of:)` to recursively classify scope-ending uses (such as
291+
/// reborrow and end_borrow).
292+
mutating func reborrowingUse(of operand: Operand, isInnerLifetime: Bool) -> WalkResult
299293
}
300294

301295
extension OwnershipUseVisitor {
@@ -320,7 +314,7 @@ extension OwnershipUseVisitor {
320314
/// adjacent phis and treat them like inner borrows.
321315
///
322316
/// This is only called for uses in the outer lifetime.
323-
mutating func visitAllUses(of: Value) -> WalkResult {
317+
mutating func visitAllUses(of value: Value) -> WalkResult {
324318
switch value.ownership {
325319
case .owned:
326320
return value.uses.ignoreTypeDependence.walk { classifyOwned(operand: $0) }
@@ -351,11 +345,9 @@ extension OwnershipUseVisitor {
351345
}
352346
}
353347
}
354-
// When a borrow introduces an owned value, each OSSA lifetime is
355-
// effectively a separate borrow scope. A destroy ends the borrow
356-
// scope, while a forwarding consume effectively "reborrows".
357-
assert(value.ownership == .owned,
358-
"inner value must be a reborrow or owned forward")
348+
// When a borrow introduces an owned value, each OSSA lifetime is effectively a separate borrow scope. A destroy
349+
// ends the borrow scope, while a forwarding consume effectively "reborrows".
350+
assert(value.ownership == .owned, "inner value must be a reborrow or owned forward")
359351
return value.uses.endingLifetime.walk {
360352
switch $0.ownership {
361353
case .forwardingConsume:
@@ -370,16 +362,14 @@ extension OwnershipUseVisitor {
370362

371363
// Visit uses of borrowing instruction (operandOwnerhip == .borrow),
372364
// skipping uses within the borrow scope.
373-
mutating func visitInnerScopeUses(of borrowInst: BorrowingInstruction)
374-
-> WalkResult {
375-
// If a borrowed value is introduced, then handle the inner scope.
365+
mutating func visitInnerBorrowUses(of borrowInst: BorrowingInstruction, operand: Operand) -> WalkResult {
366+
// Delegate begin_borrow to visitInnerScopeUses, because it dispatches to reborrowingUse.
376367
if let beginBorrow = BeginBorrowValue(resultOf: borrowInst) {
377368
return visitInnerScopeUses(of: beginBorrow.value)
378369
}
379-
// Otherwise, directly visit the scope ending uses.
370+
// Otherwise, directly visit the scope ending uses as leaf uses.
380371
//
381-
// TODO: remove this stack by changign visitScopeEndingOperands to
382-
// take a non-escaping closure that can call ownershipLeafUse.
372+
// TODO: remove this stack by changing visitScopeEndingOperands to take a non-escaping closure.
383373
var stack = Stack<Operand>(context)
384374
defer { stack.deinitialize() }
385375
_ = borrowInst.visitScopeEndingOperands(context) {
@@ -406,8 +396,7 @@ extension OwnershipUseVisitor {
406396
case .pointerEscape:
407397
return pointerEscapingUse(of: operand)
408398

409-
case .instantaneousUse, .forwardingUnowned, .unownedInstantaneousUse,
410-
.bitwiseEscape:
399+
case .instantaneousUse, .forwardingUnowned, .unownedInstantaneousUse, .bitwiseEscape:
411400
return ownershipLeafUse(of: operand, isInnerLifetime: false)
412401

413402
case .borrow:
@@ -436,8 +425,7 @@ extension OwnershipUseVisitor {
436425
}
437426
return pointerEscapingUse(of: operand)
438427

439-
case .instantaneousUse, .forwardingUnowned, .unownedInstantaneousUse,
440-
.bitwiseEscape, .endBorrow:
428+
case .instantaneousUse, .forwardingUnowned, .unownedInstantaneousUse, .bitwiseEscape, .endBorrow:
441429
return ownershipLeafUse(of: operand, isInnerLifetime: false)
442430

443431
case .reborrow:
@@ -457,8 +445,7 @@ extension OwnershipUseVisitor {
457445
}
458446
}
459447

460-
private mutating func visitBorrowingUse(of operand: Operand)
461-
-> WalkResult {
448+
private mutating func visitBorrowingUse(of operand: Operand) -> WalkResult {
462449
switch operand.instruction {
463450
case let pai as PartialApplyInst:
464451
assert(!pai.mayEscape)
@@ -472,8 +459,7 @@ extension OwnershipUseVisitor {
472459
}
473460
}
474461

475-
private mutating func visitInteriorPointerUse(of operand: Operand)
476-
-> WalkResult {
462+
private mutating func visitInteriorPointerUse(of operand: Operand) -> WalkResult {
477463
switch operand.instruction {
478464
case is RefTailAddrInst, is RefElementAddrInst, is ProjectBoxInst,
479465
is OpenExistentialBoxInst:

include/swift/SIL/OwnershipUseVisitor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ bool OwnershipUseVisitor<Impl>::visitInnerBorrowScopeEnd(Operand *borrowEnd) {
326326
// partial_apply [on_stack] and mark_dependence [nonescaping] can introduce
327327
// borrowing operand and can have destroy_value, return, or store consumes.
328328
//
329-
// TODO: When we have a C++ ForwardingUseDefWalker, walk the def-use
329+
// TODO: When we have a C++ ForwardingUseDefWalker, walk the use-def
330330
// chain to ensure we have a partial_apply [on_stack] or mark_dependence
331331
// [nonescaping] def.
332332
return handleUsePoint(borrowEnd, UseLifetimeConstraint::NonLifetimeEnding);

0 commit comments

Comments
 (0)