Skip to content

Commit 943e8e9

Browse files
authored
Merge pull request #20379 from DougGregor/runtime-demangle-objc-protocol-remangled-5.0
[5.0] [Runtime] Use the old remangler to compute the @objc protocol name.
2 parents 6af0cd9 + 334024d commit 943e8e9

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

lib/IRGen/GenKeyPath.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ emitWitnessTableGeneratorForKeyPath(IRGenModule &IGM,
732732
static unsigned getClassFieldIndex(ClassDecl *classDecl, VarDecl *property) {
733733
SmallVector<ClassDecl *, 3> superclasses;
734734
for (auto *superDecl = classDecl; superDecl != nullptr;
735-
superDecl = classDecl->getSuperclassDecl()) {
735+
superDecl = superDecl->getSuperclassDecl()) {
736736
superclasses.push_back(superDecl);
737737
}
738738

stdlib/public/runtime/MetadataLookup.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -997,8 +997,7 @@ class DecodedMetadataBuilder {
997997
#if SWIFT_OBJC_INTEROP
998998
// Look for a Swift-defined @objc protocol with the Swift 3 mangling that
999999
// is used for Objective-C entities.
1000-
std::string objcMangledName =
1001-
"_TtP" + mangledName.substr(0, mangledName.size()-1) + "_";
1000+
std::string objcMangledName = "_Tt" + mangleNodeOld(node) + "_";
10021001
if (auto protocol = objc_getProtocol(objcMangledName.c_str()))
10031002
return ProtocolDescriptorRef::forObjC(protocol);
10041003
#endif

test/IRGen/keypaths.sil

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,14 @@ struct G<T> {
3333
subscript<U: Hashable>(x: U) -> T { get set }
3434
}
3535

36+
class C1: C { }
37+
class C2: C1 {
38+
var reabstracted: () -> ()
39+
}
40+
3641
sil_vtable C {}
42+
sil_vtable C1 {}
43+
sil_vtable C2 {}
3744

3845
// CHECK: %TSi = type <{ [[WORD:i.*]] }>
3946

@@ -195,6 +202,10 @@ sil_vtable C {}
195202
// CHECK-SAME: void (%swift.function*, %T8keypaths1SV*)* @m_get,
196203
// CHECK-SAME: void (%swift.function*, %T8keypaths1SV*)* @m_set }>
197204

205+
// -- %m2: reabstracted
206+
// Note: the contents here aren't interesting. The test triggered infinite
207+
// looping in the compiler at one point.
208+
// CHECK: [[KP_M:@keypath.*]] = private global <{ {{.*}} }> <{
198209

199210
// -- %i: Gen<A>.x
200211
// CHECK: [[KP_I:@keypath.*]] = private global <{ {{.*}} }> <{
@@ -261,6 +272,7 @@ entry:
261272
%k = keypath $KeyPath<S, Int>, (root $S; gettable_property $Int, id @k_id : $@convention(thin) () -> (), getter @k_get : $@convention(thin) (@in_guaranteed S) -> @out Int)
262273
%l = keypath $KeyPath<C, Int>, (root $C; settable_property $Int, id #C.w!getter.1, getter @l_get : $@convention(thin) (@in_guaranteed C) -> @out Int, setter @l_set : $@convention(thin) (@in_guaranteed Int, @in_guaranteed C) -> ())
263274
%m = keypath $KeyPath<S, () -> ()>, (root $S; settable_property $() -> (), id ##S.reabstracted, getter @m_get : $@convention(thin) (@in_guaranteed S) -> @out @callee_guaranteed () -> @out (), setter @m_set : $@convention(thin) (@in_guaranteed @callee_guaranteed () -> @out (), @inout S) -> ())
275+
%m2 = keypath $KeyPath<C2, () -> ()>, (root $C2; settable_property $() -> (), id ##C2.reabstracted, getter @m2_get : $@convention(thin) (@in_guaranteed C2) -> @out @callee_guaranteed () -> @out (), setter @m2_set : $@convention(thin) (@in_guaranteed @callee_guaranteed () -> @out (), @inout C2) -> ())
264276

265277
return undef : $()
266278
}
@@ -274,6 +286,9 @@ sil @l_set : $@convention(thin) (@in_guaranteed Int, @in_guaranteed C) -> ()
274286
sil @m_get : $@convention(thin) (@in_guaranteed S) -> @out @callee_guaranteed () -> @out ()
275287
sil @m_set : $@convention(thin) (@in_guaranteed @callee_guaranteed () -> @out (), @inout S) -> ()
276288

289+
sil @m2_get : $@convention(thin) (@in_guaranteed C2) -> @out @callee_guaranteed () -> @out ()
290+
sil @m2_set : $@convention(thin) (@in_guaranteed @callee_guaranteed () -> @out (), @inout C2) -> ()
291+
277292
struct Gen<T, U> {
278293
var x: T
279294
var y: U

test/Runtime/demangleToMetadataObjC.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ let DemangleToMetadataTests = TestSuite("DemangleToMetadataObjC")
1515
@objc protocol P1 { }
1616
protocol P2 { }
1717
@objc protocol P3: P1 { }
18+
@objc protocol mainP4 { }
1819

1920
DemangleToMetadataTests.test("@objc classes") {
2021
expectEqual(type(of: C()), _typeByMangledName("4main1CC")!)
@@ -25,10 +26,13 @@ DemangleToMetadataTests.test("@objc enums") {
2526
}
2627

2728
func f1_composition_objc_protocol(_: P1) { }
29+
func f1_composition_objc_protocol_P4(_: mainP4) { }
2830

2931
DemangleToMetadataTests.test("@objc protocols") {
3032
expectEqual(type(of: f1_composition_objc_protocol),
3133
_typeByMangledName("yy4main2P1_pc")!)
34+
expectEqual(type(of: f1_composition_objc_protocol_P4),
35+
_typeByMangledName("yy4main0A2P4_pc")!)
3236
}
3337

3438
DemangleToMetadataTests.test("Objective-C classes") {

0 commit comments

Comments
 (0)