Skip to content

Commit e7e035f

Browse files
committed
[region-isolation] Convert the transfer non sendable typed error to be a new short-error, long-note form error.
I also messed with the text a little bit. This eliminates the last of the old style diagnostics.
1 parent 359ae52 commit e7e035f

16 files changed

+127
-67
lines changed

include/swift/AST/DiagnosticsSIL.def

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -944,18 +944,6 @@ ERROR(regionbasedisolation_unknown_pattern, none,
944944
"pattern that the region based isolation checker does not understand how to check. Please file a bug",
945945
())
946946

947-
//===---
948-
// Old Transfer Non Sendable Diagnostics
949-
//
950-
951-
ERROR(regionbasedisolation_arg_transferred, none,
952-
"sending %0 value of type %1 with later accesses to %2 context risks causing data races",
953-
(StringRef, Type, ActorIsolation))
954-
955-
//===---
956-
// New Transfer Non Sendable Diagnostics
957-
//
958-
959947
ERROR(regionbasedisolation_named_transfer_yields_race, none,
960948
"sending %0 risks causing data races",
961949
(Identifier))
@@ -1030,7 +1018,7 @@ NOTE(regionbasedisolation_typed_tns_passed_to_sending, none,
10301018
"Passing %0 value of non-Sendable type %1 as a 'sending' parameter risks causing races inbetween %0 uses and uses reachable from the callee",
10311019
(StringRef, Type))
10321020
NOTE(regionbasedisolation_typed_tns_passed_to_sending_callee, none,
1033-
"Passing %0 value of non-Sendable type %1 as a 'sending' parameter to %2 %3 risks causing races inbetween %0 uses and uses reachable from %2",
1021+
"Passing %0 value of non-Sendable type %1 as a 'sending' parameter to %2 %3 risks causing races inbetween %0 uses and uses reachable from %3",
10341022
(StringRef, Type, DescriptiveDeclKind, DeclName))
10351023

10361024
NOTE(regionbasedisolation_named_transfer_nt_asynclet_capture, none,
@@ -1044,6 +1032,13 @@ NOTE(regionbasedisolation_typed_use_after_sending_callee, none,
10441032
"Passing value of non-Sendable type %0 as a 'sending' argument to %1 %2 risks causing races in between local and caller code",
10451033
(Type, DescriptiveDeclKind, DeclName))
10461034

1035+
NOTE(regionbasedisolation_typed_transferneversendable_via_arg, none,
1036+
"sending %0 value of non-Sendable type %1 to %2 callee risks causing races in between %0 and %2 uses",
1037+
(StringRef, Type, ActorIsolation))
1038+
NOTE(regionbasedisolation_typed_transferneversendable_via_arg_callee, none,
1039+
"sending %0 value of non-Sendable type %1 to %2 %3 %4 risks causing races in between %0 and %2 uses",
1040+
(StringRef, Type, ActorIsolation, DescriptiveDeclKind, DeclName))
1041+
10471042
// Misc Error.
10481043
ERROR(regionbasedisolation_task_or_actor_isolated_transferred, none,
10491044
"task or actor isolated value cannot be sent", ())

lib/SILOptimizer/Mandatory/TransferNonSendable.cpp

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,17 +1315,30 @@ class TransferNonTransferrableDiagnosticEmitter {
13151315
.limitBehaviorIf(getBehaviorLimit());
13161316
}
13171317

1318-
void emitFunctionArgumentApply(SILLocation loc, Type type,
1319-
ApplyIsolationCrossing crossing) {
1318+
void emitPassToApply(SILLocation loc, Type inferredType,
1319+
ApplyIsolationCrossing crossing) {
1320+
diagnoseError(loc, diag::regionbasedisolation_type_transfer_yields_race,
1321+
inferredType)
1322+
.highlight(loc.getSourceRange())
1323+
.limitBehaviorIf(getBehaviorLimit());
1324+
13201325
SmallString<64> descriptiveKindStr;
13211326
{
13221327
llvm::raw_svector_ostream os(descriptiveKindStr);
13231328
getIsolationRegionInfo().printForDiagnostics(os);
13241329
}
1325-
diagnoseError(loc, diag::regionbasedisolation_arg_transferred,
1326-
descriptiveKindStr, type, crossing.getCalleeIsolation())
1327-
.highlight(getOperand()->getUser()->getLoc().getSourceRange())
1328-
.limitBehaviorIf(getBehaviorLimit());
1330+
1331+
if (auto calleeInfo = getTransferringCalleeInfo()) {
1332+
diagnoseNote(
1333+
loc,
1334+
diag::regionbasedisolation_typed_transferneversendable_via_arg_callee,
1335+
descriptiveKindStr, inferredType, crossing.getCalleeIsolation(),
1336+
calleeInfo->first, calleeInfo->second);
1337+
} else {
1338+
diagnoseNote(
1339+
loc, diag::regionbasedisolation_typed_transferneversendable_via_arg,
1340+
descriptiveKindStr, inferredType, crossing.getCalleeIsolation());
1341+
}
13291342
}
13301343

13311344
void emitNamedFunctionArgumentClosure(SILLocation loc, Identifier name,
@@ -1695,7 +1708,7 @@ bool TransferNonTransferrableDiagnosticInferrer::run() {
16951708
}
16961709
}
16971710

1698-
diagnosticEmitter.emitFunctionArgumentApply(loc, type, *isolation);
1711+
diagnosticEmitter.emitPassToApply(loc, type, *isolation);
16991712
return true;
17001713
}
17011714

@@ -1710,8 +1723,8 @@ bool TransferNonTransferrableDiagnosticInferrer::run() {
17101723
// See if we are in SIL and have an apply site specified isolation.
17111724
if (auto fas = FullApplySite::isa(op->getUser())) {
17121725
if (auto isolation = fas.getIsolationCrossing()) {
1713-
diagnosticEmitter.emitFunctionArgumentApply(
1714-
loc, op->get()->getType().getASTType(), *isolation);
1726+
diagnosticEmitter.emitPassToApply(loc, op->get()->getType().getASTType(),
1727+
*isolation);
17151728
return true;
17161729
}
17171730
}

test/Concurrency/concurrent_value_checking.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,19 +413,23 @@ extension NotConcurrent {
413413
func f() { }
414414

415415
func test() {
416-
Task { // expected-tns-warning {{task-isolated value of type '() async -> ()' passed as a strongly transferred parameter}}
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}}
417418
f()
418419
}
419420

420-
Task { // expected-tns-warning {{task-isolated value of type '() async -> ()' passed as a strongly transferred parameter}}
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}}
421423
self.f()
422424
}
423425

