Skip to content

Commit 705cfa4

Browse files
committed
[IRGen JIT] Register Objective-C classes/categories after other metadata.
The instantiation of an Objective-C class or definition of an Objective-C category can depend (at runtime) on Swift metadata, which is triggered (only) by mangled name round-trip verification. Teach the JIT to call the registration functions for Objective-C classes and categories after we’ve called all of the metadata registration functions.
1 parent 1f2f90e commit 705cfa4

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

lib/IRGen/GenDecl.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ void IRGenModule::emitRuntimeRegistration() {
613613
if (DebugInfo && !Context.LangOpts.DebuggerSupport)
614614
DebugInfo->emitArtificialFunction(RegIGF, RegistrationFunction);
615615

616-
// Register ObjC protocols, classes, and extensions we added.
616+
// Register ObjC protocols we added.
617617
if (ObjCInterop) {
618618
if (!ObjCProtocols.empty()) {
619619
// We need to initialize ObjC protocols in inheritance order, parents
@@ -649,14 +649,6 @@ void IRGenModule::emitRuntimeRegistration() {
649649
.visitMembers(proto);
650650
}
651651
}
652-
653-
for (llvm::WeakTrackingVH &ObjCClass : ObjCClasses) {
654-
RegIGF.Builder.CreateCall(getInstantiateObjCClassFn(), {ObjCClass});
655-
}
656-
657-
for (ExtensionDecl *ext : ObjCCategoryDecls) {
658-
CategoryInitializerVisitor(RegIGF, ext).visitMembers(ext);
659-
}
660652
}
661653

662654
// Register Swift protocols if we added any.
@@ -716,6 +708,17 @@ void IRGenModule::emitRuntimeRegistration() {
716708
RegIGF.Builder.CreateCall(getRegisterTypeMetadataRecordsFn(), {begin, end});
717709
}
718710

711+
// Register Objective-C classes and extensions we added.
712+
if (ObjCInterop) {
713+
for (llvm::WeakTrackingVH &ObjCClass : ObjCClasses) {
714+
RegIGF.Builder.CreateCall(getInstantiateObjCClassFn(), {ObjCClass});
715+
}
716+
717+
for (ExtensionDecl *ext : ObjCCategoryDecls) {
718+
CategoryInitializerVisitor(RegIGF, ext).visitMembers(ext);
719+
}
720+
}
721+
719722
if (!FieldDescriptors.empty()) {
720723
emitFieldDescriptors();
721724
}

0 commit comments

Comments
 (0)