Skip to content

Commit 5e9e282

Browse files
committed
LifetimeDependenceUtils comment clarification and cleanup.
1 parent 95a100a commit 5e9e282

File tree

1 file changed

+19
-28
lines changed

1 file changed

+19
-28
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/LifetimeDependenceUtils.swift

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -530,13 +530,12 @@ extension LifetimeDependence {
530530
visitedValues.insert(value)
531531
}
532532

533-
// Visit the base value of a lifetime dependence. If the base is
534-
// an address, the dependence scope is the enclosing access. The
535-
// walker does not walk past an `mark_dependence [nonescaping]`
536-
// that produces an address, because that will never occur inside
537-
// of an access scope. An address type mark_dependence
538-
// [nonescaping]` can only result from an indirect function result
539-
// when opaque values are not enabled.
533+
// Visit the base value of a lifetime dependence. If the base is an address, the dependence scope is the enclosing
534+
// access. The walker does not walk past an `mark_dependence [nonescaping]` that produces an address, because that
535+
// will never occur inside of an access scope. An address type mark_dependence [unresolved]` can only result from an
536+
// indirect function result when opaque values are not enabled. Address type `mark_dependence [nonescaping]`
537+
// instruction are also produced for captured arguments but ClosureLifetimeFixup, but those aren't considered to
538+
// have a LifetimeDependence scope.
540539
mutating func introducer(_ value: Value, _ owner: Value?) -> WalkResult {
541540
let base = owner ?? value
542541
guard let scope = LifetimeDependence.Scope(base: base, context)
@@ -617,32 +616,24 @@ struct VariableIntroducerUseDefWalker : LifetimeDependenceUseDefWalker {
617616

618617
/// Walk up the lifetime dependence chain.
619618
///
620-
/// This finds the introducers of a dependence chain. which represent
621-
/// the value's "inherited" dependencies. This stops at phis; all
622-
/// introducers dominate. This stops at addresses in general, but if
623-
/// the value is loaded from a singly-initialized location, then it
624-
/// continues walking up the value stored by the initializer. This
619+
/// This finds the introducers of a dependence chain. which represent the value's "inherited" dependencies. This stops
620+
/// at phis, so all introducers dominate their dependencies. This stops at addresses in general, but if the value is
621+
/// loaded from a singly-initialized location, then it continues walking up the value stored by the initializer. This
625622
/// bypasses the copies to temporary memory locations emitted by SILGen.
626623
///
627-
/// In this example, the dependence root is
628-
/// copied, borrowed, and forwarded before being used as the base
629-
/// operand of `mark_dependence`. The dependence "root" is the parent
630-
/// of the outer-most dependence scope.
624+
/// In this example, the dependence root is copied, borrowed, and forwarded before being used as the base operand of
625+
/// `mark_dependence`. The dependence "root" is the parent of the outer-most dependence scope.
631626
///
632627
/// %root = apply // lifetime dependence root
633628
/// %copy = copy_value %root
634629
/// %parent = begin_borrow %copy // lifetime dependence parent value
635630
/// %base = struct_extract %parent // lifetime dependence base value
636631
/// %dependent = mark_dependence [nonescaping] %value on %base
637632
///
638-
/// This extends the ForwardingUseDefWalker, which finds the
639-
/// forward-extended lifetime introducers. Certain forward-extended
640-
/// lifetime introducers can inherit a lifetime dependency from their
641-
/// operand: namely copies, moves, and borrows. These introducers are
642-
/// considered part of their operand's dependence scope because
643-
/// non-escapable values can be copied, moved, and
644-
/// borrowed. Nonetheless, all of their uses must remain within
645-
/// original dependence scope.
633+
/// This extends the ForwardingUseDefWalker, which finds the forward-extended lifetime introducers. Certain
634+
/// forward-extended lifetime introducers can inherit a lifetime dependency from their operand: namely copies, moves,
635+
/// and borrows. These introducers are considered part of their operand's dependence scope because non-escapable values
636+
/// can be copied, moved, and borrowed. Nonetheless, all of their uses must remain within original dependence scope.
646637
///
647638
/// # owned lifetime dependence
648639
/// %parent = apply // begin dependence scope -+
@@ -662,10 +653,9 @@ struct VariableIntroducerUseDefWalker : LifetimeDependenceUseDefWalker {
662653
/// ... |
663654
/// destroy_value %parent // end dependence scope -+
664655
///
665-
/// All of the dependent uses including `end_borrow %5` and
666-
/// `destroy_value %4` must be before the end of the dependence scope:
667-
/// `destroy_value %parent`. In this case, the dependence parent is an
668-
/// owned value, so the scope is simply the value's OSSA lifetime.
656+
/// All of the dependent uses including `end_borrow %5` and `destroy_value %4` must be before the end of the dependence
657+
/// scope: `destroy_value %parent`. In this case, the dependence parent is an owned value, so the scope is simply the
658+
/// value's OSSA lifetime.
669659
///
670660
/// Minimal requirements:
671661
/// var context: Context
@@ -740,6 +730,7 @@ extension LifetimeDependenceUseDefWalker {
740730
if Phi(value) != nil {
741731
return introducer(value, owner)
742732
}
733+
// ForwardingUseDefWalker will callback to introducer() when it finds no forwarding instruction.
743734
return walkUpDefault(forwarded: value, owner)
744735
}
745736

0 commit comments

Comments
 (0)