Skip to content

Commit 7bbb63a

Browse files
authored
Merge pull request #77631 from xedin/rdar-134442168
[SILGen] ResultPlan: Make sure that checked continuations are destroye…
2 parents da5ce12 + 6fef6f5 commit 7bbb63a

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

lib/SILGen/ResultPlan.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,7 @@ class ForeignAsyncInitializationPlan final : public ResultPlan {
782782
SGF.emitApplyOfLibraryIntrinsic(loc, createIntrinsic, subs,
783783
{continuationMV}, SGFContext())
784784
.forwardInto(SGF, loc, underlyingInit.get());
785+
SGF.enterDestroyCleanup(underlyingContinuationAddr);
785786
} else {
786787
SGF.B.createStore(loc, wrappedContinuation, underlyingContinuationAddr,
787788
StoreOwnershipQualifier::Trivial);

test/SILGen/objc_async_checked.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ func testSlowServer(slowServer: SlowServer) async throws {
2525
// CHECK: [[BLOCK:%.*]] = init_block_storage_header [[BLOCK_STORAGE]] {{.*}}, invoke [[BLOCK_IMPL]]
2626
// CHECK: apply [[METHOD]]([[ARG]], [[BLOCK]], %0)
2727
// CHECK: [[COPY:%.*]] = copy_value [[ARG]]
28+
// CHECK: destroy_addr [[CHECKED_CONT_SLOT]] : $*CheckedContinuation<Int, Never>
29+
// CHECK: dealloc_stack [[CHECKED_CONT]] : $*CheckedContinuation<Int, Never>
30+
// CHECK: dealloc_stack %20 : $*@block_storage Any
2831
// CHECK: destroy_value [[ARG]]
2932
// CHECK: await_async_continuation [[CONT]] {{.*}}, resume [[RESUME:bb[0-9]+]]
3033
// CHECK: [[RESUME]]:
@@ -50,6 +53,8 @@ func testSlowServer(slowServer: SlowServer) async throws {
5053
// CHECK: [[BLOCK_IMPL:%.*]] = function_ref @[[STRING_COMPLETION_THROW_BLOCK:.*]] : $@convention(c) (@inout_aliasable @block_storage Any, Optional<NSString>, Optional<NSError>) -> ()
5154
// CHECK: [[BLOCK:%.*]] = init_block_storage_header [[BLOCK_STORAGE]] {{.*}}, invoke [[BLOCK_IMPL]]
5255
// CHECK: apply [[METHOD]]([[BLOCK]], %0)
56+
// CHECK: destroy_addr [[CHECKED_CONT_SLOT]] : $*CheckedContinuation<String, any Error>
57+
// CHECK: dealloc_stack [[CHECKED_CONT]] : $*CheckedContinuation<String, any Error>
5358
// CHECK: await_async_continuation [[CONT]] {{.*}}, resume [[RESUME:bb[0-9]+]], error [[ERROR:bb[0-9]+]]
5459
// CHECK: [[RESUME]]:
5560
// CHECK: [[RESULT:%.*]] = load [take] [[RESUME_BUF]]
@@ -207,6 +212,8 @@ func testSlowServerFromMain(slowServer: SlowServer) async throws {
207212
// CHECK: [[BLOCK:%.*]] = init_block_storage_header [[BLOCK_STORAGE]] {{.*}}, invoke [[BLOCK_IMPL]]
208213
// CHECK: apply [[METHOD]]([[ARG]], [[BLOCK]], %0)
209214
// CHECK: [[COPY:%.*]] = copy_value [[ARG]]
215+
// CHECK: destroy_addr [[CHECKED_CONT_SLOT]] : $*CheckedContinuation<Int, Never>
216+
// CHECK: dealloc_stack [[CHECKED_CONT]] : $*CheckedContinuation<Int, Never>
210217
// CHECK: destroy_value [[ARG]]
211218
// CHECK: await_async_continuation [[CONT]] {{.*}}, resume [[RESUME:bb[0-9]+]]
212219
// CHECK: [[RESUME]]:
@@ -232,6 +239,8 @@ func testSlowServerFromMain(slowServer: SlowServer) async throws {
232239
// CHECK: [[CHECKED_CONT:%.*]] = alloc_stack $CheckedContinuation<String, any Error>
233240
// CHECK: {{.*}} = apply [[CHECKED_CONT_INIT_FN]]<String>([[CHECKED_CONT]], [[UNSAFE_CONT]]) : $@convention(thin) <τ_0_0> (UnsafeContinuation<τ_0_0, any Error>) -> @out CheckedContinuation<τ_0_0, any Error>
234241
// CHECK: copy_addr [take] [[CHECKED_CONT]] to [init] [[CHECKED_CONT_SLOT]] : $*CheckedContinuation<String, any Error>
242+
// CHECK: destroy_addr [[CHECKED_CONT_SLOT]] : $*CheckedContinuation<String, any Error>
243+
// CHECK: dealloc_stack [[CHECKED_CONT]] : $*CheckedContinuation<String, any Error>
235244
// CHECK: cond_br {{.*}}, [[RESUME:bb[0-9]+]], [[ERROR:bb[0-9]+]]
236245
//
237246
// CHECK: [[ERROR]]:
@@ -268,6 +277,7 @@ func testThrowingMethodFromMain(slowServer: SlowServer) async -> String {
268277
// CHECK: [[OPTIONAL_BLK:%.*]] = enum {{.*}}, #Optional.some!enumelt, [[BLOCK]]
269278
// CHECK: {{.*}} = apply [[METH]]([[STRING_ARG]], [[OPTIONAL_BLK]], {{%.*}}) : $@convention(objc_method) (NSString, Optional<@convention(block) (Optional<NSString>, Optional<NSError>) -> ()>, SlowServer) -> ()
270279
// CHECK: [[STRING_ARG_COPY:%.*]] = copy_value [[STRING_ARG]] : $NSString
280+
// CHECK: destroy_addr [[CHECKED_CONT_SLOT]] : $*CheckedContinuation<String, any Error>
271281
// CHECK: dealloc_stack [[CHECKED_CONT]] : $*CheckedContinuation<String, any Error>
272282
// CHECK: dealloc_stack [[STORE_ALLOC]] : $*@block_storage Any
273283
// CHECK: destroy_value [[STRING_ARG]] : $NSString
@@ -302,6 +312,8 @@ func testThrowingMethodFromMain(slowServer: SlowServer) async -> String {
302312
// CHECK: [[METH:%.*]] = objc_method {{%.*}} : $@objc_metatype Person.Type, #Person.asCustomer!foreign
303313
// CHECK: get_async_continuation_addr NSObject, [[RESULT_BUF]] : $*NSObject
304314
// CHECK: = apply [[METH]]
315+
// CHECK: destroy_addr {{.*}} : $*CheckedContinuation<NSObject, Never>
316+
// CHECK: dealloc_stack {{.*}} : $*CheckedContinuation<NSObject, Never>
305317
// CHECK: dealloc_stack {{%.*}} : $*@block_storage
306318
// CHECK: await_async_continuation {{%.*}} : $Builtin.RawUnsafeContinuation, resume bb1
307319
// CHECK: bb1:
@@ -349,6 +361,8 @@ extension OptionalMemberLookups {
349361
// CHECK: = function_ref @$sIeyB_yt18objc_async_checked21OptionalMemberLookupsRzlTz_ : $@convention(c) @pseudogeneric <τ_0_0 where τ_0_0 : OptionalMemberLookups> (@inout_aliasable @block_storage Any) -> ()
350362
// CHECK: [[BLOCK:%[0-9]+]] = init_block_storage_header {{.*}} : $*@block_storage Any
351363
// CHECK: = apply [[METH]]([[BLOCK]], [[SELF]]) : $@convention(objc_method) (@convention(block) () -> (), Self) -> ()
364+
// CHECK: destroy_addr [[CHECKED_CONT_SLOT]] : $*CheckedContinuation<(), Never>
365+
// CHECK: dealloc_stack [[CHECKED_CONT]] : $*CheckedContinuation<(), Never>
352366
// CHECK: await_async_continuation {{.*}} : $Builtin.RawUnsafeContinuation, resume bb1
353367
// CHECK: hop_to_executor {{.*}} : $MainActor
354368
// CHECK: } // end sil function '$s18objc_async_checked21OptionalMemberLookupsPAAE19testForceDirectCallyyYaF'

test/SILGen/objc_effectful_properties_checked.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ func testJustAsync(eff : EffProps) async {
2121
// CHECK: [[BLOCK_IMPL:%.*]] = function_ref @[[NSO_COMPLETION_BLOCK:.*]] : $@convention(c) (@inout_aliasable @block_storage Any, NSObject) -> ()
2222
// CHECK: [[BLOCK:%.*]] = init_block_storage_header [[BLOCK_STORAGE]] {{.*}}, invoke [[BLOCK_IMPL]]
2323
// CHECK: apply [[METHOD]]([[BLOCK]], %0)
24+
// CHECK: destroy_addr [[CHECKED_CONT_SLOT]] : $*CheckedContinuation<NSObject, Never>
25+
// CHECK: dealloc_stack [[CHECKED_CONT]] : $*CheckedContinuation<NSObject, Never>
2426
// CHECK: await_async_continuation [[CONT]] {{.*}}, resume [[RESUME:bb[0-9]+]]
2527

2628
// CHECK: [[RESUME]]:
@@ -45,6 +47,8 @@ func testAsyncThrows(eff : EffProps) async {
4547
// CHECK: [[BLOCK_IMPL:%.*]] = function_ref @[[NSO_COMPLETION_BLOCK:.*]] : $@convention(c) (@inout_aliasable @block_storage Any, Optional<NSObject>, Optional<NSError>) -> ()
4648
// CHECK: [[BLOCK:%.*]] = init_block_storage_header [[BLOCK_STORAGE]] {{.*}}, invoke [[BLOCK_IMPL]]
4749
// CHECK: apply [[METHOD]]([[BLOCK]], %0)
50+
// CHECK: destroy_addr [[CHECKED_CONT_SLOT]] : $*CheckedContinuation<Optional<NSObject>, any Error>
51+
// CHECK: dealloc_stack [[CHECKED_CONT]] : $*CheckedContinuation<Optional<NSObject>, any Error>
4852
// CHECK: await_async_continuation [[CONT]] {{.*}}, resume [[RESUME:bb[0-9]+]], error [[RESUME_ERROR:bb[0-9]+]]
4953

5054
// CHECK: [[RESUME]]:

0 commit comments

Comments
 (0)