@@ -92,6 +92,10 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
92
92
// / have.
93
93
struct ValueOwnershipKind {
94
94
enum innerty : uint8_t {
95
+ // / A value used to signal that two merged ValueOwnershipKinds were
96
+ // / incompatible.
97
+ Invalid = 0 ,
98
+
95
99
// / A SILValue with `Unowned` ownership kind is an independent value that
96
100
// / has a lifetime that is only guaranteed to last until the next program
97
101
// / visible side-effect. To maintain the lifetime of an unowned value, it
@@ -156,7 +160,10 @@ struct ValueOwnershipKind {
156
160
return Value == b;
157
161
}
158
162
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 ;
160
167
161
168
// / Given that there is an aggregate value (like a struct or enum) with this
162
169
// / ownership kind, and a subobject of type Proj is being projected from the
@@ -172,6 +179,8 @@ struct ValueOwnershipKind {
172
179
// / kinds.
173
180
UseLifetimeConstraint getForwardingLifetimeConstraint () const {
174
181
switch (Value) {
182
+ case ValueOwnershipKind::Invalid:
183
+ llvm_unreachable (" Invalid ownership doesnt have a lifetime constraint!" );
175
184
case ValueOwnershipKind::None:
176
185
case ValueOwnershipKind::Guaranteed:
177
186
case ValueOwnershipKind::Unowned:
@@ -188,7 +197,7 @@ struct ValueOwnershipKind {
188
197
// / The reason why we do not compare directy is to allow for
189
198
// / ValueOwnershipKind::None to merge into other forms of ValueOwnershipKind.
190
199
bool isCompatibleWith (ValueOwnershipKind other) const {
191
- return merge (other). hasValue ( );
200
+ return bool ( merge (other));
192
201
}
193
202
194
203
// / Returns isCompatibleWith(other.getOwnershipKind()).
@@ -197,16 +206,14 @@ struct ValueOwnershipKind {
197
206
// / dependencies.
198
207
bool isCompatibleWith (SILValue other) const ;
199
208
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
+ });
210
217
}
211
218
212
219
StringRef asString () const ;
0 commit comments