Skip to content

Commit 6c47454

Browse files
Merge pull request #36827 from varungandhi-apple/vg-objc-proto-no-extended-encoding
[IRGen] Don't use extended encoding for async @objc protocol methods.
2 parents 07dc2a9 + 117e6ca commit 6c47454

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

lib/IRGen/GenObjC.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,10 +1185,11 @@ irgen::emitObjCMethodDescriptorParts(IRGenModule &IGM,
11851185
/// with numbers that used to represent stack offsets for each of these
11861186
/// elements.
11871187
CanSILFunctionType methodType = getObjCMethodType(IGM, method);
1188-
descriptor.typeEncoding =
1189-
getObjCEncodingForMethod(IGM, methodType, /*extended*/ method->hasAsync(),
1190-
method);
11911188

1189+
bool useExtendedEncoding =
1190+
method->hasAsync() && !isa<ProtocolDecl>(method->getDeclContext());
1191+
descriptor.typeEncoding = getObjCEncodingForMethod(
1192+
IGM, methodType, /*extended*/ useExtendedEncoding, method);
11921193
/// The third element is the method implementation pointer.
11931194
if (!concrete) {
11941195
descriptor.impl = nullptr;

test/IRGen/objc_async_metadata.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,16 @@ class MyClass: NSObject {
2121
@objc func method() async -> String { "" }
2222
@objc func throwingMethod() async throws -> String { "" }
2323
}
24+
25+
// CHECK: [[ENCODE_ASYNC_STRING_PROTO:@.*]] = private unnamed_addr constant [15 x i8] c"v32@0:8@16@?24\00"
26+
// CHECK-LABEL: @_PROTOCOL_INSTANCE_METHODS__TtP19objc_async_metadata7MyProto_ = internal constant
27+
// CHECK-SAME: _selector_data(myProtoRequirement:completionHandler:)
28+
// CHECK-SAME: [15 x i8]* [[ENCODE_ASYNC_STRING_PROTO]]
29+
30+
// CHECK: [[ENCODE_ASYNC_STRING_PROTO_TYPE:@.*]] = private unnamed_addr constant [41 x i8] c"v32@0:8@\22NSString\2216@?<v@?@\22NSString\22>24\00"
31+
// CHECK-LABEL: @_PROTOCOL_METHOD_TYPES__TtP19objc_async_metadata7MyProto_ = internal constant
32+
// CHECK-SAME: [41 x i8]* [[ENCODE_ASYNC_STRING_PROTO_TYPE]]
33+
34+
@objc protocol MyProto {
35+
@objc func myProtoRequirement(_ x: String) async -> String
36+
}

0 commit comments

Comments
 (0)