424-
Task { [self] in // expected-tns-warning {{task-isolated value of type '() async -> ()' passed as a strongly transferred parameter}}
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}}
425428
f()
426429
}
427430

428-
Task { [self] in // expected-tns-warning {{task-isolated value of type '() async -> ()' passed as a strongly transferred parameter}}
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}}
429433
self.f()
430434
}
431435
}

test/Concurrency/isolated_parameters.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,8 @@ func testNonSendableCaptures(ns: NotSendable, a: isolated MyActor) {
501501

502502
// FIXME: The `a` in the capture list and `isolated a` are the same,
503503
// 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 {{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}}
505506
_ = a
506507
_ = ns
507508
}

test/Concurrency/sendable_preconcurrency.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ struct MyType3 {
3232

3333
func testA(ns: NS, mt: MyType, mt2: MyType2, mt3: MyType3, sc: StrictClass, nsc: NonStrictClass) async {
3434
// This is task isolated since we are capturing function arguments.
35-
Task { // expected-tns-warning {{task-isolated value of type '() async -> ()' passed as a strongly transferred parameter}}
35+
Task { // expected-tns-warning {{sending value of non-Sendable type '() async -> ()' risks causing data races}}
36+
// 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}}
3637
print(ns)
3738
print(mt) // no warning: MyType is Sendable because we suppressed NonStrictClass's warning
3839
print(mt2)

test/Concurrency/sendable_without_preconcurrency.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ struct MyType2 {
2626
}
2727

2828
func testA(ns: NS, mt: MyType, mt2: MyType2, sc: StrictClass, nsc: NonStrictClass) async {
29-
Task { // expected-tns-warning {{task-isolated value of type '() async -> ()' passed as a strongly transferred parameter; later accesses could race}}
29+
Task { // expected-tns-warning {{sending value of non-Sendable type '() async -> ()' risks causing data races; this is an error in the Swift 6 language mode}}
30+
// 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}}
3031
print(ns)
3132
print(mt) // no warning by default: MyType is Sendable because we suppressed NonStrictClass's warning
3233
print(mt2)

test/Concurrency/sendable_without_preconcurrency_2.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ struct MyType2: Sendable {
2929
}
3030

3131
func testA(ns: NS, mt: MyType, mt2: MyType2, sc: StrictClass, nsc: NonStrictClass) async {
32-
Task { // expected-tns-warning {{task-isolated value of type '() async -> ()' passed as a strongly transferred parameter}}
32+
Task { // expected-tns-warning {{sending value of non-Sendable type '() async -> ()' risks causing data races}}
33+
// 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}}
3334
print(ns)
3435
print(mt) // no warning with targeted: MyType is Sendable because we suppressed NonStrictClass's warning
3536
print(mt2)

test/Concurrency/transfernonsendable.sil

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ bb0(%0 : $*{ var NonSendableKlass }):
114114
%f = function_ref @transferIndirect : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> ()
115115
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %f<NonSendableKlass>(%3) : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> ()
116116
// expected-warning @-1 {{}}
117+
// expected-note @-2 {{}}
117118
destroy_value %1 : ${ var NonSendableKlass }
118119

119120
%9999 = tuple ()
@@ -295,6 +296,7 @@ bb0(%0 : @guaranteed $MyActor):
295296
%4 = apply %3(%0) : $@convention(method) (@sil_isolated @guaranteed MyActor) -> @owned NonSendableKlass
296297
%5 = class_method %4 : $NonSendableKlass, #NonSendableKlass.asyncCall : (NonSendableKlass) -> () async -> (), $@convention(method) @async (@guaranteed NonSendableKlass) -> ()
297298
%6 = apply [caller_isolation=nonisolated] [callee_isolation=actor_instance] %5(%4) : $@convention(method) @async (@guaranteed NonSendableKlass) -> () // expected-warning {{}}
299+
// expected-note @-1 {{}}
298300
destroy_value %4 : $NonSendableKlass
299301
hop_to_executor %0 : $MyActor
300302
%9 = tuple ()
@@ -316,6 +318,7 @@ bb0(%0 : @guaranteed $MyActor):
316318
%12 = store_borrow %6 to %11 : $*NonSendableKlass
317319
%13 = function_ref @transferIndirect : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> ()
318320
%14 = apply [caller_isolation=actor_instance] [callee_isolation=global_actor] %13<NonSendableKlass>(%12) : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> () // expected-warning {{}}
321+
// expected-note @-1 {{}}
319322
end_borrow %12 : $*NonSendableKlass
320323
dealloc_stack %11 : $*NonSendableKlass
321324
hop_to_executor %0 : $MyActor

test/Concurrency/transfernonsendable.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,8 @@ extension MyActor {
265265
let x = (1, closure)
266266
await transferToMain(x) // expected-complete-warning {{passing argument of non-sendable type '(Int, () -> ())' into main actor-isolated context may introduce data races}}
267267
// expected-complete-note @-1 {{a function type must be marked '@Sendable' to conform to 'Sendable'}}
268-
// expected-tns-warning @-2 {{sending 'self'-isolated value of type '(Int, () -> ())' with later accesses to main actor-isolated context risks causing data races}}
268+
// expected-tns-warning @-2 {{sending value of non-Sendable type '(Int, () -> ())' risks causing data races}}
269+
// expected-tns-note @-3 {{sending 'self'-isolated value of non-Sendable type '(Int, () -> ())' to main actor-isolated global function 'transferToMain' risks causing races in between 'self'-isolated and main actor-isolated uses}}
269270
}
270271

271272
func simpleClosureCaptureSelfAndTransferThroughTupleBackwards() async {
@@ -274,9 +275,8 @@ extension MyActor {
274275
}
275276

276277
let x = (closure, 1)
277-
await transferToMain(x) // expected-tns-warning {{sending 'self'-isolated value of type '(() -> (), Int)' with later accesses to main actor-isolated context risks causing data races}}
278-
// expected-complete-warning @-1 {{passing argument of non-sendable type '(() -> (), Int)' into main actor-isolated context may introduce data races}}
279-
// expected-complete-note @-2 {{a function type must be marked '@Sendable' to conform to 'Sendable'}}
278+
await transferToMain(x) // expected-tns-warning {{sending value of non-Sendable type '(() -> (), Int)' risks causing data races}}
279+
// expected-tns-note @-1 {{sending 'self'-isolated value of non-Sendable type '(() -> (), Int)' to main actor-isolated global function 'transferToMain' risks causing races in between 'self'-isolated and main actor-isolated uses}}
280280
}
281281

282282
func simpleClosureCaptureSelfAndTransferThroughOptional() async {

0 commit comments

Comments
 (0)