@@ -168,6 +168,11 @@ namespace {
168
168
169
169
unsigned NumInherited = 0 ;
170
170
171
+ // Does the class require a metadata template? This will be true if
172
+ // the class or any of its ancestors have generic parameters, or if
173
+ // any of the below conditions are false.
174
+ bool ClassHasMetadataPattern = false ;
175
+
171
176
// Does the superclass have a fixed number of stored properties?
172
177
// If not, and the class has generally-dependent layout, we have to
173
178
// access stored properties through an indirect offset into the field
@@ -212,6 +217,7 @@ namespace {
212
217
fieldLayout.InheritedStoredProperties = inheritedStoredProps;
213
218
fieldLayout.AllFieldAccesses = IGM.Context .AllocateCopy (AllFieldAccesses);
214
219
fieldLayout.MetadataAccess = MetadataAccess;
220
+ fieldLayout.HasMetadataPattern = ClassHasMetadataPattern;
215
221
return fieldLayout;
216
222
}
217
223
@@ -237,6 +243,8 @@ namespace {
237
243
} else if (IGM.isResilient (superclass, ResilienceScope::Component)) {
238
244
// If the superclass is resilient, the number of stored properties
239
245
// is not known at compile time.
246
+ ClassHasMetadataPattern = true ;
247
+
240
248
ClassHasFixedFieldCount = false ;
241
249
ClassHasFixedSize = false ;
242
250
@@ -246,6 +254,9 @@ namespace {
246
254
if (superclass->isGenericContext ())
247
255
ClassHasConcreteLayout = false ;
248
256
} else {
257
+ if (superclass->isGenericContext ())
258
+ ClassHasMetadataPattern = true ;
259
+
249
260
// Otherwise, we have total knowledge of the class and its
250
261
// fields, so walk them to compute the layout.
251
262
addFieldsForClass (superclass, superclassType);
@@ -269,10 +280,11 @@ namespace {
269
280
auto &eltType = IGM.getTypeInfo (type);
270
281
271
282
if (!eltType.isFixedSize ()) {
283
+ ClassHasMetadataPattern = true ;
284
+ ClassHasFixedSize = false ;
285
+
272
286
if (type.hasArchetype ())
273
287
ClassHasConcreteLayout = false ;
274
-
275
- ClassHasFixedSize = false ;
276
288
}
277
289
278
290
Elements.push_back (ElementLayout::getIncomplete (eltType));
@@ -1826,3 +1838,11 @@ ClassDecl *irgen::getRootClassForMetaclass(IRGenModule &IGM, ClassDecl *C) {
1826
1838
1827
1839
return IGM.getObjCRuntimeBaseClass (IGM.Context .Id_SwiftObject );
1828
1840
}
1841
+
1842
+ bool irgen::getClassHasMetadataPattern (IRGenModule &IGM, ClassDecl *theClass) {
1843
+ // Classes imported from Objective-C never have a metadata pattern.
1844
+ if (theClass->hasClangNode ())
1845
+ return false ;
1846
+
1847
+ return getSelfTypeInfo (IGM, theClass).getClassLayout (IGM).HasMetadataPattern ;
1848
+ }
0 commit comments