@@ -21,16 +21,21 @@ import _Concurrency
21
21
22
22
class Klass {}
23
23
24
- class NonSendableKlass { // expected-note 2 {{}}
24
+ class NonSendableKlass { // expected-note 4 {{}}
25
25
var klass: Klass
26
26
27
27
func asyncCall() async
28
+
29
+ @MainActor static func getValue() -> sending NonSendableKlass
28
30
}
29
31
30
32
sil @transferNonSendableKlass : $@convention(thin) @async (@guaranteed NonSendableKlass) -> ()
31
33
sil @useNonSendableKlass : $@convention(thin) (@guaranteed NonSendableKlass) -> ()
34
+ sil @useNonSendableKlassAsync : $@convention(thin) @async (@guaranteed NonSendableKlass) -> ()
32
35
sil @constructNonSendableKlass : $@convention(thin) () -> @owned NonSendableKlass
33
36
sil @useUnmanagedNonSendableKlass : $@convention(thin) (@guaranteed @sil_unmanaged NonSendableKlass) -> ()
37
+ sil @constructNonSendableKlassAsync : $@convention(thin) @async () -> @owned NonSendableKlass
38
+ sil @constructNonSendableKlassAsyncSending : $@convention(thin) @async () -> @sil_sending @owned NonSendableKlass
34
39
35
40
final class SendableKlass : Sendable {}
36
41
@@ -376,11 +381,60 @@ bb0(%0 : @guaranteed $Self):
376
381
return %9999 : $()
377
382
}
378
383
384
+ sil [ossa] @sending_direct_result_from_callee : $@convention(thin) @async () -> () {
385
+ bb0:
386
+ %0 = function_ref @constructNonSendableKlassAsyncSending : $@convention(thin) @async () -> @sil_sending @owned NonSendableKlass
387
+ %1 = apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %0() : $@convention(thin) @async () -> @sil_sending @owned NonSendableKlass
388
+
389
+ %useValue = function_ref @useNonSendableKlassAsync : $@convention(thin) @async (@guaranteed NonSendableKlass) -> ()
390
+ apply [caller_isolation=nonisolated] [callee_isolation=actor_instance] %useValue(%1) : $@convention(thin) @async (@guaranteed NonSendableKlass) -> ()
391
+ destroy_value %1
392
+
393
+ // Double check we actually error without @sil_sending
394
+ %2 = function_ref @constructNonSendableKlassAsync : $@convention(thin) @async () -> @owned NonSendableKlass
395
+ %3 = apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %2() : $@convention(thin) @async () -> @owned NonSendableKlass
396
+ // expected-warning @-1 {{non-Sendable 'NonSendableKlass'-typed result can not be returned from global actor '<null>'-isolated function to nonisolated context}}
397
+
398
+ apply [caller_isolation=nonisolated] [callee_isolation=actor_instance] %useValue(%3) : $@convention(thin) @async (@guaranteed NonSendableKlass) -> ()
399
+ // expected-warning @-1 {{sending value of non-Sendable type 'NonSendableKlass' risks causing data races}}
400
+ // expected-note @-2 {{}}
401
+
402
+ destroy_value %3
403
+
404
+ %9999 = tuple ()
405
+ return %9999 : $()
406
+ }
407
+
408
+ sil [ossa] @sending_direct_result_from_callee_2 : $@convention(thin) @async () -> () {
409
+ bb0:
410
+ %0 = function_ref @constructNonSendableKlassAsyncSending : $@convention(thin) @async () -> @sil_sending @owned NonSendableKlass
411
+ %1 = apply [caller_isolation=global_actor] [callee_isolation=global_actor] %0() : $@convention(thin) @async () -> @sil_sending @owned NonSendableKlass
412
+
413
+ %useValue = function_ref @useNonSendableKlassAsync : $@convention(thin) @async (@guaranteed NonSendableKlass) -> ()
414
+ apply [caller_isolation=global_actor] [callee_isolation=actor_instance] %useValue(%1) : $@convention(thin) @async (@guaranteed NonSendableKlass) -> ()
415
+ destroy_value %1
416
+
417
+ // Double check we actually error without @sil_sending
418
+ %2 = function_ref @constructNonSendableKlassAsync : $@convention(thin) @async () -> @owned NonSendableKlass
419
+ %3 = apply [caller_isolation=global_actor] [callee_isolation=global_actor] %2() : $@convention(thin) @async () -> @owned NonSendableKlass
420
+ // expected-warning @-1 {{non-Sendable 'NonSendableKlass'-typed result can not be returned from global actor '<null>'-isolated function to global actor '<null>'-isolated context}}
421
+
422
+ apply [caller_isolation=global_actor] [callee_isolation=actor_instance] %useValue(%3) : $@convention(thin) @async (@guaranteed NonSendableKlass) -> ()
423
+ // expected-warning @-1 {{sending value of non-Sendable type 'NonSendableKlass' risks causing data races}}
424
+ // expected-note @-2 {{}}
425
+
426
+ destroy_value %3
427
+
428
+ %9999 = tuple ()
429
+ return %9999 : $()
430
+ }
431
+
432
+
379
433
sil @closureForCheckedContinuation : $@convention(thin) <τ_0_0> (@in_guaranteed CheckedContinuation<τ_0_0, Never>) -> ()
380
434
sil @withCheckedContinuation : $@convention(thin) @async <τ_0_0> (@sil_isolated @guaranteed Optional<any Actor>, @guaranteed @noescape @callee_guaranteed <τ_0_0> (@in_guaranteed CheckedContinuation<τ_0_0, Never>) -> ()) -> @sil_sending @out τ_0_0
381
435
382
436
// We shouldn't emit any error here due to sil_sending.
383
- sil [ossa] @sending_result_from_callee : $@convention(thin) @async () -> () {
437
+ sil [ossa] @sending_indirect_result_from_callee : $@convention(thin) @async () -> () {
384
438
bb0:
385
439
%0 = alloc_stack $NonSendableKlass
386
440
%1 = function_ref @closureForCheckedContinuation : $@convention(thin) <τ_0_0> (@in_guaranteed CheckedContinuation<τ_0_0, Never>) -> ()
0 commit comments