Skip to content

Commit 3041694

Browse files
committed
add SILGen test of ObjC effectful property imports
1 parent f5551f3 commit 3041694

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-silgen -I %S/Inputs/custom-modules -enable-experimental-concurrency %s -verify | %FileCheck --enable-var-scope --check-prefix=CHECK --check-prefix=CHECK-%target-cpu %s
2+
// REQUIRES: concurrency
3+
// REQUIRES: objc_interop
4+
5+
import Foundation
6+
import EffectfulProperties
7+
8+
// CHECK-LABEL: sil {{.*}}@${{.*}}13testJustAsync
9+
func testJustAsync(eff : EffProps) async {
10+
// CHECK: [[RESUME_BUF:%.*]] = alloc_stack $NSObject
11+
// CHECK: [[METHOD:%.*]] = objc_method {{.*}} $@convention(objc_method) (@convention(block) (NSObject) -> (), EffProps) -> ()
12+
// CHECK: [[CONT:%.*]] = get_async_continuation_addr NSObject, [[RESUME_BUF]]
13+
// CHECK: [[WRAPPED:%.*]] = struct $UnsafeContinuation<NSObject, Never> ([[CONT]] : $Builtin.RawUnsafeContinuation)
14+
// CHECK: [[BLOCK_STORAGE:%.*]] = alloc_stack $@block_storage UnsafeContinuation<NSObject, Never>
15+
// CHECK: [[CONT_SLOT:%.*]] = project_block_storage [[BLOCK_STORAGE]]
16+
// CHECK: store [[WRAPPED]] to [trivial] [[CONT_SLOT]]
17+
// CHECK: [[BLOCK_IMPL:%.*]] = function_ref @[[NSO_COMPLETION_BLOCK:.*]] : $@convention(c) (@inout_aliasable @block_storage UnsafeContinuation<NSObject, Never>, NSObject) -> ()
18+
// CHECK: [[BLOCK:%.*]] = init_block_storage_header [[BLOCK_STORAGE]] {{.*}}, invoke [[BLOCK_IMPL]]
19+
// CHECK: apply [[METHOD]]([[BLOCK]], %0)
20+
// CHECK: await_async_continuation [[CONT]] {{.*}}, resume [[RESUME:bb[0-9]+]]
21+
22+
// CHECK: [[RESUME]]:
23+
// CHECK: [[RESULT:%.*]] = load [take] [[RESUME_BUF]]
24+
// CHECK: dealloc_stack [[RESUME_BUF]]
25+
let _ = await eff.doggo
26+
}
27+
28+
// CHECK-LABEL: sil {{.*}}@${{.*}}15testAsyncThrows
29+
func testAsyncThrows(eff : EffProps) async {
30+
// CHECK: [[RESUME_BUF:%.*]] = alloc_stack $Optional<NSObject>
31+
// CHECK: [[METHOD:%.*]] = objc_method {{.*}} $@convention(objc_method) (@convention(block) (Optional<NSObject>, Optional<NSError>) -> (), EffProps) -> ()
32+
// CHECK: [[CONT:%.*]] = get_async_continuation_addr [throws] Optional<NSObject>, [[RESUME_BUF]]
33+
// CHECK: [[WRAPPED:%.*]] = struct $UnsafeContinuation<Optional<NSObject>, Error> ([[CONT]] : $Builtin.RawUnsafeContinuation)
34+
// CHECK: [[BLOCK_STORAGE:%.*]] = alloc_stack $@block_storage UnsafeContinuation<Optional<NSObject>, Error>
35+
// CHECK: [[CONT_SLOT:%.*]] = project_block_storage [[BLOCK_STORAGE]]
36+
// CHECK: store [[WRAPPED]] to [trivial] [[CONT_SLOT]]
37+
// CHECK: [[BLOCK_IMPL:%.*]] = function_ref @[[NSO_COMPLETION_BLOCK:.*]] : $@convention(c) (@inout_aliasable @block_storage UnsafeContinuation<Optional<NSObject>, Error>, Optional<NSObject>, Optional<NSError>) -> ()
38+
// CHECK: [[BLOCK:%.*]] = init_block_storage_header [[BLOCK_STORAGE]] {{.*}}, invoke [[BLOCK_IMPL]]
39+
// CHECK: apply [[METHOD]]([[BLOCK]], %0)
40+
// CHECK: await_async_continuation [[CONT]] {{.*}}, resume [[RESUME:bb[0-9]+]], error [[RESUME_ERROR:bb[0-9]+]]
41+
42+
// CHECK: [[RESUME]]:
43+
// CHECK: [[RESULT:%.*]] = load [take] [[RESUME_BUF]]
44+
// CHECK: dealloc_stack [[RESUME_BUF]]
45+
46+
// CHECK: [[RESUME_ERROR]]([[ERROR_VAL:%[0-9]+]] : @owned $Error):
47+
// CHECK: dealloc_stack [[RESUME_BUF]]
48+
let _ = try? await eff.catto
49+
}
50+
51+
// CHECK-LABEL: sil {{.*}}@${{.*}}17testMainActorProp
52+
func testMainActorProp(eff : EffProps) async {
53+
// CHECK-NOT: hop_to_executor
54+
// CHECK: } // end sil function '${{.*}}17testMainActorProp
55+
let _ = await eff.mainDogProp
56+
}
57+
58+
// CHECK-LABEL: sil {{.*}}@${{.*}}19testMainActorMethod
59+
func testMainActorMethod(eff : EffProps) async {
60+
// CHECK-NOT: hop_to_executor
61+
// CHECK: } // end sil function '${{.*}}19testMainActorMethod
62+
let _ = await eff.regularMainDog()
63+
}

0 commit comments

Comments
 (0)