@@ -47,6 +47,15 @@ static StructDecl *getFullyReferenceableStruct(SILType ktypeTy) {
47
47
return structDecl;
48
48
}
49
49
50
+ static bool isValueTypeWithDeinit (SILType type) {
51
+ // Do not look inside an aggregate type that has a user-deinit, for which
52
+ // memberwise-destruction is not equivalent to aggregate destruction.
53
+ if (auto *nominal = type.getNominalOrBoundGenericNominal ()) {
54
+ return nominal->getValueTypeDestructor () != nullptr ;
55
+ }
56
+ return false ;
57
+ }
58
+
50
59
// ===----------------------------------------------------------------------===//
51
60
// MARK: TypeSubElementCount
52
61
// ===----------------------------------------------------------------------===//
@@ -70,7 +79,7 @@ TypeSubElementCount::TypeSubElementCount(SILType type, SILModule &mod,
70
79
type.getFieldType (fieldDecl, mod, context), mod, context);
71
80
number = numElements;
72
81
73
- if (type. isValueTypeWithDeinit ()) {
82
+ if (isValueTypeWithDeinit (type )) {
74
83
// 'self' has its own liveness represented as an additional field at the
75
84
// end of the structure.
76
85
++number;
@@ -355,7 +364,7 @@ void TypeTreeLeafTypeRange::constructFilteredProjections(
355
364
callback (newValue, TypeTreeLeafTypeRange (start, next));
356
365
start = next;
357
366
}
358
- if (type. isValueTypeWithDeinit ()) {
367
+ if (isValueTypeWithDeinit (type )) {
359
368
// 'self' has its own liveness
360
369
++start;
361
370
}
0 commit comments