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
(cherry picked from commit 4bb2e4f)
Conflicts:
include/swift/AST/DiagnosticsSIL.def
lib/SILOptimizer/Mandatory/TransferNonSendable.cpp
test/Concurrency/concurrent_value_checking.swift
test/Concurrency/isolated_parameters.swift
test/Concurrency/sendable_preconcurrency.swift
test/Concurrency/sendable_without_preconcurrency.swift
test/Concurrency/sendable_without_preconcurrency_2.swift
test/Concurrency/transfernonsendable.swift
test/Concurrency/transfernonsendable_global_actor_sending.swift
Copy file name to clipboardExpand all lines: test/Concurrency/concurrent_value_checking.swift
+8-8Lines changed: 8 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -413,20 +413,20 @@ extension NotConcurrent {
413
413
func f(){}
414
414
415
415
func test(){
416
-
Task{ // expected-tns-warning {{task-isolated value of type '() async -> ()' passed as a strongly transferred parameter}}
417
-
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}}
418
418
}
419
419
420
-
Task{ // expected-tns-warning {{task-isolated value of type '() async -> ()' passed as a strongly transferred parameter}}
421
-
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}}
422
422
}
423
423
424
-
Task{[self]in // expected-tns-warning {{task-isolated value of type '() async -> ()' passed as a strongly transferred parameter}}
425
-
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}}
426
426
}
427
427
428
-
Task{[self]in // expected-tns-warning {{task-isolated value of type '() async -> ()' passed as a strongly transferred parameter}}
429
-
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 {{'a'-isolated value of type '() async -> ()' passed as a strongly transferred parameter}}
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