[Runtime] Lookup @objc protocols in mangled name -> type metadata function.

Swift-defined @objc protocols are registered with the Objective-C runtime
under the Swift 3 mangling scheme; look in the Objective-C runting using
objc_getProtocol() with the appropriate name.

Also, correctly compute the "class bound" bit when forming a protocol
composition metatype. The information isn't in the mangled name when it
can be recovered from the protocols themselves, so look at the protocols.
This commit is contained in:
Doug Gregor
2018-01-10 16:18:55 -08:00
parent 82140ca811
commit c302042dc5
4 changed files with 83 additions and 4 deletions

View File

@@ -0,0 +1,30 @@
// RUN: %target-run-simple-swift
// REQUIRES: executable_test
// REQUIRES: objc_interop
import StdlibUnittest
import Foundation
let DemangleToMetadataTests = TestSuite("DemangleToMetadataObjC")
@objc class C : NSObject { }
@objc enum E: Int { case a }
@objc protocol P1 { }
DemangleToMetadataTests.test("@objc classes") {
expectEqual(type(of: C()), _typeByMangledName("4main1CC")!)
}
DemangleToMetadataTests.test("@objc enums") {
expectEqual(type(of: E.a), _typeByMangledName("4main1EO")!)
}
func f1_composition_objc_protocol(_: P1) { }
DemangleToMetadataTests.test("@objc protocols") {
expectEqual(type(of: f1_composition_objc_protocol),
_typeByMangledName("yy4main2P1_pc")!)
}
runAllTests()