@@ -183,6 +183,27 @@ CONSTANT_OWNERSHIP_INST(None, TypeValue)
183
183
184
184
#undef CONSTANT_OWNERSHIP_INST
185
185
186
+ ValueOwnershipKind ValueOwnershipKindClassifier::visitStructExtractInst (StructExtractInst *sei) {
187
+ if (sei->getType ().isTrivial (*sei->getFunction ()) ||
188
+ // A struct value can have "none" ownership even if its type is not trivial.
189
+ // This happens when the struct/tuple contains a non-trivial enum, but it's initialized with
190
+ // a trivial enum case (e.g. with `Optional.none`).
191
+ sei->getOperand ()->getOwnershipKind () == OwnershipKind::None) {
192
+ return OwnershipKind::None;
193
+ }
194
+ return OwnershipKind::Guaranteed;
195
+ }
196
+
197
+ ValueOwnershipKind ValueOwnershipKindClassifier::visitTupleExtractInst (TupleExtractInst *tei) {
198
+ if (tei->getType ().isTrivial (*tei->getFunction ()) ||
199
+ // A tuple value can have "none" ownership even if its type is not trivial.
200
+ // This happens when the struct/tuple contains a non-trivial enum, but it's initialized with
201
+ // a trivial enum case (e.g. with `Optional.none`).
202
+ tei->getOperand ()->getOwnershipKind () == OwnershipKind::None)
203
+ return OwnershipKind::None;
204
+ return OwnershipKind::Guaranteed;
205
+ }
206
+
186
207
#define CONSTANT_OR_NONE_OWNERSHIP_INST (OWNERSHIP, INST ) \
187
208
ValueOwnershipKind ValueOwnershipKindClassifier::visit##INST##Inst( \
188
209
INST##Inst *I) { \
@@ -192,8 +213,6 @@ CONSTANT_OWNERSHIP_INST(None, TypeValue)
192
213
} \
193
214
return OwnershipKind::OWNERSHIP; \
194
215
}
195
- CONSTANT_OR_NONE_OWNERSHIP_INST (Guaranteed, StructExtract)
196
- CONSTANT_OR_NONE_OWNERSHIP_INST(Guaranteed, TupleExtract)
197
216
CONSTANT_OR_NONE_OWNERSHIP_INST (Guaranteed, TuplePackExtract)
198
217
CONSTANT_OR_NONE_OWNERSHIP_INST(Guaranteed, DifferentiableFunctionExtract)
199
218
CONSTANT_OR_NONE_OWNERSHIP_INST(Guaranteed, LinearFunctionExtract)
0 commit comments