Skip to content

[region-isolation] Tweak the main transferring diagnostic. #72895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/swift/AST/DiagnosticsSIL.def
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ NOTE(regionbasedisolation_isolated_since_in_same_region_basename, none,
//

ERROR(regionbasedisolation_named_transfer_yields_race, none,
"transferring %0 may cause a race",
"transferring %0 may cause a data race",
(Identifier))

NOTE(regionbasedisolation_named_info_transfer_yields_race, none,
Expand Down
6 changes: 3 additions & 3 deletions test/ClangImporter/transferring_objc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func methodTestTransferringResult() async {
func methodTestTransferringArg() async {
let x = MyType()
let s = NSObject()
let _ = x.getResultWithTransferringArgument(s) // expected-error {{transferring 's' may cause a race}}
let _ = x.getResultWithTransferringArgument(s) // expected-error {{transferring 's' may cause a data race}}
// expected-note @-1 {{'s' used after being passed as a transferring parameter; Later uses could race}}
useValue(s) // expected-note {{use here could race}}
}
Expand All @@ -45,14 +45,14 @@ func funcTestTransferringResult() async {
// Just to show that without the transferring param, we generate diagnostics.
let x2 = NSObject()
let y2 = returnNSObjectFromGlobalFunction(x2)
await transferToMain(x2) // expected-error {{transferring 'x2' may cause a race}}
await transferToMain(x2) // expected-error {{transferring 'x2' may cause a data race}}
// expected-note @-1 {{transferring disconnected 'x2' to main actor-isolated callee could cause races in between callee main actor-isolated and local nonisolated uses}}
useValue(y2) // expected-note {{use here could race}}
}

func funcTestTransferringArg() async {
let x = NSObject()
transferNSObjectToGlobalFunction(x) // expected-error {{transferring 'x' may cause a race}}
transferNSObjectToGlobalFunction(x) // expected-error {{transferring 'x' may cause a data race}}
// expected-note @-1 {{'x' used after being passed as a transferring parameter; Later uses could race}}
useValue(x) // expected-note {{use here could race}}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ actor Test {
_ body: (consuming NonSendableValue, isolated (any Actor)?) -> Void) async {
Self.$local.withValue(12) {
// Unexpected errors here:
// error: unexpected warning produced: transferring 'body' may cause a race; this is an error in the Swift 6 language mode
// error: unexpected warning produced: transferring 'body' may cause a data race; this is an error in the Swift 6 language mode
// error: unexpected note produced: actor-isolated 'body' is captured by a actor-isolated closure. actor-isolated uses in closure may race against later nonisolated uses
body(NonSendableValue(), isolation)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func iterate(stream: AsyncStream<Int>) async {
// FIXME: Region isolation should consider a value from a 'nonisolated(unsafe)'
// declaration to be in a disconnected region

// expected-region-isolation-warning @+3 {{transferring 'it' may cause a race}}
// expected-region-isolation-warning @+3 {{transferring 'it' may cause a data race}}
// expected-region-isolation-note @+2 {{transferring disconnected 'it' to nonisolated callee could cause races in between callee nonisolated and local main actor-isolated uses}}
// expected-region-isolation-note @+1 {{use here could race}}
while let element = await it.next() {
Expand Down
6 changes: 3 additions & 3 deletions test/Concurrency/isolated_captures.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class NotSendable {
MyActor.ns = ns

await { @YourActor in
// expected-region-isolation-warning @+3 {{transferring 'ns' may cause a race}}
// expected-region-isolation-warning @+3 {{transferring 'ns' may cause a data race}}
// expected-region-isolation-note @+2 {{global actor 'MyActor'-isolated 'ns' is captured by a global actor 'YourActor'-isolated closure. global actor 'YourActor'-isolated uses in closure may race against later global actor 'MyActor'-isolated uses}}
// expected-complete-warning@+1 {{capture of 'ns' with non-sendable type 'NotSendable' in an isolated closure; this is an error in the Swift 6 language mode}}
YourActor.ns = ns
Expand All @@ -62,7 +62,7 @@ class NotSendable {
ns.stash()

await { @YourActor in
// expected-region-isolation-warning @+3 {{transferring 'ns' may cause a race}}
// expected-region-isolation-warning @+3 {{transferring 'ns' may cause a data race}}
// expected-region-isolation-note @+2 {{global actor 'MyActor'-isolated 'ns' is captured by a global actor 'YourActor'-isolated closure. global actor 'YourActor'-isolated uses in closure may race against later global actor 'MyActor'-isolated uses}}
// expected-complete-warning@+1 {{capture of 'ns' with non-sendable type 'NotSendable' in an isolated closure; this is an error in the Swift 6 language mode}}
YourActor.ns = ns
Expand All @@ -83,7 +83,7 @@ class NotSendable {
let ns = NotSendable()

await { @YourActor in
// expected-region-isolation-warning @+3 {{transferring 'ns' may cause a race}}
// expected-region-isolation-warning @+3 {{transferring 'ns' may cause a data race}}
// expected-region-isolation-note @+2 {{global actor 'MyActor'-isolated 'ns' is captured by a global actor 'YourActor'-isolated closure. global actor 'YourActor'-isolated uses in closure may race against later global actor 'MyActor'-isolated uses}}
// expected-complete-warning@+1 {{capture of 'ns' with non-sendable type 'NotSendable' in an isolated closure; this is an error in the Swift 6 language mode}}
YourActor.ns = ns
Expand Down
12 changes: 6 additions & 6 deletions test/Concurrency/sendable_checking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public actor MyActor: MyProto {

func g(ns1: NS1) async {
await nonisolatedAsyncFunc1(ns1) // expected-targeted-and-complete-warning{{passing argument of non-sendable type 'NS1' outside of actor-isolated context may introduce data races}}
// expected-tns-warning @-1 {{transferring 'ns1' may cause a race}}
// expected-tns-warning @-1 {{transferring 'ns1' may cause a data race}}
// expected-tns-note @-2 {{transferring actor-isolated 'ns1' to nonisolated callee could cause races between nonisolated and actor-isolated uses}}
_ = await nonisolatedAsyncFunc2() // expected-warning{{non-sendable type 'NS1' returned by implicitly asynchronous call to nonisolated function cannot cross actor boundary}}
}
Expand Down Expand Up @@ -253,12 +253,12 @@ final class NonSendable {
func call() async {
await update()
// expected-targeted-and-complete-warning @-1 {{passing argument of non-sendable type 'NonSendable' into main actor-isolated context may introduce data races}}
// expected-tns-warning @-2 {{transferring 'self' may cause a race}}
// expected-tns-warning @-2 {{transferring 'self' may cause a data race}}
// expected-tns-note @-3 {{transferring task-isolated 'self' to main actor-isolated callee could cause races between main actor-isolated and task-isolated uses}}

await self.update()
// expected-targeted-and-complete-warning @-1 {{passing argument of non-sendable type 'NonSendable' into main actor-isolated context may introduce data races}}
// expected-tns-warning @-2 {{transferring 'self' may cause a race}}
// expected-tns-warning @-2 {{transferring 'self' may cause a data race}}
// expected-tns-note @-3 {{transferring task-isolated 'self' to main actor-isolated callee could cause races between main actor-isolated and task-isolated uses}}

_ = await x
Expand All @@ -277,7 +277,7 @@ func testNonSendableBaseArg() async {
let t = NonSendable()
await t.update()
// expected-targeted-and-complete-warning @-1 {{passing argument of non-sendable type 'NonSendable' into main actor-isolated context may introduce data races}}
// expected-tns-warning @-2 {{transferring 't' may cause a race}}
// expected-tns-warning @-2 {{transferring 't' may cause a data race}}
// expected-tns-note @-3 {{transferring disconnected 't' to main actor-isolated callee could cause races in between callee main actor-isolated and local nonisolated uses}}

_ = await t.x
Expand All @@ -297,13 +297,13 @@ func callNonisolatedAsyncClosure(
) async {
await g(ns)
// expected-targeted-and-complete-warning @-1 {{passing argument of non-sendable type 'NonSendable' outside of main actor-isolated context may introduce data races}}
// expected-tns-warning @-2 {{transferring 'ns' may cause a race}}
// expected-tns-warning @-2 {{transferring 'ns' may cause a data race}}
// expected-tns-note @-3 {{transferring main actor-isolated 'ns' to nonisolated callee could cause races between nonisolated and main actor-isolated uses}}

let f: (NonSendable) async -> () = globalSendable // okay
await f(ns)
// expected-targeted-and-complete-warning@-1 {{passing argument of non-sendable type 'NonSendable' outside of main actor-isolated context may introduce data races}}
// expected-tns-warning @-2 {{transferring 'ns' may cause a race}}
// expected-tns-warning @-2 {{transferring 'ns' may cause a data race}}
// expected-tns-note @-3 {{transferring main actor-isolated 'ns' to nonisolated callee could cause races between nonisolated and main actor-isolated uses}}
}

Expand Down
12 changes: 6 additions & 6 deletions test/Concurrency/transfernonsendable.sil
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ bb0(%0 : @guaranteed $NonSendableStruct):
debug_value %0 : $NonSendableStruct, var, name "myname"
%2 = struct_extract %0 : $NonSendableStruct, #NonSendableStruct.ns
%3 = copy_value %2 : $NonSendableKlass
return %3 : $NonSendableKlass // expected-warning {{transferring 'myname.ns' may cause a race}}
return %3 : $NonSendableKlass // expected-warning {{transferring 'myname.ns' may cause a data race}}
// expected-note @-1 {{task-isolated 'myname.ns' cannot be a transferring result. task-isolated uses may race with caller uses}}
}

Expand All @@ -235,7 +235,7 @@ bb0(%0 : @guaranteed $MainActorIsolatedStruct):
debug_value %0 : $MainActorIsolatedStruct, var, name "myname"
%2 = struct_extract %0 : $MainActorIsolatedStruct, #MainActorIsolatedStruct.ns
%3 = copy_value %2 : $NonSendableKlass
return %3 : $NonSendableKlass // expected-warning {{transferring 'myname.ns' may cause a race}}
return %3 : $NonSendableKlass // expected-warning {{transferring 'myname.ns' may cause a data race}}
// expected-note @-1 {{main actor-isolated 'myname.ns' cannot be a transferring result. main actor-isolated uses may race with caller uses}}
}

Expand All @@ -244,7 +244,7 @@ bb0(%0 : $*MainActorIsolatedStruct):
debug_value %0 : $*MainActorIsolatedStruct, var, name "myname"
%2 = struct_element_addr %0 : $*MainActorIsolatedStruct, #MainActorIsolatedStruct.ns
%3 = load [copy] %2 : $*NonSendableKlass
return %3 : $NonSendableKlass // expected-warning {{transferring 'myname.ns' may cause a race}}
return %3 : $NonSendableKlass // expected-warning {{transferring 'myname.ns' may cause a data race}}
// expected-note @-1 {{main actor-isolated 'myname.ns' cannot be a transferring result. main actor-isolated uses may race with caller uses}}
}

Expand All @@ -253,7 +253,7 @@ bb0(%0 : @guaranteed $MainActorIsolatedEnum):
debug_value %0 : $MainActorIsolatedEnum, var, name "myname"
%2 = unchecked_enum_data %0 : $MainActorIsolatedEnum, #MainActorIsolatedEnum.second!enumelt
%3 = copy_value %2 : $NonSendableKlass
return %3 : $NonSendableKlass // expected-warning {{transferring 'myname.second' may cause a race}}
return %3 : $NonSendableKlass // expected-warning {{transferring 'myname.second' may cause a data race}}
// expected-note @-1 {{main actor-isolated 'myname.second' cannot be a transferring result. main actor-isolated uses may race with caller uses}}
}

Expand All @@ -262,7 +262,7 @@ bb0(%0 : $*MainActorIsolatedEnum):
debug_value %0 : $*MainActorIsolatedEnum, var, name "myname"
%2 = unchecked_take_enum_data_addr %0 : $*MainActorIsolatedEnum, #MainActorIsolatedEnum.second!enumelt
%3 = load [take] %2 : $*NonSendableKlass
return %3 : $NonSendableKlass // expected-warning {{transferring 'myname.second' may cause a race}}
return %3 : $NonSendableKlass // expected-warning {{transferring 'myname.second' may cause a data race}}
// expected-note @-1 {{main actor-isolated 'myname.second' cannot be a transferring result. main actor-isolated uses may race with caller uses}}
}

Expand All @@ -281,7 +281,7 @@ bb2(%1 : @guaranteed $NonSendableKlass):
br bb3(%3 : $FakeOptional<NonSendableKlass>)

bb3(%4 : @owned $FakeOptional<NonSendableKlass>):
return %4 : $FakeOptional<NonSendableKlass> // expected-warning {{transferring 'myname.some' may cause a race}}
return %4 : $FakeOptional<NonSendableKlass> // expected-warning {{transferring 'myname.some' may cause a data race}}
// expected-note @-1 {{main actor-isolated 'myname.some' cannot be a transferring result. main actor-isolated uses may race with caller uses}}
}

Expand Down
Loading