Skip to content

Commit 5c88120

Browse files
authored
Merge pull request #34630 from gottesmm/pr-7615785dbc35f076a8c60b0e9a79fdd71a9632c4
[ownership] Rename the cases of UseLifetimeConstraint to use clearer language
2 parents a647f0f + 642a993 commit 5c88120

File tree

12 files changed

+181
-176
lines changed

12 files changed

+181
-176
lines changed

include/swift/SIL/SILValue.h

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,16 @@ static inline llvm::hash_code hash_value(ValueKind K) {
6363
/// What constraint does the given use of an SSA value put on the lifetime of
6464
/// the given SSA value.
6565
///
66-
/// There are two possible constraints: MustBeLive and
67-
/// MustBeInvalidated. MustBeLive means that the SSA value must be able to be
68-
/// used in a valid way at the given use point. MustBeInvalidated means that any
69-
/// use of given SSA value after this instruction on any path through this
70-
/// instruction.
66+
/// There are two possible constraints: NonLifetimeEnding and
67+
/// LifetimeEnding. NonLifetimeEnding means that the SSA value must be
68+
/// able to be used in a valid way at the given use
69+
/// point. LifetimeEnding means that the value has been invalidated at
70+
/// the given use point and any uses reachable from that point are
71+
/// invalid in SIL causing a SIL verifier error.
7172
enum class UseLifetimeConstraint {
7273
/// This use requires the SSA value to be live after the given instruction's
7374
/// execution.
74-
MustBeLive,
75+
NonLifetimeEnding,
7576

7677
/// This use invalidates the given SSA value.
7778
///
@@ -81,7 +82,7 @@ enum class UseLifetimeConstraint {
8182
/// guaranteed (i.e. shared borrow) semantics this means that the program
8283
/// has left the scope of the borrowed SSA value and said value can not be
8384
/// used.
84-
MustBeInvalidated,
85+
LifetimeEnding,
8586
};
8687

8788
llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
@@ -174,9 +175,9 @@ struct ValueOwnershipKind {
174175
case ValueOwnershipKind::None:
175176
case ValueOwnershipKind::Guaranteed:
176177
case ValueOwnershipKind::Unowned:
177-
return UseLifetimeConstraint::MustBeLive;
178+
return UseLifetimeConstraint::NonLifetimeEnding;
178179
case ValueOwnershipKind::Owned:
179-
return UseLifetimeConstraint::MustBeInvalidated;
180+
return UseLifetimeConstraint::LifetimeEnding;
180181
}
181182
llvm_unreachable("covered switch");
182183
}
@@ -523,7 +524,8 @@ struct OperandOwnershipKindMap {
523524
if (ValueOwnershipKind(index) == kind) {
524525
continue;
525526
}
526-
map.add(ValueOwnershipKind(index), UseLifetimeConstraint::MustBeLive);
527+
map.add(ValueOwnershipKind(index),
528+
UseLifetimeConstraint::NonLifetimeEnding);
527529
}
528530
return map;
529531
}
@@ -548,7 +550,8 @@ struct OperandOwnershipKindMap {
548550
unsigned index = 0;
549551
unsigned end = unsigned(ValueOwnershipKind::LastValueOwnershipKind) + 1;
550552
while (index != end) {
551-
map.add(ValueOwnershipKind(index), UseLifetimeConstraint::MustBeLive);
553+
map.add(ValueOwnershipKind(index),
554+
UseLifetimeConstraint::NonLifetimeEnding);
552555
++index;
553556
}
554557
return map;
@@ -574,7 +577,7 @@ struct OperandOwnershipKindMap {
574577

575578
void addCompatibilityConstraint(ValueOwnershipKind kind,
576579
UseLifetimeConstraint constraint) {
577-
add(ValueOwnershipKind::None, UseLifetimeConstraint::MustBeLive);
580+
add(ValueOwnershipKind::None, UseLifetimeConstraint::NonLifetimeEnding);
578581
add(kind, constraint);
579582
}
580583

@@ -697,14 +700,14 @@ class Operand {
697700

698701
/// Returns true if this operand acts as a use that consumes its associated
699702
/// value.
700-
bool isConsumingUse() const {
703+
bool isLifetimeEnding() const {
701704
// Type dependent uses can never be consuming and do not have valid
702705
// ownership maps since they do not participate in the ownership system.
703706
if (isTypeDependent())
704707
return false;
705708
auto map = getOwnershipKindMap();
706709
auto constraint = map.getLifetimeConstraint(get().getOwnershipKind());
707-
return constraint == UseLifetimeConstraint::MustBeInvalidated;
710+
return constraint == UseLifetimeConstraint::LifetimeEnding;
708711
}
709712

710713
SILBasicBlock *getParentBlock() const;
@@ -792,9 +795,9 @@ class ConsumingUseIterator : public ValueBaseUseIterator {
792795
explicit ConsumingUseIterator(Operand *cur) : ValueBaseUseIterator(cur) {}
793796
ConsumingUseIterator &operator++() {
794797
assert(Cur && "incrementing past end()!");
795-
assert(Cur->isConsumingUse());
798+
assert(Cur->isLifetimeEnding());
796799
while ((Cur = Cur->NextUse)) {
797-
if (Cur->isConsumingUse())
800+
if (Cur->isLifetimeEnding())
798801
break;
799802
}
800803
return *this;
@@ -810,7 +813,7 @@ class ConsumingUseIterator : public ValueBaseUseIterator {
810813
inline ValueBase::consuming_use_iterator
811814
ValueBase::consuming_use_begin() const {
812815
auto cur = FirstUse;
813-
while (cur && !cur->isConsumingUse()) {
816+
while (cur && !cur->isLifetimeEnding()) {
814817
cur = cur->NextUse;
815818
}
816819
return ValueBase::consuming_use_iterator(cur);
@@ -825,9 +828,9 @@ class NonConsumingUseIterator : public ValueBaseUseIterator {
825828
explicit NonConsumingUseIterator(Operand *cur) : ValueBaseUseIterator(cur) {}
826829
NonConsumingUseIterator &operator++() {
827830
assert(Cur && "incrementing past end()!");
828-
assert(!Cur->isConsumingUse());
831+
assert(!Cur->isLifetimeEnding());
829832
while ((Cur = Cur->NextUse)) {
830-
if (!Cur->isConsumingUse())
833+
if (!Cur->isLifetimeEnding())
831834
break;
832835
}
833836
return *this;
@@ -843,7 +846,7 @@ class NonConsumingUseIterator : public ValueBaseUseIterator {
843846
inline ValueBase::non_consuming_use_iterator
844847
ValueBase::non_consuming_use_begin() const {
845848
auto cur = FirstUse;
846-
while (cur && cur->isConsumingUse()) {
849+
while (cur && cur->isLifetimeEnding()) {
847850
cur = cur->NextUse;
848851
}
849852
return ValueBase::non_consuming_use_iterator(cur);
@@ -880,7 +883,7 @@ inline Operand *ValueBase::getSingleUse() const {
880883
inline Operand *ValueBase::getSingleConsumingUse() const {
881884
Operand *result = nullptr;
882885
for (auto *op : getUses()) {
883-
if (op->isConsumingUse()) {
886+
if (op->isLifetimeEnding()) {
884887
if (result) {
885888
return nullptr;
886889
}

0 commit comments

Comments
 (0)