Skip to content

Commit a56d0f5

Browse files
committed
[region-isolation] Tweak the main transferring diagnostic.
Specifically, I am transforming it from "may cause a race" -> "may cause a data race". Adding data is a small thing, but it adds a bunch of nice clarity.
1 parent 415715e commit a56d0f5

19 files changed

+260
-260
lines changed

include/swift/AST/DiagnosticsSIL.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ NOTE(regionbasedisolation_isolated_since_in_same_region_basename, none,
973973
//
974974

975975
ERROR(regionbasedisolation_named_transfer_yields_race, none,
976-
"transferring %0 may cause a race",
976+
"transferring %0 may cause a data race",
977977
(Identifier))
978978

979979
NOTE(regionbasedisolation_named_info_transfer_yields_race, none,

test/ClangImporter/transferring_objc.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func methodTestTransferringResult() async {
2525
func methodTestTransferringArg() async {
2626
let x = MyType()
2727
let s = NSObject()
28-
let _ = x.getResultWithTransferringArgument(s) // expected-error {{transferring 's' may cause a race}}
28+
let _ = x.getResultWithTransferringArgument(s) // expected-error {{transferring 's' may cause a data race}}
2929
// expected-note @-1 {{'s' used after being passed as a transferring parameter; Later uses could race}}
3030
useValue(s) // expected-note {{use here could race}}
3131
}
@@ -45,14 +45,14 @@ func funcTestTransferringResult() async {
4545
// Just to show that without the transferring param, we generate diagnostics.
4646
let x2 = NSObject()
4747
let y2 = returnNSObjectFromGlobalFunction(x2)
48-
await transferToMain(x2) // expected-error {{transferring 'x2' may cause a race}}
48+
await transferToMain(x2) // expected-error {{transferring 'x2' may cause a data race}}
4949
// expected-note @-1 {{transferring disconnected 'x2' to main actor-isolated callee could cause races in between callee main actor-isolated and local nonisolated uses}}
5050
useValue(y2) // expected-note {{use here could race}}
5151
}
5252

5353
func funcTestTransferringArg() async {
5454
let x = NSObject()
55-
transferNSObjectToGlobalFunction(x) // expected-error {{transferring 'x' may cause a race}}
55+
transferNSObjectToGlobalFunction(x) // expected-error {{transferring 'x' may cause a data race}}
5656
// expected-note @-1 {{'x' used after being passed as a transferring parameter; Later uses could race}}
5757
useValue(x) // expected-note {{use here could race}}
5858
}

test/Concurrency/async_task_locals_basic_warnings_bug_isolation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ actor Test {
1818
_ body: (consuming NonSendableValue, isolated (any Actor)?) -> Void) async {
1919
Self.$local.withValue(12) {
2020
// Unexpected errors here:
21-
// error: unexpected warning produced: transferring 'body' may cause a race; this is an error in the Swift 6 language mode
21+
// error: unexpected warning produced: transferring 'body' may cause a data race; this is an error in the Swift 6 language mode
2222
// 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
2323
body(NonSendableValue(), isolation)
2424
}

test/Concurrency/experimental_feature_strictconcurrency.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func iterate(stream: AsyncStream<Int>) async {
3131
// FIXME: Region isolation should consider a value from a 'nonisolated(unsafe)'
3232
// declaration to be in a disconnected region
3333

34-
// expected-region-isolation-warning @+3 {{transferring 'it' may cause a race}}
34+
// expected-region-isolation-warning @+3 {{transferring 'it' may cause a data race}}
3535
// expected-region-isolation-note @+2 {{transferring disconnected 'it' to nonisolated callee could cause races in between callee nonisolated and local main actor-isolated uses}}
3636
// expected-region-isolation-note @+1 {{use here could race}}
3737
while let element = await it.next() {

test/Concurrency/isolated_captures.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class NotSendable {
4040
MyActor.ns = ns
4141

4242
await { @YourActor in
43-
// expected-region-isolation-warning @+3 {{transferring 'ns' may cause a race}}
43+
// expected-region-isolation-warning @+3 {{transferring 'ns' may cause a data race}}
4444
// 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}}
4545
// 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}}
4646
YourActor.ns = ns
@@ -62,7 +62,7 @@ class NotSendable {
6262
ns.stash()
6363

6464
await { @YourActor in
65-
// expected-region-isolation-warning @+3 {{transferring 'ns' may cause a race}}
65+
// expected-region-isolation-warning @+3 {{transferring 'ns' may cause a data race}}
6666
// 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}}
6767
// 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}}
6868
YourActor.ns = ns
@@ -83,7 +83,7 @@ class NotSendable {
8383
let ns = NotSendable()
8484

8585
await { @YourActor in
86-
// expected-region-isolation-warning @+3 {{transferring 'ns' may cause a race}}
86+
// expected-region-isolation-warning @+3 {{transferring 'ns' may cause a data race}}
8787
// 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}}
8888
// 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}}
8989
YourActor.ns = ns

test/Concurrency/sendable_checking.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public actor MyActor: MyProto {
9696

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

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

264264
_ = await x
@@ -277,7 +277,7 @@ func testNonSendableBaseArg() async {
277277
let t = NonSendable()
278278
await t.update()
279279
// expected-targeted-and-complete-warning @-1 {{passing argument of non-sendable type 'NonSendable' into main actor-isolated context may introduce data races}}
280-
// expected-tns-warning @-2 {{transferring 't' may cause a race}}
280+
// expected-tns-warning @-2 {{transferring 't' may cause a data race}}
281281
// 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}}
282282

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

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

test/Concurrency/transfernonsendable.sil

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ bb0(%0 : @guaranteed $NonSendableStruct):
226226
debug_value %0 : $NonSendableStruct, var, name "myname"
227227
%2 = struct_extract %0 : $NonSendableStruct, #NonSendableStruct.ns
228228
%3 = copy_value %2 : $NonSendableKlass
229-
return %3 : $NonSendableKlass // expected-warning {{transferring 'myname.ns' may cause a race}}
229+
return %3 : $NonSendableKlass // expected-warning {{transferring 'myname.ns' may cause a data race}}
230230
// expected-note @-1 {{task-isolated 'myname.ns' cannot be a transferring result. task-isolated uses may race with caller uses}}
231231
}
232232

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

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

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

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

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

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

0 commit comments

Comments
 (0)