7
7
@preconcurrency var sendyHandler : @Sendable ( ) -> Void { get set }
8
8
}
9
9
10
+ @preconcurrency class OldWorld {
11
+ @preconcurrency var handler : ( @Sendable ( ) -> Void ) ?
12
+ @preconcurrency var nonOptionalHandler : @Sendable ( ) -> Void = { }
13
+ }
14
+
10
15
// CHECK-LABEL: sil hidden [ossa] @$s19objc_preconcurrency19testDynamicDispatch1p17completionHandleryAA1P_p_yyctF
11
16
// CHECK: dynamic_method_br
12
17
// CHECK: bb{{[0-9]+}}(%{{[0-9]+}} : $@convention(objc_method) (@convention(block) @Sendable () -> (), @opened
@@ -19,26 +24,100 @@ func testDynamicDispatch(p: P, completionHandler: @escaping () -> Void) {
19
24
}
20
25
21
26
// CHECK-LABEL: sil hidden [ossa] @$s19objc_preconcurrency21testOptionalVarAccessyySo12NSTouchGrassCF
22
- // CHECK: unchecked_addr_cast {{.*}} : $* Optional<@Sendable @callee_guaranteed () -> ()> to $* Optional<@callee_guaranteed () -> ()>
27
+ // CHECK: unchecked_bitwise_cast {{.*}} : $Optional<@Sendable @callee_guaranteed () -> ()> to $Optional<@callee_guaranteed () -> ()>
23
28
// CHECK: } // end sil function '$s19objc_preconcurrency21testOptionalVarAccessyySo12NSTouchGrassCF'
24
29
func testOptionalVarAccess( _ grass: NSTouchGrass ) {
25
30
grass. cancellationHandler ? ( )
26
31
}
27
32
33
+ // CHECK-LABEL: sil hidden [ossa] @$s19objc_preconcurrency33testOptionalVarAccessPartialApplyyyycSgSo12NSTouchGrassCF
34
+ // CHECK: unchecked_bitwise_cast {{.*}} : $Optional<@Sendable @callee_guaranteed () -> ()> to $Optional<@callee_guaranteed () -> ()>
35
+ // CHECK: } // end sil function '$s19objc_preconcurrency33testOptionalVarAccessPartialApplyyyycSgSo12NSTouchGrassCF'
36
+ func testOptionalVarAccessPartialApply( _ grass: NSTouchGrass ) -> ( ( ) -> Void ) ? {
37
+ let handler = grass. cancellationHandler
38
+ if let unwrapped = handler {
39
+ unwrapped ( )
40
+ }
41
+ return handler
42
+ }
43
+
44
+ // CHECK-LABEL: sil hidden [ossa] @$s19objc_preconcurrency16testObjCVarWriteyySo12NSTouchGrassCF
45
+ // CHECK: unchecked_bitwise_cast {{.*}} : $Optional<@callee_guaranteed () -> ()> to $Optional<@Sendable @callee_guaranteed () -> ()>
46
+ // CHECK: objc_method {{.*}} : $NSTouchGrass, #NSTouchGrass.cancellationHandler!setter.foreign : (NSTouchGrass) -> ((@Sendable () -> ())?) -> (), $@convention(objc_method) (Optional<@convention(block) @Sendable () -> ()>, NSTouchGrass) -> ()
47
+ // CHECK: } // end sil function '$s19objc_preconcurrency16testObjCVarWriteyySo12NSTouchGrassCF'
48
+ func testObjCVarWrite( _ grass: NSTouchGrass ) {
49
+ grass. cancellationHandler = { }
50
+ }
51
+
52
+ // the below looks kinda long and wonky, but is expected. for a summary, the steps are:
53
+ // 1. objc to native
54
+ // 2. Sendable to non-Sendable (major part of this test)
55
+ // 3. non-optional to optional
56
+ // 4. from non-Sendable to Sendable (major part of this test)
57
+ // 5. from native to objc (which involves unwrapping and rewrapping that optional; kinda silly but optimization will clean it up)
58
+ //
59
+ // CHECK-LABEL: sil hidden [ossa] @$s19objc_preconcurrency22testObjCVarWriteAcrossyySo12NSTouchGrassCF
60
+ // CHECK: [[GET_EXCEPTION:%[0-9]+]] = objc_method {{.*}} : $NSTouchGrass, #NSTouchGrass.exceptionHandler!getter.foreign
61
+ // CHECK: [[SENDABLE_BLOCK:%[0-9]+]] = apply [[GET_EXCEPTION]]({{.*}}) : $@convention(objc_method) (NSTouchGrass) -> @autoreleased @convention(block) @Sendable () -> ()
62
+ // << step 1 >>
63
+ // CHECK: [[NATIVE_THUNK:%[0-9]+]] = function_ref @$sIeyBh_Iegh_TR : $@convention(thin) @Sendable (@guaranteed @convention(block) @Sendable () -> ()) -> ()
64
+ // CHECK: [[NATIVE_SENDABLE_EXCEPTION:%[0-9]+]] = partial_apply [callee_guaranteed] [[NATIVE_THUNK]]([[SENDABLE_BLOCK]])
65
+ // << step 2 >>
66
+ // CHECK: [[NATIVE_EXCEPTION:%[0-9]+]] = convert_function [[NATIVE_SENDABLE_EXCEPTION]] : $@Sendable @callee_guaranteed () -> () to $@callee_guaranteed () -> ()
67
+ // << step 3 >>
68
+ // CHECK: [[OPTIONAL_NATIVE_EXCEPTION:%[0-9]+]] = enum $Optional<@callee_guaranteed () -> ()>, #Optional.some!enumelt, [[NATIVE_EXCEPTION]] : $@callee_guaranteed () -> ()
69
+ // << step 4 >>
70
+ // CHECK: = unchecked_bitwise_cast [[OPTIONAL_NATIVE_EXCEPTION]] : $Optional<@callee_guaranteed () -> ()> to $Optional<@Sendable @callee_guaranteed () -> ()>
71
+ // << step 5 >>
72
+ // CHECK: switch_enum {{.*}} : $Optional<@Sendable @callee_guaranteed () -> ()>
73
+ //
74
+ // CHECK: bb1({{.*}} : @owned $@Sendable @callee_guaranteed () -> ()):
75
+ // CHECK: init_block_storage_header {{.*}} : $*@block_storage @Sendable @callee_guaranteed () -> ()
76
+ // CHECK: } // end sil function '$s19objc_preconcurrency22testObjCVarWriteAcrossyySo12NSTouchGrassCF'
77
+ func testObjCVarWriteAcross( _ grass: NSTouchGrass ) {
78
+ grass. cancellationHandler = grass. exceptionHandler // *slaps roof of assignment* this bad boy can fit so much conversion in it!
79
+ }
80
+
81
+ // CHECK-LABEL: sil hidden [ossa] @$s19objc_preconcurrency25testOptionalAssignSetter1yyAA8OldWorldCF
82
+ // CHECK: unchecked_bitwise_cast {{.*}} : $Optional<@callee_guaranteed () -> ()> to $Optional<@Sendable @callee_guaranteed () -> ()>
83
+ // CHECK: #OldWorld.handler!setter : (OldWorld) -> ((@Sendable () -> ())?) -> ()
84
+ // CHECK: } // end sil function '$s19objc_preconcurrency25testOptionalAssignSetter1yyAA8OldWorldCF'
85
+ func testOptionalAssignSetter1( _ oldWorld: OldWorld ) {
86
+ oldWorld. handler = { }
87
+ }
88
+
89
+ // CHECK-LABEL: sil hidden [ossa] @$s19objc_preconcurrency25testOptionalAssignSetter2yyAA8OldWorldCF
90
+ // CHECK: convert_function {{.*}} : $@callee_guaranteed () -> () to $@Sendable @callee_guaranteed () -> ()
91
+ // CHECK: $OldWorld, #OldWorld.nonOptionalHandler!setter : (OldWorld) -> (@escaping @Sendable () -> ()) -> ()
92
+ // CHECK: } // end sil function '$s19objc_preconcurrency25testOptionalAssignSetter2yyAA8OldWorldCF'
93
+ func testOptionalAssignSetter2( _ oldWorld: OldWorld ) {
94
+ oldWorld. nonOptionalHandler = { }
95
+ }
96
+
28
97
func modify( _ v: inout ( ) -> Void ) {
29
98
v = { }
30
99
}
31
100
32
101
// CHECK-LABEL: sil hidden [ossa] @$s19objc_preconcurrency15testInoutAccessyySo12NSTouchGrassCF
33
- // CHECK: unchecked_addr_cast {{.*}} : $*@Sendable @callee_guaranteed () -> () to $*@callee_guaranteed () -> ()
102
+ // CHECK: [[BEFORE_MODIFY:%[0-9]+]] = convert_function {{.*}} : $@Sendable @callee_guaranteed () -> () to $@callee_guaranteed () -> ()
103
+ // CHECK: store [[BEFORE_MODIFY]] to [init] [[INOUT_ALLOC:%[0-9]+]] : $*@callee_guaranteed () -> ()
104
+ // CHECK: [[MODIFY_FN:%[0-9]+]] = function_ref @$s19objc_preconcurrency6modifyyyyyczF : $@convention(thin) (@inout @callee_guaranteed () -> ()) -> ()
105
+ // CHECK: = apply [[MODIFY_FN]]([[INOUT_ALLOC]])
106
+ // CHECK: [[AFTER_MODIFY:%[0-9]+]] = load [take] [[INOUT_ALLOC]] : $*@callee_guaranteed () -> ()
107
+ // CHECK: convert_function [[AFTER_MODIFY]] : $@callee_guaranteed () -> () to $@Sendable @callee_guaranteed () -> ()
34
108
// CHECK: } // end sil function '$s19objc_preconcurrency15testInoutAccessyySo12NSTouchGrassCF'
35
109
func testInoutAccess( _ grass: NSTouchGrass ) {
36
110
modify ( & grass. exceptionHandler)
37
111
}
38
112
39
113
40
114
// CHECK-LABEL: sil hidden [ossa] @$s19objc_preconcurrency21testProtocolVarAccess1pyAA1P_p_tF
41
- // CHECK: unchecked_addr_cast {{.*}} : $*@Sendable @callee_guaranteed () -> () to $*@callee_guaranteed () -> ()
115
+ // CHECK: [[BEFORE_MODIFY:%[0-9]+]] = convert_function {{.*}} : $@Sendable @callee_guaranteed () -> () to $@callee_guaranteed () -> ()
116
+ // CHECK: store [[BEFORE_MODIFY]] to [init] [[INOUT_ALLOC:%[0-9]+]] : $*@callee_guaranteed () -> ()
117
+ // CHECK: [[MODIFY_FN:%[0-9]+]] = function_ref @$s19objc_preconcurrency6modifyyyyyczF : $@convention(thin) (@inout @callee_guaranteed () -> ()) -> ()
118
+ // CHECK: = apply [[MODIFY_FN]]([[INOUT_ALLOC]])
119
+ // CHECK: [[AFTER_MODIFY:%[0-9]+]] = load [take] [[INOUT_ALLOC]] : $*@callee_guaranteed () -> ()
120
+ // CHECK: convert_function [[AFTER_MODIFY]] : $@callee_guaranteed () -> () to $@Sendable @callee_guaranteed () -> ()
42
121
// CHECK: } // end sil function '$s19objc_preconcurrency21testProtocolVarAccess1pyAA1P_p_tF'
43
122
func testProtocolVarAccess( p: P ) {
44
123
modify ( & p. sendyHandler)
0 commit comments