@@ -105,7 +105,7 @@ namespace {
105
105
} // end anonymous namespace
106
106
107
107
// / Return the lowered type for the class's 'self' type within its context.
108
- static SILType getSelfType (ClassDecl *base) {
108
+ static SILType getSelfType (const ClassDecl *base) {
109
109
auto loweredTy = base->getDeclaredTypeInContext ()->getCanonicalType ();
110
110
return SILType::getPrimitiveObjectType (loweredTy);
111
111
}
@@ -2131,10 +2131,17 @@ llvm::Constant *irgen::emitClassPrivateData(IRGenModule &IGM,
2131
2131
builder.buildMetaclassStub ();
2132
2132
2133
2133
HasUpdateCallback_t hasUpdater = DoesNotHaveUpdateCallback;
2134
- if (doesClassMetadataRequireUpdate (IGM, cls) &&
2135
- !doesClassMetadataRequireInitialization (IGM, cls)) {
2134
+
2135
+ switch (IGM.getClassMetadataStrategy (cls)) {
2136
+ case ClassMetadataStrategy::Resilient:
2137
+ case ClassMetadataStrategy::Singleton:
2138
+ case ClassMetadataStrategy::Fixed:
2139
+ break ;
2140
+ case ClassMetadataStrategy::Update:
2141
+ case ClassMetadataStrategy::FixedOrUpdate:
2136
2142
hasUpdater = HasUpdateCallback;
2137
2143
emitObjCMetadataUpdateFunction (IGM, cls);
2144
+ break ;
2138
2145
}
2139
2146
2140
2147
// Then build the class RO-data.
@@ -2293,40 +2300,26 @@ ClassDecl *irgen::getRootClassForMetaclass(IRGenModule &IGM, ClassDecl *C) {
2293
2300
IGM.Context .Id_SwiftObject );
2294
2301
}
2295
2302
2296
- bool irgen::doesClassMetadataRequireRelocation (IRGenModule &IGM,
2297
- ClassDecl *theClass) {
2303
+ ClassMetadataStrategy
2304
+ IRGenModule::getClassMetadataStrategy ( const ClassDecl *theClass) {
2298
2305
SILType selfType = getSelfType (theClass);
2299
- auto &selfTI = IGM.getTypeInfo (selfType).as <ClassTypeInfo>();
2300
-
2301
- // A completely fragile layout does not change whether the metadata
2302
- // requires *relocation*, since that only depends on resilient class
2303
- // ancestry, or the class itself being generic.
2304
- auto &layout = selfTI.getClassLayout (IGM, selfType,
2305
- /* forBackwardDeployment=*/ false );
2306
- return layout.doesMetadataRequireRelocation ();
2307
- }
2306
+ auto &selfTI = getTypeInfo (selfType).as <ClassTypeInfo>();
2308
2307
2309
- bool irgen::doesClassMetadataRequireInitialization (IRGenModule &IGM,
2310
- ClassDecl *theClass) {
2311
- SILType selfType = getSelfType (theClass);
2312
- auto &selfTI = IGM.getTypeInfo (selfType).as <ClassTypeInfo>();
2313
-
2314
- // If we have a fragile layout used for backward deployment, we must use
2315
- // idempotent initialization; swift_initClassMetadata() does not work with
2316
- // statically registered classes.
2317
- auto &layout = selfTI.getClassLayout (IGM, selfType,
2318
- /* forBackwardDeployment=*/ true );
2319
- return layout.doesMetadataRequireInitialization ();
2320
- }
2308
+ auto &resilientLayout = selfTI.getClassLayout (*this , selfType,
2309
+ /* forBackwardDeployment=*/ false );
2310
+ auto &fragileLayout = selfTI.getClassLayout (*this , selfType,
2311
+ /* forBackwardDeployment=*/ true );
2321
2312
2322
- bool irgen::doesClassMetadataRequireUpdate (IRGenModule &IGM,
2323
- ClassDecl *theClass) {
2324
- SILType selfType = getSelfType (theClass);
2325
- auto &selfTI = IGM.getTypeInfo (selfType).as <ClassTypeInfo>();
2313
+ if (resilientLayout.doesMetadataRequireRelocation ())
2314
+ return ClassMetadataStrategy::Resilient;
2315
+
2316
+ if (fragileLayout.doesMetadataRequireInitialization ())
2317
+ return ClassMetadataStrategy::Singleton;
2318
+
2319
+ if (resilientLayout.doesMetadataRequireInitialization ())
2320
+ return ClassMetadataStrategy::FixedOrUpdate;
2326
2321
2327
- auto &layout = selfTI.getClassLayout (IGM, selfType,
2328
- /* forBackwardDeployment=*/ false );
2329
- return layout.doesMetadataRequireInitialization ();
2322
+ return ClassMetadataStrategy::Fixed;
2330
2323
}
2331
2324
2332
2325
bool irgen::hasKnownSwiftMetadata (IRGenModule &IGM, CanType type) {
0 commit comments