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
[region-isolation] Improve the error we emit for closure literals captured as a sending parameter.
Specifically:
I changed the main error message to focus on the closure and that the closure
is being accessed concurrently.
If we find that we captured a value that is the actual isolation source, we
emit that the capture is actually actor isolated.
If the captured value is in the same region as the isolated value but is not
isolated, we instead say that the value is accessible from *-isolated code or
code within the current task.
If we find multiple captures and we do not which is the actual value that was
in the same region before we formed the partial apply, we just emit a note on
the captures saying that the closure captures the value.
I changed the diagnostics from using the phrase "task-isolated" to use some
variant of accessible to code in the current task.
The idea is that in all situations we provide a breadcrumb that the user can
start investigating rather than just saying that the closure is "task-isolated".
From a preconcurrency perspective, I made it so that we apply the preconcurrency
behavior of all of the captures. This means that if one of the captures is
preconcurrency, we apply the preconcurrency restriction to the closure. This is
one step towards making it so that preconcurrency applies at the region level...
we just are not completely there yet.
rdar://133798044
Copy file name to clipboardExpand all lines: test/Concurrency/concurrent_value_checking.swift
+8-12Lines changed: 8 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -413,24 +413,20 @@ extension NotConcurrent {
413
413
func f(){}
414
414
415
415
func test(){
416
-
Task{ // expected-tns-warning {{sending value of non-Sendable type '() async -> ()' risks causing data races}}
417
-
// expected-tns-note @-1 {{Passing task-isolated value of non-Sendable type '() async -> ()' as a 'sending' parameter risks causing races inbetween task-isolated uses and uses reachable from the callee}}
418
-
f()
416
+
Task{ // expected-tns-warning {{passing closure as a 'sending' parameter risks causing data races between code in the current task and concurrent execution of the closure}}
417
+
f() // expected-tns-note {{closure captures 'self' which is accessible to code in the current task}}
419
418
}
420
419
421
-
Task{ // expected-tns-warning {{sending value of non-Sendable type '() async -> ()' risks causing data races}}
422
-
// expected-tns-note @-1 {{Passing task-isolated value of non-Sendable type '() async -> ()' as a 'sending' parameter risks causing races inbetween task-isolated uses and uses reachable from the callee}}
423
-
self.f()
420
+
Task{ // expected-tns-warning {{passing closure as a 'sending' parameter risks causing data races between code in the current task and concurrent execution of the closure}}
421
+
self.f() // expected-tns-note {{closure captures 'self' which is accessible to code in the current task}}
424
422
}
425
423
426
-
Task{[self]in // expected-tns-warning {{sending value of non-Sendable type '() async -> ()' risks causing data races}}
427
-
// expected-tns-note @-1 {{Passing task-isolated value of non-Sendable type '() async -> ()' as a 'sending' parameter risks causing races inbetween task-isolated uses and uses reachable from the callee}}
428
-
f()
424
+
Task{[self]in // expected-tns-warning {{passing closure as a 'sending' parameter risks causing data races between code in the current task and concurrent execution of the closure}}
425
+
f() // expected-tns-note {{closure captures 'self' which is accessible to code in the current task}}
429
426
}
430
427
431
-
Task{[self]in // expected-tns-warning {{sending value of non-Sendable type '() async -> ()' risks causing data races}}
432
-
// expected-tns-note @-1 {{Passing task-isolated value of non-Sendable type '() async -> ()' as a 'sending' parameter risks causing races inbetween task-isolated uses and uses reachable from the callee}}
433
-
self.f()
428
+
Task{[self]in // expected-tns-warning {{passing closure as a 'sending' parameter risks causing data races between code in the current task and concurrent execution of the closure}}
429
+
self.f() // expected-tns-note {{closure captures 'self' which is accessible to code in the current task}}
// FIXME: The `a` in the capture list and `isolated a` are the same,
503
503
// but the actor isolation checker doesn't know that.
504
-
Task{[a]in // expected-tns-warning {{sending value of non-Sendable type '() async -> ()' risks causing data races}}
505
-
// expected-tns-note @-1 {{Passing 'a'-isolated value of non-Sendable type '() async -> ()' as a 'sending' parameter risks causing races inbetween 'a'-isolated uses and uses reachable from the callee}}
504
+
Task{[a]in // expected-tns-warning {{passing closure as a 'sending' parameter risks causing data races between 'a'-isolated code and concurrent execution of the closure}}
0 commit comments