You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[AST] NonisolatedNonsendingByDefault: Print @concurrent on nonisolated async function types
With the feature enabled any function type without an explicit `@concurrent`
is going to be inferred to be `nonisolated(nonsending)`. `@concurrent` should
always be printed for diagnostic and other purposes because the isolation
checking would consider them to be `nonisolated(nonsending)` otherwise, especially
important to code produced by fix-its.
Resolves: rdar://161739470
Copy file name to clipboardExpand all lines: test/Concurrency/attr_execution/nonisolated_nonsending_by_default.swift
+14-1Lines changed: 14 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,19 @@
5
5
func testCasts(){
6
6
letdefaultedType=(()async->()).self
7
7
_ = defaultedType as(@concurrent()async->()).Type
8
-
// expected-error@-1 {{cannot convert value of type '(nonisolated(nonsending) () async -> ()).Type' to type '(() async -> ()).Type' in coercion}}
8
+
// expected-error@-1 {{cannot convert value of type '(nonisolated(nonsending) () async -> ()).Type' to type '(@concurrent () async -> ()).Type' in coercion}}
9
9
_ = defaultedType as(nonisolated(nonsending)()async->()).Type // Ok
10
10
}
11
+
12
+
protocolTestWitnessFixIts{
13
+
func test(_:@concurrent()async->Void)
14
+
// expected-note@-1 {{protocol requires function 'test' with type '(@concurrent () async -> Void) -> ()'}}
15
+
}
16
+
17
+
do{
18
+
structTest:TestWitnessFixIts{ // expected-error {{type 'Test' does not conform to protocol 'TestWitnessFixIts'}}
Task.detached{ x =1} // expected-warning {{sending value of non-Sendable type '() async -> ()' risks causing data races}}
1882
-
// expected-note @-1 {{Passing value of non-Sendable type '() async -> ()' as a 'sending' argument to static method 'detached(name:priority:operation:)' risks causing races in between local and caller code}}
1881
+
Task.detached{ x =1}
1882
+
// expected-ni-warning @-1 {{sending value of non-Sendable type '() async -> ()' risks causing data races}}
1883
+
// expected-ni-note @-2 {{Passing value of non-Sendable type '() async -> ()' as a 'sending' argument to static method 'detached(name:priority:operation:)' risks causing races in between local and caller code}}
1884
+
// expected-ni-ns-warning @-3 {{sending value of non-Sendable type '@concurrent () async -> ()' risks causing data races}}
1885
+
// expected-ni-ns-note @-4 {{Passing value of non-Sendable type '@concurrent () async -> ()' as a 'sending' argument to static method 'detached(name:priority:operation:)' risks causing races in between local and caller code}}
1883
1886
1884
1887
x =2 // expected-note {{access can happen concurrently}}
Task.detached{ x =1} // expected-warning {{sending value of non-Sendable type '() async -> ()' risks causing data races}}
1892
-
// expected-note @-1 {{Passing value of non-Sendable type '() async -> ()' as a 'sending' argument to static method 'detached(name:priority:operation:)' risks causing races in between local and caller code}}
1894
+
Task.detached{ x =1}
1895
+
// expected-ni-warning @-1 {{sending value of non-Sendable type '() async -> ()' risks causing data races}}
1896
+
// expected-ni-note @-2 {{Passing value of non-Sendable type '() async -> ()' as a 'sending' argument to static method 'detached(name:priority:operation:)' risks causing races in between local and caller code}}
1897
+
// expected-ni-ns-warning @-3 {{sending value of non-Sendable type '@concurrent () async -> ()' risks causing data races}}
1898
+
// expected-ni-ns-note @-4 {{Passing value of non-Sendable type '@concurrent () async -> ()' as a 'sending' argument to static method 'detached(name:priority:operation:)' risks causing races in between local and caller code}}
1893
1899
1894
1900
print(x) // expected-note {{access can happen concurrently}}
awaitnormalGlobalActorAcceptsAsyncClosure{} // expected-error {{sending value of non-Sendable type '() async -> ()' risks causing data races}}
174
-
// expected-note @-1 {{sending global actor 'CustomActor'-isolated value of non-Sendable type '() async -> ()' to main actor-isolated global function 'normalGlobalActorAcceptsAsyncClosure' risks causing races in between global actor 'CustomActor'-isolated and main actor-isolated uses}}
173
+
awaitnormalGlobalActorAcceptsAsyncClosure{}
174
+
// expected-ni-error @-1 {{sending value of non-Sendable type '() async -> ()' risks causing data races}}
175
+
// expected-ni-note @-2 {{sending global actor 'CustomActor'-isolated value of non-Sendable type '() async -> ()' to main actor-isolated global function 'normalGlobalActorAcceptsAsyncClosure' risks causing races in between global actor 'CustomActor'-isolated and main actor-isolated uses}}
176
+
// expected-ni-ns-error @-3 {{sending value of non-Sendable type '@concurrent () async -> ()' risks causing data races}}
177
+
// expected-ni-ns-note @-4 {{sending global actor 'CustomActor'-isolated value of non-Sendable type '@concurrent () async -> ()' to main actor-isolated global function 'normalGlobalActorAcceptsAsyncClosure' risks causing races in between global actor 'CustomActor'-isolated and main actor-isolated uses}}
175
178
176
179
// CHECK-LABEL: // closure #2 in test_CallerSyncNormal_CalleeAsyncMainActorIsolated()
awaitasyncNormalGlobalActorAcceptsAsyncClosure{} // expected-error {{sending value of non-Sendable type '() async -> ()' risks causing data races}}
290
-
// expected-note @-1 {{sending global actor 'CustomActor'-isolated value of non-Sendable type '() async -> ()' to main actor-isolated global function 'asyncNormalGlobalActorAcceptsAsyncClosure' risks causing races in between global actor 'CustomActor'-isolated and main actor-isolated uses}}
292
+
awaitasyncNormalGlobalActorAcceptsAsyncClosure{}
293
+
// expected-ni-error @-1 {{sending value of non-Sendable type '() async -> ()' risks causing data races}}
294
+
// expected-ni-note @-2 {{sending global actor 'CustomActor'-isolated value of non-Sendable type '() async -> ()' to main actor-isolated global function 'asyncNormalGlobalActorAcceptsAsyncClosure' risks causing races in between global actor 'CustomActor'-isolated and main actor-isolated uses}}
295
+
// expected-ni-ns-error @-3 {{sending value of non-Sendable type '@concurrent () async -> ()' risks causing data races}}
296
+
// expected-ni-ns-note @-4 {{sending global actor 'CustomActor'-isolated value of non-Sendable type '@concurrent () async -> ()' to main actor-isolated global function 'asyncNormalGlobalActorAcceptsAsyncClosure' risks causing races in between global actor 'CustomActor'-isolated and main actor-isolated uses}}
291
297
292
298
// CHECK-LABEL: // closure #2 in test_CallerAsyncNormal_CalleeAsyncMainActorIsolated()
293
299
// CHECK-NEXT: // Isolation: nonisolated
@@ -397,8 +403,11 @@ extension MyActor {
397
403
398
404
// CHECK-LABEL: // closure #1 in MyActor.test_CallerSyncNormal_CalleeAsyncMainActorIsolated()
awaitnormalGlobalActorAcceptsAsyncClosure{print(self)} // expected-error {{sending value of non-Sendable type '() async -> ()' risks causing data races}}
401
-
// expected-note @-1 {{sending 'self'-isolated value of non-Sendable type '() async -> ()' to main actor-isolated global function 'normalGlobalActorAcceptsAsyncClosure' risks causing races in between 'self'-isolated and main actor-isolated uses}}
// expected-ni-error @-1 {{sending value of non-Sendable type '() async -> ()' risks causing data races}}
408
+
// expected-ni-note @-2 {{sending 'self'-isolated value of non-Sendable type '() async -> ()' to main actor-isolated global function 'normalGlobalActorAcceptsAsyncClosure' risks causing races in between 'self'-isolated and main actor-isolated uses}}
409
+
// expected-ni-ns-error @-3 {{sending value of non-Sendable type '@concurrent () async -> ()' risks causing data races}}
410
+
// expected-ni-ns-note @-4 {{sending 'self'-isolated value of non-Sendable type '@concurrent () async -> ()' to main actor-isolated global function 'normalGlobalActorAcceptsAsyncClosure' risks causing races in between 'self'-isolated and main actor-isolated uses}}
402
411
403
412
// CHECK-LABEL: // closure #2 in MyActor.test_CallerSyncNormal_CalleeAsyncMainActorIsolated()
404
413
// CHECK-NEXT: // Isolation: nonisolated
@@ -513,8 +522,11 @@ extension MyActor {
513
522
514
523
// CHECK-LABEL: // closure #1 in MyActor.test_CallerAsyncNormal_CalleeAsyncMainActorIsolated()
awaitasyncNormalGlobalActorAcceptsAsyncClosure{print(self)} // expected-error {{sending value of non-Sendable type '() async -> ()' risks causing data races}}
517
-
// expected-note @-1 {{sending 'self'-isolated value of non-Sendable type '() async -> ()' to main actor-isolated global function 'asyncNormalGlobalActorAcceptsAsyncClosure' risks causing races in between 'self'-isolated and main actor-isolated uses}}
// expected-ni-error @-1 {{sending value of non-Sendable type '() async -> ()' risks causing data races}}
527
+
// expected-ni-note @-2 {{sending 'self'-isolated value of non-Sendable type '() async -> ()' to main actor-isolated global function 'asyncNormalGlobalActorAcceptsAsyncClosure' risks causing races in between 'self'-isolated and main actor-isolated uses}}
528
+
// expected-ni-ns-error @-3 {{sending value of non-Sendable type '@concurrent () async -> ()' risks causing data races}}
529
+
// expected-ni-ns-note @-4 {{sending 'self'-isolated value of non-Sendable type '@concurrent () async -> ()' to main actor-isolated global function 'asyncNormalGlobalActorAcceptsAsyncClosure' risks causing races in between 'self'-isolated and main actor-isolated uses}}
518
530
519
531
// CHECK-LABEL: // closure #2 in MyActor.test_CallerAsyncNormal_CalleeAsyncMainActorIsolated()
Task.detached{ _ = x1 } // expected-warning {{sending value of non-Sendable type '() async -> ()' risks causing data races}}
1013
-
// expected-note @-1 {{Passing value of non-Sendable type '() async -> ()' as a 'sending' argument to static method 'detached(name:priority:operation:)' risks causing races in between local and caller code}}
1012
+
Task.detached{ _ = x1 }
1013
+
// expected-ni-warning @-1 {{sending value of non-Sendable type '() async -> ()' risks causing data races}}
1014
+
// expected-ni-note @-2 {{Passing value of non-Sendable type '() async -> ()' as a 'sending' argument to static method 'detached(name:priority:operation:)' risks causing races in between local and caller code}}
1015
+
// expected-ni-ns-warning @-3 {{sending value of non-Sendable type '@concurrent () async -> ()' risks causing data races}}
1016
+
// expected-ni-ns-note @-4 {{Passing value of non-Sendable type '@concurrent () async -> ()' as a 'sending' argument to static method 'detached(name:priority:operation:)' risks causing races in between local and caller code}}
Task.detached{ _ = x4a; _ = x4b } // expected-warning {{sending value of non-Sendable type '() async -> ()' risks causing data races}}
1028
-
// expected-note @-1 {{Passing value of non-Sendable type '() async -> ()' as a 'sending' argument to static method 'detached(name:priority:operation:)' risks causing races in between local and caller code}}
1031
+
Task.detached{ _ = x4a; _ = x4b }
1032
+
// expected-ni-warning @-1 {{sending value of non-Sendable type '() async -> ()' risks causing data races}}
1033
+
// expected-ni-note @-2 {{Passing value of non-Sendable type '() async -> ()' as a 'sending' argument to static method 'detached(name:priority:operation:)' risks causing races in between local and caller code}}
1034
+
// expected-ni-ns-warning @-3 {{sending value of non-Sendable type '@concurrent () async -> ()' risks causing data races}}
1035
+
// expected-ni-ns-note @-4 {{Passing value of non-Sendable type '@concurrent () async -> ()' as a 'sending' argument to static method 'detached(name:priority:operation:)' risks causing races in between local and caller code}}
0 commit comments