Skip to content

Commit 24fa288

Browse files
committed
Comment OwnershipConstraints with respect to Unowned values.
1 parent 4678567 commit 24fa288

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

include/swift/SIL/SILValue.h

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
122122
/// information like knowledge of an enum case. Trivial values have no
123123
/// ownership semantics.
124124
///
125-
/// * OperandConstraint: This represents a constraint on the values that can be
126-
/// used by a specific operand. Here Any is valid and is used for operands
125+
/// * OwnershipConstraint: This represents a constraint on the values that can
126+
/// be used by a specific operand. Here Any is valid and is used for operands
127127
/// that don't care about the ownership kind (lack ownership constraints). In
128128
/// contrast, a constraint of None is the most restrictive. It requires a
129129
/// trivial value. An Unowned, Owned, or Guaranteed constraint requires either
@@ -588,6 +588,18 @@ inline bool ValueOwnershipKind::isCompatibleWith(SILValue other) const {
588588
return isCompatibleWith(other.getOwnershipKind());
589589
}
590590

591+
/// Constraints on the ownership of an operand value.
592+
///
593+
/// The ownershipKind component constrains the operand's value ownership to be
594+
/// the same or "above" the constraint in the lattice, such that
595+
/// join(constraint, valueOwnership) == valueOwnership. In other words, applying
596+
/// the constraint does not change the value's ownership. For example, a value
597+
/// with None ownership is accepted by any OwnershipConstraint, and an
598+
/// OwnershipConstraint with 'Any' ownership kind can accept any value. Note
599+
/// that operands commonly allow either Owned or Guaranteed operands. These
600+
/// operands have an Any ownership constraint to allow either. However,
601+
/// enforcement of Unowned value is more strict. This requires separate logic in
602+
/// canAcceptUnownedValue() to avoid complicating the OwnershipKind lattice.
591603
class OwnershipConstraint {
592604
OwnershipKind ownershipKind;
593605
UseLifetimeConstraint lifetimeConstraint;
@@ -746,6 +758,11 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
746758
const OperandOwnership &operandOwnership);
747759

748760
/// Defined inline so the switch is eliminated for constant OperandOwnership.
761+
///
762+
/// Here, an Any ownership constraint is used to allow either Owned or
763+
/// Guaranteed values. However, enforcement of Unowned values is more
764+
/// strict. This is handled by separate logic in canAcceptUnownedValue() to
765+
/// avoid complicating the OwnershipKind lattice.
749766
inline OwnershipConstraint OperandOwnership::getOwnershipConstraint() {
750767
switch (value) {
751768
case OperandOwnership::TrivialUse:

0 commit comments

Comments
 (0)