Skip to content

Commit 93ab162

Browse files
committed
[embedded] Lazily emit class metadata in embedded mode
1 parent 0f99458 commit 93ab162

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

lib/IRGen/GenClass.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,16 +1051,22 @@ void IRGenModule::emitClassDecl(ClassDecl *D) {
10511051
auto &resilientLayout =
10521052
classTI.getClassLayout(*this, selfType, /*forBackwardDeployment=*/false);
10531053

1054+
auto isEmbeddedWithExistentials =
1055+
Context.LangOpts.hasFeature(Feature::EmbeddedExistentials);
1056+
10541057
// As a matter of policy, class metadata is never emitted lazily for now.
1055-
assert(!IRGen.hasLazyMetadata(D));
1058+
assert(isEmbeddedWithExistentials || !IRGen.hasLazyMetadata(D));
10561059

10571060
// Emit the class metadata.
10581061
if (!D->getASTContext().LangOpts.hasFeature(Feature::Embedded)) {
10591062
emitClassMetadata(*this, D, fragileLayout, resilientLayout);
10601063
emitFieldDescriptor(D);
10611064
} else {
1062-
if (!D->isGenericContext()) {
1063-
emitEmbeddedClassMetadata(*this, D, fragileLayout);
1065+
if (!isEmbeddedWithExistentials && !D->isGenericContext()) {
1066+
emitEmbeddedClassMetadata(*this, D);
1067+
} else {
1068+
// We create all metadata lazyly in embedded with existentials mode.
1069+
return;
10641070
}
10651071
}
10661072

lib/IRGen/GenMeta.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5398,6 +5398,7 @@ diagnoseUnsupportedObjCImplLayout(IRGenModule &IGM, ClassDecl *classDecl,
53985398
void irgen::emitClassMetadata(IRGenModule &IGM, ClassDecl *classDecl,
53995399
const ClassLayout &fragileLayout,
54005400
const ClassLayout &resilientLayout) {
5401+
54015402
assert(!classDecl->isForeign());
54025403
PrettyStackTraceDecl stackTraceRAII("emitting metadata for", classDecl);
54035404

@@ -5565,8 +5566,7 @@ static void emitEmbeddedVTable(IRGenModule &IGM, CanType classTy,
55655566
(void)var;
55665567
}
55675568

5568-
void irgen::emitEmbeddedClassMetadata(IRGenModule &IGM, ClassDecl *classDecl,
5569-
const ClassLayout &fragileLayout) {
5569+
void irgen::emitEmbeddedClassMetadata(IRGenModule &IGM, ClassDecl *classDecl) {
55705570
PrettyStackTraceDecl stackTraceRAII("emitting metadata for", classDecl);
55715571
assert(!classDecl->isForeign());
55725572
CanType declaredType = classDecl->getDeclaredType()->getCanonicalType();
@@ -5578,7 +5578,9 @@ void irgen::emitLazyClassMetadata(IRGenModule &IGM, CanType classTy) {
55785578
// Might already be emitted, skip if that's the case.
55795579
auto entity =
55805580
LinkEntity::forTypeMetadata(classTy, TypeMetadataAddress::AddressPoint);
5581-
if (IGM.Context.LangOpts.hasFeature(Feature::EmbeddedExistentials)) {
5581+
5582+
auto isEmbeddedWithExistentials = IGM.Context.LangOpts.hasFeature(Feature::EmbeddedExistentials);
5583+
if (isEmbeddedWithExistentials) {
55825584
entity = LinkEntity::forTypeMetadata(classTy, TypeMetadataAddress::FullMetadata);
55835585
}
55845586
auto *existingVar = cast<llvm::GlobalVariable>(
@@ -5587,6 +5589,11 @@ void irgen::emitLazyClassMetadata(IRGenModule &IGM, CanType classTy) {
55875589
return;
55885590
}
55895591

5592+
if (isEmbeddedWithExistentials) {
5593+
emitEmbeddedClassMetadata(IGM, classTy->getClassOrBoundGenericClass());
5594+
return;
5595+
}
5596+
55905597
auto &context = classTy->getNominalOrBoundGenericNominal()->getASTContext();
55915598
PrettyStackTraceType stackTraceRAII(
55925599
context, "emitting lazy class metadata for", classTy);

lib/IRGen/GenMeta.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ namespace irgen {
6161

6262
/// Emit "embedded Swift" class metadata (a simple vtable) for the given class
6363
/// declaration.
64-
void emitEmbeddedClassMetadata(IRGenModule &IGM, ClassDecl *theClass,
65-
const ClassLayout &fragileLayout);
64+
void emitEmbeddedClassMetadata(IRGenModule &IGM, ClassDecl *theClass);
6665

6766
/// Emit the constant initializer of the type metadata candidate for
6867
/// the given foreign class declaration.

0 commit comments

Comments
 (0)