Skip to content

Commit 32ab89b

Browse files
committed
[Runtime] Reference ObjC class objects indirectly in conformance records.
Within conformance records, reference Objective-C class objects indirectly so the runtime can update those references appropriately. We don't need to do this for classes with Swift metadata.
1 parent 7e6f523 commit 32ab89b

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

include/swift/Runtime/Metadata.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2543,12 +2543,12 @@ struct TargetProtocolConformanceRecord {
25432543

25442544
/// An indirect reference to the metadata.
25452545
RelativeIndirectablePointer<const TargetClassMetadata<Runtime> *>
2546-
IndirectClass;
2546+
IndirectClass;
25472547

25482548
/// The nominal type descriptor for a resilient or generic type which has
25492549
/// instances that conform to the protocol.
25502550
RelativeIndirectablePointer<TargetNominalTypeDescriptor<Runtime>>
2551-
TypeDescriptor;
2551+
TypeDescriptor;
25522552
};
25532553

25542554

lib/IRGen/GenDecl.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,6 +1354,8 @@ bool LinkEntity::isAvailableExternally(IRGenModule &IGM) const {
13541354
return ::isAvailableExternally(IGM, getProtocolConformance()->getDeclContext());
13551355

13561356
case Kind::ObjCClassRef:
1357+
return false;
1358+
13571359
case Kind::ValueWitness:
13581360
case Kind::TypeMetadataAccessFunction:
13591361
case Kind::TypeMetadataLazyCacheVariable:
@@ -2215,18 +2217,21 @@ getTypeEntityInfo(IRGenModule &IGM, CanType conformingType) {
22152217
defaultTy = IGM.TypeMetadataStructTy;
22162218
defaultPtrTy = IGM.TypeMetadataPtrTy;
22172219
} else {
2218-
// TODO: We should indirectly reference classes. For now directly
2219-
// reference the class object, which is totally wrong for ObjC interop.
2220-
2221-
typeKind = TypeMetadataRecordKind::UniqueDirectClass;
2222-
if (hasKnownSwiftMetadata(IGM, clas))
2220+
if (hasKnownSwiftMetadata(IGM, clas)) {
2221+
typeKind = TypeMetadataRecordKind::UniqueDirectClass;
22232222
entity = LinkEntity::forTypeMetadata(
22242223
conformingType,
22252224
TypeMetadataAddress::AddressPoint,
22262225
/*isPattern*/ false);
2227-
else
2228-
entity = LinkEntity::forObjCClass(clas);
2229-
defaultTy = IGM.TypeMetadataStructTy;
2226+
defaultTy = IGM.TypeMetadataStructTy;
2227+
} else {
2228+
// Form the class reference.
2229+
(void)IGM.getAddrOfObjCClassRef(clas);
2230+
2231+
typeKind = TypeMetadataRecordKind::UniqueIndirectClass;
2232+
entity = LinkEntity::forObjCClassRef(clas);
2233+
defaultTy = IGM.TypeMetadataPtrTy;
2234+
}
22302235
defaultPtrTy = IGM.TypeMetadataPtrTy;
22312236
}
22322237
} else {

test/IRGen/objc_bridged_generic_conformance.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
// CHECK-NOT: _TMnCSo
55

6-
// CHECK: @"\01l_protocol_conformances" = {{.*}} @"got.OBJC_CLASS_$_Thingy"
6+
// CHECK: @"\01l_protocol_conformances" = {{.*}} @"OBJC_CLASS_REF_$_Thingy"
77

88
// CHECK-NOT: _TMnCSo
99

test/IRGen/protocol_conformance_records_objc.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ extension NSRect: Runcible {
3131
// CHECK: %swift.protocol_conformance {
3232
// -- protocol descriptor
3333
// CHECK: [[RUNCIBLE]]
34-
// -- class object (TODO should be class ref variable)
35-
// CHECK: @"got.OBJC_CLASS_$_Gizmo"
34+
// -- class object reference
35+
// CHECK: @"OBJC_CLASS_REF_$_Gizmo"
3636
// -- witness table
3737
// CHECK: @_T0So5GizmoC33protocol_conformance_records_objc8RuncibleACWP
38-
// -- flags 0x01: unique direct metadata (TODO should be 0x03 indirect class)
39-
// CHECK: i32 1
38+
// -- flags 0x03: indirect class metadata
39+
// CHECK: i32 3
4040
// CHECK: }
4141
extension Gizmo: Runcible {
4242
public func runce() {}

0 commit comments

Comments
 (0)