Skip to content

Commit b9eb24e

Browse files
committed
IRGen: Emit remote reflection metadata for @objc protocols
I noticed even with multi-payload enum layout working, remote reflection could not understand Set and Dictionary, because of issues with Objective-C protocols in the standard library that are used in the representation of those types. The problem is that we were taking a different code path and not emitting a field descriptor. A field descriptor is necessary to differentiate Objective-C, class-bound and opaque protocols from each other, so that existentials can use the correct representation.
1 parent 1ef1d1f commit b9eb24e

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

lib/IRGen/GenMeta.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5677,6 +5677,9 @@ namespace {
56775677
/// the protocol descriptor, and for ObjC interop, references to the descriptor
56785678
/// that the ObjC runtime uses for uniquing.
56795679
void IRGenModule::emitProtocolDecl(ProtocolDecl *protocol) {
5680+
// Emit remote reflection metadata for the protocol.
5681+
emitFieldMetadataRecord(protocol);
5682+
56805683
// If the protocol is Objective-C-compatible, go through the path that
56815684
// produces an ObjC-compatible protocol_t.
56825685
if (protocol->isObjC()) {
@@ -5706,8 +5709,6 @@ void IRGenModule::emitProtocolDecl(ProtocolDecl *protocol) {
57065709
init->getType()));
57075710
var->setConstant(true);
57085711
var->setInitializer(init);
5709-
5710-
emitFieldMetadataRecord(protocol);
57115712
}
57125713

57135714
/// \brief Load a reference to the protocol descriptor for the given protocol.

test/Reflection/Inputs/ObjectiveCTypes.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public class HasObjCClasses {
1919
let rect = CGRect(x: 0, y: 1, width: 2, height: 3)
2020
}
2121

22+
@objc public protocol OP {}
23+
2224
public func closureHasObjCClasses(b: Bundle, c: NSCoding) -> () -> () {
2325
return { _ = b; _ = c }
2426
}

test/Reflection/typeref_decoding_objc.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
// CHECK: rect: __C.CGRect
4343
// CHECK: (struct __C.CGRect)
4444

45+
// CHECK: TypesToReflect.OP
46+
// CHECK: -----------------
47+
4548
// CHECK: __ObjC.Bundle
4649
// CHECK: ---------------
4750
// CHECK: __ObjC.NSURL

0 commit comments

Comments
 (0)