Skip to content

Commit c3b6b49

Browse files
authored
Merge pull request #35300 from jckarter/balance-continuation-copies
SILGen: Copy values fed from completion handler invocation to balance retains.
2 parents f2d28cf + 82fc441 commit c3b6b49

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

lib/SILGen/SILGenThunk.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ SILGenModule::getOrCreateForeignAsyncCompletionHandlerImplFunction(
233233
IsNotDynamic);
234234

235235
if (F->empty()) {
236-
// TODO: Emit the implementation.
236+
// Emit the implementation.
237237
SILGenFunction SGF(*this, *F, SwiftModule);
238238
{
239239
Scope scope(SGF, loc);
@@ -310,7 +310,7 @@ SILGenModule::getOrCreateForeignAsyncCompletionHandlerImplFunction(
310310
// Convert the ObjC argument to the bridged Swift representation we
311311
// want.
312312
ManagedValue bridgedArg = SGF.emitBridgedToNativeValue(loc,
313-
arg,
313+
arg.copy(SGF, loc),
314314
arg.getType().getASTType(),
315315
// FIXME: pass down formal type
316316
destBuf->getType().getASTType(),

test/Inputs/clang-importer-sdk/usr/include/ObjCConcurrency.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ typedef void (^CompletionHandler)(NSString * _Nullable, NSString * _Nullable_res
4747
-(void)doSomethingSlowNullably:(NSString *)operation completionHandler:(void (^ _Nullable)(NSInteger))handler;
4848
-(void)findAnswerNullably:(NSString *)operation completionHandler:(void (^ _Nullable)(NSString *))handler;
4949
-(void)doSomethingDangerousNullably:(NSString *)operation completionHandler:(void (^ _Nullable)(NSString *_Nullable, NSError *_Nullable))handler;
50+
51+
// rdar://72604599
52+
- (void)stopRecordingWithHandler:(nullable void (^)(NSObject *_Nullable_result x, NSError *_Nullable error))handler __attribute__((swift_async_name("stopRecording()"))) __attribute__((swift_async(not_swift_private, 1)));
53+
5054
@end
5155

5256
@protocol RefrigeratorDelegate<NSObject>

test/SILGen/objc_async.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ func testSlowServer(slowServer: SlowServer) async throws {
5858

5959
let _: String = await slowServer.findAnswerNullably("foo")
6060
let _: String = try await slowServer.doSomethingDangerousNullably("foo")
61+
62+
let _: NSObject? = try await slowServer.stopRecording()
6163
}
6264

6365
// CHECK: sil{{.*}}@[[INT_COMPLETION_BLOCK]]
@@ -77,8 +79,9 @@ func testSlowServer(slowServer: SlowServer) async throws {
7779
// CHECK: switch_enum [[ERROR_IN_B]] : {{.*}}, case #Optional.some!enumelt: [[ERROR_BB:bb[0-9]+]], case #Optional.none!enumelt: [[RESUME_BB:bb[0-9]+]]
7880
// CHECK: [[RESUME_BB]]:
7981
// CHECK: [[RESULT_BUF:%.*]] = alloc_stack $String
82+
// CHECK: [[RESUME_CP:%.*]] = copy_value [[RESUME_IN]]
8083
// CHECK: [[BRIDGE:%.*]] = function_ref @{{.*}}unconditionallyBridgeFromObjectiveC
81-
// CHECK: [[BRIDGED_RESULT:%.*]] = apply [[BRIDGE]]([[RESUME_IN]]
84+
// CHECK: [[BRIDGED_RESULT:%.*]] = apply [[BRIDGE]]([[RESUME_CP]]
8285
// CHECK: store [[BRIDGED_RESULT]] to [init] [[RESULT_BUF]]
8386
// CHECK: [[RESUME:%.*]] = function_ref @{{.*}}resumeUnsafeThrowingContinuation
8487
// CHECK: apply [[RESUME]]<String>([[CONT]], [[RESULT_BUF]])

0 commit comments

Comments
 (0)