@@ -92,6 +92,10 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
9292// / have.
9393struct ValueOwnershipKind {
9494 enum innerty : uint8_t {
95+ // / A value used to signal that two merged ValueOwnershipKinds were
96+ // / incompatible.
97+ Invalid = 0 ,
98+
9599 // / A SILValue with `Unowned` ownership kind is an independent value that
96100 // / has a lifetime that is only guaranteed to last until the next program
97101 // / visible side-effect. To maintain the lifetime of an unowned value, it
@@ -156,7 +160,10 @@ struct ValueOwnershipKind {
156160 return Value == b;
157161 }
158162
159- Optional<ValueOwnershipKind> merge (ValueOwnershipKind RHS) const ;
163+ // / Returns true if this ValueOwnershipKind is not invalid.
164+ explicit operator bool () const { return Value != Invalid; }
165+
166+ ValueOwnershipKind merge (ValueOwnershipKind RHS) const ;
160167
161168 // / Given that there is an aggregate value (like a struct or enum) with this
162169 // / ownership kind, and a subobject of type Proj is being projected from the
@@ -172,6 +179,8 @@ struct ValueOwnershipKind {
172179 // / kinds.
173180 UseLifetimeConstraint getForwardingLifetimeConstraint () const {
174181 switch (Value) {
182+ case ValueOwnershipKind::Invalid:
183+ llvm_unreachable (" Invalid ownership doesnt have a lifetime constraint!" );
175184 case ValueOwnershipKind::None:
176185 case ValueOwnershipKind::Guaranteed:
177186 case ValueOwnershipKind::Unowned:
@@ -188,7 +197,7 @@ struct ValueOwnershipKind {
188197 // / The reason why we do not compare directy is to allow for
189198 // / ValueOwnershipKind::None to merge into other forms of ValueOwnershipKind.
190199 bool isCompatibleWith (ValueOwnershipKind other) const {
191- return merge (other). hasValue ( );
200+ return bool ( merge (other));
192201 }
193202
194203 // / Returns isCompatibleWith(other.getOwnershipKind()).
@@ -197,16 +206,14 @@ struct ValueOwnershipKind {
197206 // / dependencies.
198207 bool isCompatibleWith (SILValue other) const ;
199208
200- template <typename RangeTy>
201- static Optional<ValueOwnershipKind> merge (RangeTy &&r) {
202- auto initial = Optional<ValueOwnershipKind>(ValueOwnershipKind::None);
203- return accumulate (
204- std::forward<RangeTy>(r), initial,
205- [](Optional<ValueOwnershipKind> acc, ValueOwnershipKind x) {
206- if (!acc)
207- return acc;
208- return acc.getValue ().merge (x);
209- });
209+ template <typename RangeTy> static ValueOwnershipKind merge (RangeTy &&r) {
210+ auto initial = ValueOwnershipKind::None;
211+ return accumulate (std::forward<RangeTy>(r), initial,
212+ [](ValueOwnershipKind acc, ValueOwnershipKind x) {
213+ if (!acc)
214+ return acc;
215+ return acc.merge (x);
216+ });
210217 }
211218
212219 StringRef asString () const ;
0 commit comments