@@ -4996,64 +4996,74 @@ void irgen::emitClassMetadata(IRGenModule &IGM, ClassDecl *classDecl,
49964996 }
49974997}
49984998
4999- void irgen::emitEmbeddedClassMetadata (IRGenModule &IGM, ClassDecl *classDecl ,
5000- const ClassLayout &fragileLayout ) {
5001- PrettyStackTraceDecl stackTraceRAII ( " emitting metadata for " , classDecl );
5002- assert (!classDecl-> isForeign () );
4999+ static void emitEmbeddedVTable (IRGenModule &IGM, CanType classTy ,
5000+ SILVTable *vtable ) {
5001+ SILType classType = SILType::getPrimitiveObjectType (classTy );
5002+ auto &classTI = IGM. getTypeInfo (classType). as <ClassTypeInfo>( );
50035003
5004- // Set up a dummy global to stand in for the metadata object while we produce
5005- // relative references.
5006- ConstantInitBuilder builder (IGM);
5007- auto init = builder.beginStruct ();
5008- init.setPacked (true );
5004+ auto &fragileLayout =
5005+ classTI.getClassLayout (IGM, classType, /* forBackwardDeployment=*/ true );
50095006
5007+ ClassDecl *classDecl = classType.getClassOrBoundGenericClass ();
50105008 auto strategy = IGM.getClassMetadataStrategy (classDecl);
50115009 assert (strategy == ClassMetadataStrategy::FixedOrUpdate ||
50125010 strategy == ClassMetadataStrategy::Fixed);
50135011
5014- FixedClassMetadataBuilder metadataBuilder (IGM, classDecl, init,
5015- fragileLayout);
5016- metadataBuilder.layout ();
5017- bool canBeConstant = metadataBuilder.canBeConstant ();
5012+ ConstantInitBuilder initBuilder (IGM);
5013+ auto init = initBuilder.beginStruct ();
5014+ init.setPacked (true );
5015+
5016+ assert (vtable);
50185017
5019- CanType declaredType = classDecl->getDeclaredType ()->getCanonicalType ();
5018+ FixedClassMetadataBuilder builder (IGM, classDecl, init, fragileLayout,
5019+ vtable);
5020+ builder.layout ();
5021+ bool canBeConstant = builder.canBeConstant ();
50205022
50215023 StringRef section{};
5022- bool isPattern = false ;
5023- auto var = IGM.defineTypeMetadata (declaredType, isPattern, canBeConstant,
5024+ auto var = IGM.defineTypeMetadata (classTy, /* isPattern*/ false , canBeConstant,
50245025 init.finishAndCreateFuture (), section);
50255026 (void )var;
50265027}
50275028
5028- void irgen::emitLazySpecializedClassMetadata (IRGenModule &IGM,
5029- CanType classTy) {
5029+ void irgen::emitEmbeddedClassMetadata (IRGenModule &IGM, ClassDecl *classDecl,
5030+ const ClassLayout &fragileLayout) {
5031+ PrettyStackTraceDecl stackTraceRAII (" emitting metadata for" , classDecl);
5032+ assert (!classDecl->isForeign ());
5033+ CanType declaredType = classDecl->getDeclaredType ()->getCanonicalType ();
5034+ SILVTable *vtable = IGM.getSILModule ().lookUpVTable (classDecl);
5035+ emitEmbeddedVTable (IGM, declaredType, vtable);
5036+ }
5037+
5038+ void irgen::emitLazyClassMetadata (IRGenModule &IGM, CanType classTy) {
5039+ // Might already be emitted, skip if that's the case.
5040+ auto entity =
5041+ LinkEntity::forTypeMetadata (classTy, TypeMetadataAddress::AddressPoint);
5042+ auto *existingVar = cast<llvm::GlobalVariable>(
5043+ IGM.getAddrOfLLVMVariable (entity, ConstantInit (), DebugTypeInfo ()));
5044+ if (!existingVar->isDeclaration ()) {
5045+ return ;
5046+ }
5047+
50305048 auto &context = classTy->getNominalOrBoundGenericNominal ()->getASTContext ();
50315049 PrettyStackTraceType stackTraceRAII (
5032- context, " emitting lazy specialized class metadata for" , classTy);
5050+ context, " emitting lazy class metadata for" , classTy);
50335051
50345052 SILType classType = SILType::getPrimitiveObjectType (classTy);
5035- auto &classTI = IGM.getTypeInfo (classType).as <ClassTypeInfo>();
5036-
5037- auto &fragileLayout =
5038- classTI.getClassLayout (IGM, classType, /* forBackwardDeployment=*/ true );
5039-
50405053 ClassDecl *classDecl = classType.getClassOrBoundGenericClass ();
5054+ SILVTable *vtable = IGM.getSILModule ().lookUpVTable (classDecl);
5055+ emitEmbeddedVTable (IGM, classTy, vtable);
5056+ }
50415057
5042- ConstantInitBuilder initBuilder (IGM);
5043- auto init = initBuilder.beginStruct ();
5044- init.setPacked (true );
5058+ void irgen::emitLazySpecializedClassMetadata (IRGenModule &IGM,
5059+ CanType classTy) {
5060+ auto &context = classTy->getNominalOrBoundGenericNominal ()->getASTContext ();
5061+ PrettyStackTraceType stackTraceRAII (
5062+ context, " emitting lazy specialized class metadata for" , classTy);
50455063
5064+ SILType classType = SILType::getPrimitiveObjectType (classTy);
50465065 SILVTable *vtable = IGM.getSILModule ().lookUpSpecializedVTable (classType);
5047- assert (vtable);
5048-
5049- FixedClassMetadataBuilder builder (IGM, classDecl, init, fragileLayout, vtable);
5050- builder.layout ();
5051- bool canBeConstant = builder.canBeConstant ();
5052-
5053- StringRef section{};
5054- auto var = IGM.defineTypeMetadata (classTy, false , canBeConstant,
5055- init.finishAndCreateFuture (), section);
5056- (void )var;
5066+ emitEmbeddedVTable (IGM, classTy, vtable);
50575067}
50585068
50595069void irgen::emitSpecializedGenericClassMetadata (IRGenModule &IGM, CanType type,
0 commit comments