Skip to content

Commit 21f9539

Browse files
committed
[Concurrency] Emit extended method type descriptors for @objc async methods.
For `@objc async` methods, all of the important information about the "result" type and whether it throws or not is within the type of the completion handler block. Enable extended type information for the generated Objective-C metadata of such methods, so that clients can understand how to invoke them using reflection facilities. Implements rdar://73048313.
1 parent 344747c commit 21f9539

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/IRGen/GenObjC.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,8 @@ irgen::emitObjCMethodDescriptorParts(IRGenModule &IGM,
11841184
/// elements.
11851185
CanSILFunctionType methodType = getObjCMethodType(IGM, method);
11861186
descriptor.typeEncoding =
1187-
getObjCEncodingForMethod(IGM, methodType, /*extended*/ false, method);
1187+
getObjCEncodingForMethod(IGM, methodType, /*extended*/ method->hasAsync(),
1188+
method);
11881189

11891190
/// The third element is the method implementation pointer.
11901191
if (!concrete) {

test/IRGen/objc_async_metadata.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %build-irgen-test-overlays
3+
// RUN: %target-swift-frontend(mock-sdk: -sdk %S/Inputs -I %t) -enable-experimental-concurrency %s -emit-ir | %FileCheck %s
4+
5+
// REQUIRES: OS=macosx
6+
// REQUIRES: concurrency
7+
// REQUIRES: objc_interop
8+
9+
10+
import Foundation
11+
12+
// CHECK: [[ENCODE_ASYNC_STRING:@.*]] = private unnamed_addr constant [28 x i8] c"v24@0:8@?<v@?@\22NSString\22>16\00"
13+
// CHECK: [[ENCODE_ASYNC_THROWS_STRING:@.*]] = private unnamed_addr constant [38 x i8] c"v24@0:8@?<v@?@\22NSString\22@\22NSError\22>16\00"
14+
15+
// CHECK: @_INSTANCE_METHODS__TtC19objc_async_metadata7MyClass = internal constant
16+
// CHECK-SAME: methodWithCompletionHandler:
17+
// CHECK-SAME: [[ENCODE_ASYNC_STRING]]
18+
// CHECK-SAME: throwingMethodWithCompletionHandler:
19+
// CHECK-SAME: [[ENCODE_ASYNC_THROWS_STRING]]
20+
class MyClass: NSObject {
21+
@objc func method() async -> String { "" }
22+
@objc func throwingMethod() async throws -> String { "" }
23+
}

0 commit comments

Comments
 (0)