Skip to content

Commit fdab5f2

Browse files
committed
Comment the getForwardingOwnership() API.
I was badly confused for a while.
1 parent ca0f638 commit fdab5f2

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

include/swift/SIL/SILInstruction.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,16 @@ class OwnershipForwardingMixin {
10251025
}
10261026

10271027
public:
1028+
/// Forwarding ownership is determined by the forwarding instruction's
1029+
/// constant ownership attribute. If forwarding ownership is owned, then the
1030+
/// instruction moves an owned operand to its result, ending its lifetime. If
1031+
/// forwarding ownership is guaranteed, then the instruction propagates the
1032+
/// lifetime of its borrows operand through its result.
1033+
///
1034+
/// The resulting forwarded value's ownership, returned by getOwnershipKind(),
1035+
/// is not identical to the forwarding ownership. It differs when the result
1036+
/// is trivial type. e.g. an owned or guaranteed value can be cast to a
1037+
/// trivial type using owned or guaranteed forwarding.
10281038
ValueOwnershipKind getForwardingOwnershipKind() const {
10291039
return ownershipKind;
10301040
}

include/swift/SIL/SILValue.h

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -880,15 +880,20 @@ inline bool canAcceptUnownedValue(OperandOwnership operandOwnership) {
880880
}
881881
}
882882

883-
/// Return the OperandOwnership for a forwarded operand when the forwarded
884-
/// result has this ValueOwnershipKind. \p allowUnowned is true for a subset
885-
/// of forwarding operations that are allowed to propagate Unowned values.
883+
/// Return the OperandOwnership for a forwarded operand when the forwarding
884+
/// operation has this "forwarding ownership" (as returned by
885+
/// getForwardingOwnershipKind()). \p allowUnowned is true for a subset of
886+
/// forwarding operations that are allowed to propagate Unowned values.
886887
///
887-
/// The ownership of a forwarded value is derived from the forwarding
888-
/// instruction's constant ownership attribute. If the result is owned, then the
889-
/// instruction moves owned operand to its result, ending its lifetime. If the
890-
/// result is guaranteed value, then the instruction propagates the lifetime of
891-
/// its borrows operand through its result.
888+
/// Forwarding ownership is determined by the forwarding instruction's constant
889+
/// ownership attribute. If forwarding ownership is owned, then the instruction
890+
/// moves owned operand to its result, ending its lifetime. If forwarding
891+
/// ownership is guaranteed, then the instruction propagates the lifetime of its
892+
/// borrows operand through its result.
893+
///
894+
/// The resulting forwarded value typically has forwarding ownership, but may
895+
/// differ when the result is trivial type. e.g. an owned or guaranteed value
896+
/// can be cast to a trivial type using owned or guaranteed forwarding.
892897
inline OperandOwnership
893898
ValueOwnershipKind::getForwardingOperandOwnership(bool allowUnowned) const {
894899
switch (value) {

0 commit comments

Comments
 (0)