Skip to content

Commit

Permalink
[sending] Change transferring diagnostics to say sending instead of t…
Browse files Browse the repository at this point in the history
…ransferring.

Just trying to slice off a larger change where I change these tests to actually
use 'sending'. This is nice to do now since it is algebraic to do.

rdar://128216574
  • Loading branch information
gottesmm committed May 17, 2024
1 parent e3e78ad commit 71e95b9
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 49 deletions.
10 changes: 5 additions & 5 deletions include/swift/AST/DiagnosticsSIL.def
Original file line number Diff line number Diff line change
Expand Up @@ -995,14 +995,14 @@ NOTE(regionbasedisolation_named_transfer_non_transferrable, none,
NOTE(regionbasedisolation_named_transfer_non_transferrable_callee, none,
"sending %1%0 to %2 %3 %4 risks causing data races between %2 and %5 uses",
(Identifier, StringRef, ActorIsolation, DescriptiveDeclKind, DeclName, StringRef))
NOTE(regionbasedisolation_named_transfer_into_transferring_param, none,
"%0%1 is passed as a transferring parameter; Uses in callee may race with later %0uses",
NOTE(regionbasedisolation_named_transfer_into_sending_param, none,
"%0%1 is passed as a 'sending' parameter; Uses in callee may race with later %0uses",
(StringRef, Identifier))
NOTE(regionbasedisolation_named_notransfer_transfer_into_result, none,
"%0%1 cannot be a transferring result. %2 uses may race with caller uses",
"%0%1 cannot be a 'sending' result. %2 uses may race with caller uses",
(StringRef, Identifier, StringRef))
NOTE(regionbasedisolation_named_stronglytransferred_binding, none,
"%0 used after being passed as a transferring parameter; Later uses could race",
NOTE(regionbasedisolation_named_value_used_after_explicit_sending, none,
"%0 used after being passed as a 'sending' parameter; Later uses could race",
(Identifier))
NOTE(regionbasedisolation_named_isolated_closure_yields_race, none,
"%0%1 is captured by a %2 closure. %2 uses in closure may race against later %3 uses",
Expand Down
6 changes: 3 additions & 3 deletions lib/SILOptimizer/Mandatory/TransferNonSendable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,8 @@ class UseAfterTransferDiagnosticEmitter {

// Then emit the note with greater context.
diagnoseNote(
loc, diag::regionbasedisolation_named_stronglytransferred_binding, name)
loc, diag::regionbasedisolation_named_value_used_after_explicit_sending,
name)
.highlight(loc.getSourceRange());

// Finally the require points.
Expand Down Expand Up @@ -1231,8 +1232,7 @@ class TransferNonTransferrableDiagnosticEmitter {
os << ' ';
}
}
auto diag =
diag::regionbasedisolation_named_transfer_into_transferring_param;
auto diag = diag::regionbasedisolation_named_transfer_into_sending_param;
diagnoseNote(loc, diag, descriptiveKindStr, varName);
}

Expand Down
2 changes: 1 addition & 1 deletion test/ClangImporter/transferring.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ func funcTestTransferringResult() async {
func funcTestTransferringArg() async {
let x = NonSendableCStruct()
transferUserDefinedIntoGlobalFunction(x) // expected-error {{sending 'x' risks causing data races}}
// expected-note @-1 {{'x' used after being passed as a transferring parameter}}
// expected-note @-1 {{'x' used after being passed as a 'sending' parameter}}
useValue(x) // expected-note {{access can happen concurrently}}
}
4 changes: 2 additions & 2 deletions test/ClangImporter/transferring_objc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func methodTestTransferringArg() async {
let x = MyType()
let s = NSObject()
let _ = x.getResultWithTransferringArgument(s) // expected-error {{sending 's' risks causing data races}}
// expected-note @-1 {{'s' used after being passed as a transferring parameter; Later uses could race}}
// expected-note @-1 {{'s' used after being passed as a 'sending' parameter; Later uses could race}}
useValue(s) // expected-note {{access can happen concurrently}}
}

Expand All @@ -53,6 +53,6 @@ func funcTestTransferringResult() async {
func funcTestTransferringArg() async {
let x = NSObject()
transferNSObjectToGlobalFunction(x) // expected-error {{sending 'x' risks causing data races}}
// expected-note @-1 {{'x' used after being passed as a transferring parameter; Later uses could race}}
// expected-note @-1 {{'x' used after being passed as a 'sending' parameter; Later uses could race}}
useValue(x) // expected-note {{access can happen concurrently}}
}
12 changes: 6 additions & 6 deletions test/Concurrency/transfernonsendable.sil
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ bb0(%0 : @guaranteed $NonSendableStruct):
%2 = struct_extract %0 : $NonSendableStruct, #NonSendableStruct.ns
%3 = copy_value %2 : $NonSendableKlass
return %3 : $NonSendableKlass // expected-warning {{sending 'myname.ns' risks causing data races}}
// expected-note @-1 {{task-isolated 'myname.ns' cannot be a transferring result. task-isolated uses may race with caller uses}}
// expected-note @-1 {{task-isolated 'myname.ns' cannot be a 'sending' result. task-isolated uses may race with caller uses}}
}

sil [ossa] @synchronous_returns_transferring_globalactor_struct_structextract : $@convention(method) (@guaranteed MainActorIsolatedStruct) -> @sil_sending @owned NonSendableKlass {
Expand All @@ -236,7 +236,7 @@ bb0(%0 : @guaranteed $MainActorIsolatedStruct):
%2 = struct_extract %0 : $MainActorIsolatedStruct, #MainActorIsolatedStruct.ns
%3 = copy_value %2 : $NonSendableKlass
return %3 : $NonSendableKlass // expected-warning {{sending 'myname.ns' risks causing data races}}
// expected-note @-1 {{main actor-isolated 'myname.ns' cannot be a transferring result. main actor-isolated uses may race with caller uses}}
// expected-note @-1 {{main actor-isolated 'myname.ns' cannot be a 'sending' result. main actor-isolated uses may race with caller uses}}
}

sil [ossa] @synchronous_returns_transferring_globalactor_struct_structelementaddr : $@convention(method) (@in_guaranteed MainActorIsolatedStruct) -> @sil_sending @owned NonSendableKlass {
Expand All @@ -245,7 +245,7 @@ bb0(%0 : $*MainActorIsolatedStruct):
%2 = struct_element_addr %0 : $*MainActorIsolatedStruct, #MainActorIsolatedStruct.ns
%3 = load [copy] %2 : $*NonSendableKlass
return %3 : $NonSendableKlass // expected-warning {{sending 'myname.ns' risks causing data races}}
// expected-note @-1 {{main actor-isolated 'myname.ns' cannot be a transferring result. main actor-isolated uses may race with caller uses}}
// expected-note @-1 {{main actor-isolated 'myname.ns' cannot be a 'sending' result. main actor-isolated uses may race with caller uses}}
}

sil [ossa] @synchronous_returns_transferring_globalactor_enum_uncheckedenumdata : $@convention(method) (@guaranteed MainActorIsolatedEnum) -> @sil_sending @owned NonSendableKlass {
Expand All @@ -254,7 +254,7 @@ bb0(%0 : @guaranteed $MainActorIsolatedEnum):
%2 = unchecked_enum_data %0 : $MainActorIsolatedEnum, #MainActorIsolatedEnum.second!enumelt
%3 = copy_value %2 : $NonSendableKlass
return %3 : $NonSendableKlass // expected-warning {{sending 'myname.second' risks causing data races}}
// expected-note @-1 {{main actor-isolated 'myname.second' cannot be a transferring result. main actor-isolated uses may race with caller uses}}
// expected-note @-1 {{main actor-isolated 'myname.second' cannot be a 'sending' result. main actor-isolated uses may race with caller uses}}
}

sil [ossa] @synchronous_returns_transferring_globalactor_enum_uncheckedtakeenumdataaddr : $@convention(method) (@in MainActorIsolatedEnum) -> @sil_sending @owned NonSendableKlass {
Expand All @@ -263,7 +263,7 @@ bb0(%0 : $*MainActorIsolatedEnum):
%2 = unchecked_take_enum_data_addr %0 : $*MainActorIsolatedEnum, #MainActorIsolatedEnum.second!enumelt
%3 = load [take] %2 : $*NonSendableKlass
return %3 : $NonSendableKlass // expected-warning {{sending 'myname.second' risks causing data races}}
// expected-note @-1 {{main actor-isolated 'myname.second' cannot be a transferring result. main actor-isolated uses may race with caller uses}}
// expected-note @-1 {{main actor-isolated 'myname.second' cannot be a 'sending' result. main actor-isolated uses may race with caller uses}}
}

sil [ossa] @synchronous_returns_transferring_globalactor_enum_switchenum : $@convention(method) (@guaranteed MainActorIsolatedEnum) -> @sil_sending @owned FakeOptional<NonSendableKlass> {
Expand All @@ -282,7 +282,7 @@ bb2(%1 : @guaranteed $NonSendableKlass):

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

sil [ossa] @warningIfCallingGetter : $@convention(method) @async (@sil_isolated @guaranteed MyActor) -> () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ extension NonSendableGlobalActorIsolatedStruct {
mutating func test3() -> transferring NonSendableKlass {
self.k
} // expected-error {{sending 'self.k' risks causing data races}}
// expected-note @-1 {{main actor-isolated 'self.k' cannot be a transferring result. main actor-isolated uses may race with caller uses}}
// expected-note @-1 {{main actor-isolated 'self.k' cannot be a 'sending' result. main actor-isolated uses may race with caller uses}}

mutating func test4() -> (any GlobalActorIsolatedProtocol)? {
self.p
Expand Down Expand Up @@ -167,7 +167,7 @@ extension NonSendableGlobalActorIsolatedEnum {
}
return x
} // expected-error {{sending 'x.some' risks causing data races}}
// expected-note @-1 {{main actor-isolated 'x.some' cannot be a transferring result. main actor-isolated uses may race with caller uses}}
// expected-note @-1 {{main actor-isolated 'x.some' cannot be a 'sending' result. main actor-isolated uses may race with caller uses}}
}

extension NonSendableGlobalActorIsolatedKlass {
Expand All @@ -182,7 +182,7 @@ extension NonSendableGlobalActorIsolatedKlass {
func test3() -> transferring NonSendableKlass {
self.k
} // expected-error {{sending 'self.k' risks causing data races}}
// expected-note @-1 {{main actor-isolated 'self.k' cannot be a transferring result. main actor-isolated uses may race with caller uses}}
// expected-note @-1 {{main actor-isolated 'self.k' cannot be a 'sending' result. main actor-isolated uses may race with caller uses}}

func test4() -> (any GlobalActorIsolatedProtocol)? {
self.p
Expand Down Expand Up @@ -215,7 +215,7 @@ extension FinalNonSendableGlobalActorIsolatedKlass {
func test3() -> transferring NonSendableKlass {
self.k
} // expected-error {{sending 'self.k' risks causing data races}}
// expected-note @-1 {{main actor-isolated 'self.k' cannot be a transferring result. main actor-isolated uses may race with caller uses}}
// expected-note @-1 {{main actor-isolated 'self.k' cannot be a 'sending' result. main actor-isolated uses may race with caller uses}}

func test4() -> (any GlobalActorIsolatedProtocol)? {
self.p
Expand Down Expand Up @@ -248,7 +248,7 @@ extension GlobalActorIsolatedProtocol {
mutating func test3() -> transferring NonSendableKlass {
self.k
} // expected-error {{sending 'self.k' risks causing data races}}
// expected-note @-1 {{main actor-isolated 'self.k' cannot be a transferring result. main actor-isolated uses may race with caller uses}}
// expected-note @-1 {{main actor-isolated 'self.k' cannot be a 'sending' result. main actor-isolated uses may race with caller uses}}

mutating func test4() -> (any GlobalActorIsolatedProtocol)? {
self.p
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ func testPreconcurrencyExplicitlyNonSendable() async {
transferArg(x)

// expected-swift-5-warning @-2 {{sending 'x' risks causing data races}}
// expected-swift-5-note @-3 {{'x' used after being passed as a transferring parameter; Later uses could race}}
// expected-swift-5-note @-3 {{'x' used after being passed as a 'sending' parameter; Later uses could race}}
// expected-swift-6-warning @-4 {{sending 'x' risks causing data races}}
// expected-swift-6-note @-5 {{'x' used after being passed as a transferring parameter; Later uses could race}}
// expected-swift-6-note @-5 {{'x' used after being passed as a 'sending' parameter; Later uses could race}}
useValue(x)
// expected-swift-5-note @-1 {{access can happen concurrently}}
// expected-swift-6-note @-2 {{access can happen concurrently}}
Expand All @@ -77,8 +77,8 @@ func testNormal() async {
transferArg(x) // expected-swift-5-no-tns-warning {{passing argument of non-sendable type 'PostCUncheckedNonSendableKlass' (aka 'NonSendableKlass') into main actor-isolated context may introduce data races}}
// expected-swift-5-warning @-1 {{sending 'x' risks causing data races}}
// expected-swift-6-error @-2 {{sending 'x' risks causing data races}}
// expected-swift-5-note @-3 {{'x' used after being passed as a transferring parameter; Later uses could race}}
// expected-swift-6-note @-4 {{'x' used after being passed as a transferring parameter; Later uses could race}}
// expected-swift-5-note @-3 {{'x' used after being passed as a 'sending' parameter; Later uses could race}}
// expected-swift-6-note @-4 {{'x' used after being passed as a 'sending' parameter; Later uses could race}}
useValue(x) // expected-swift-5-note {{access can happen concurrently}}
// expected-swift-6-note @-1 {{access can happen concurrently}}
}
Expand All @@ -91,9 +91,9 @@ func testOnlyErrorOnExactValue() async {
transferArg(y)
// expected-swift-5-no-tns-warning @-1 2{{passing argument of non-sendable type '(PreCUncheckedNonSendableKlass, PreCUncheckedNonSendableKlass)' (aka '(NonSendableKlass, NonSendableKlass)') into main actor-isolated context may introduce data races}}
// expected-swift-5-warning @-2 {{sending 'y' risks causing data races}}
// expected-swift-5-note @-3 {{'y' used after being passed as a transferring parameter; Later uses could race}}
// expected-swift-5-note @-3 {{'y' used after being passed as a 'sending' parameter; Later uses could race}}
// expected-swift-6-error @-4 {{sending 'y' risks causing data races}}
// expected-swift-6-note @-5 {{'y' used after being passed as a transferring parameter; Later uses could race}}
// expected-swift-6-note @-5 {{'y' used after being passed as a 'sending' parameter; Later uses could race}}
useValue(x)
// expected-swift-5-note @-1 {{access can happen concurrently}}
// expected-swift-6-note @-2 {{access can happen concurrently}}
Expand All @@ -118,35 +118,35 @@ func testNeverTransfer(_ x: PreCUncheckedNonSendableKlass) async {
func testNeverTransferExplicit(_ x: PreCUncheckedExplicitlyNonSendableKlass) async {
transferArg(x) // expected-swift-5-no-tns-warning {{passing argument of non-sendable type 'PreCUncheckedExplicitlyNonSendableKlass' (aka 'ExplicitlyNonSendableKlass') into main actor-isolated context may introduce data races}}
// expected-swift-5-warning @-1 {{sending 'x' risks causing data races}}
// expected-swift-5-note @-2 {{task-isolated 'x' is passed as a transferring parameter; Uses in callee may race with later task-isolated uses}}
// expected-swift-5-note @-2 {{task-isolated 'x' is passed as a 'sending' parameter; Uses in callee may race with later task-isolated uses}}
// expected-swift-6-warning @-3 {{sending 'x' risks causing data races}}
// expected-swift-6-note @-4 {{task-isolated 'x' is passed as a transferring parameter; Uses in callee may race with later task-isolated uses}}
// expected-swift-6-note @-4 {{task-isolated 'x' is passed as a 'sending' parameter; Uses in callee may race with later task-isolated uses}}
}

func testNeverTransferNormal(_ x: PostCUncheckedNonSendableKlass) async {
transferArg(x) // expected-swift-5-no-tns-warning {{passing argument of non-sendable type 'PostCUncheckedNonSendableKlass' (aka 'NonSendableKlass') into main actor-isolated context may introduce data races}}
// expected-swift-5-warning @-1 {{sending 'x' risks causing data races}}
// expected-swift-5-note @-2 {{task-isolated 'x' is passed as a transferring parameter; Uses in callee may race with later task-isolated uses}}
// expected-swift-5-note @-2 {{task-isolated 'x' is passed as a 'sending' parameter; Uses in callee may race with later task-isolated uses}}
// expected-swift-6-error @-3 {{sending 'x' risks causing data races}}
// expected-swift-6-note @-4 {{task-isolated 'x' is passed as a transferring parameter; Uses in callee may race with later task-isolated uses}}
// expected-swift-6-note @-4 {{task-isolated 'x' is passed as a 'sending' parameter; Uses in callee may race with later task-isolated uses}}
}

// Inexact match => normal behavior.
func testNeverTransferInexactMatch(_ x: (PreCUncheckedNonSendableKlass, PreCUncheckedNonSendableKlass)) async {
transferArg(x) // expected-swift-5-no-tns-warning 2{{passing argument of non-sendable type '(PreCUncheckedNonSendableKlass, PreCUncheckedNonSendableKlass)' (aka '(NonSendableKlass, NonSendableKlass)') into main actor-isolated context may introduce data races}}
// expected-swift-5-warning @-1 {{sending 'x' risks causing data races}}
// expected-swift-5-note @-2 {{task-isolated 'x' is passed as a transferring parameter; Uses in callee may race with later task-isolated uses}}
// expected-swift-5-note @-2 {{task-isolated 'x' is passed as a 'sending' parameter; Uses in callee may race with later task-isolated uses}}
// expected-swift-6-error @-3 {{sending 'x' risks causing data races}}
// expected-swift-6-note @-4 {{task-isolated 'x' is passed as a transferring parameter; Uses in callee may race with later task-isolated uses}}
// expected-swift-6-note @-4 {{task-isolated 'x' is passed as a 'sending' parameter; Uses in callee may race with later task-isolated uses}}
}

// Inexact match => normal behavior.
func testNeverTransferInexactMatchExplicit(_ x: (PreCUncheckedExplicitlyNonSendableKlass, PreCUncheckedExplicitlyNonSendableKlass)) async {
transferArg(x) // expected-swift-5-no-tns-warning {{passing argument of non-sendable type '(PreCUncheckedExplicitlyNonSendableKlass, PreCUncheckedExplicitlyNonSendableKlass)' (aka '(ExplicitlyNonSendableKlass, ExplicitlyNonSendableKlass)') into main actor-isolated context may introduce data races}}
// expected-swift-5-warning @-1 {{sending 'x' risks causing data races}}
// expected-swift-5-note @-2 {{task-isolated 'x' is passed as a transferring parameter; Uses in callee may race with later task-isolated uses}}
// expected-swift-5-note @-2 {{task-isolated 'x' is passed as a 'sending' parameter; Uses in callee may race with later task-isolated uses}}
// expected-swift-6-error @-3 {{sending 'x' risks causing data races}}
// expected-swift-6-note @-4 {{task-isolated 'x' is passed as a transferring parameter; Uses in callee may race with later task-isolated uses}}
// expected-swift-6-note @-4 {{task-isolated 'x' is passed as a 'sending' parameter; Uses in callee may race with later task-isolated uses}}
}


Loading

0 comments on commit 71e95b9

Please sign in to comment.