Skip to content

Commit 2febd26

Browse files
committed
[region-isolation] Convert emitTypedIsolationCrossingDueToCapture error to use a new form of error.
NOTE: To make testing these easier (since they are fallback paths), I added an option that disables named errors only for use in asserts.
1 parent bfdbc76 commit 2febd26

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

include/swift/AST/DiagnosticsSIL.def

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -948,9 +948,6 @@ ERROR(regionbasedisolation_unknown_pattern, none,
948948
// Old Transfer Non Sendable Diagnostics
949949
//
950950

951-
ERROR(regionbasedisolation_isolated_capture_yields_race, none,
952-
"%1 closure captures value of non-Sendable type %0 from %2 context; later accesses to value could race",
953-
(Type, ActorIsolation, ActorIsolation))
954951
ERROR(regionbasedisolation_transfer_yields_race_stronglytransferred_binding, none,
955952
"value of non-Sendable type %0 accessed after being transferred; later accesses could race",
956953
(Type))
@@ -981,6 +978,9 @@ NOTE(regionbasedisolation_type_use_after_transfer, none,
981978
NOTE(regionbasedisolation_type_use_after_transfer_callee, none,
982979
"sending value of non-Sendable type %0 to %1 %2 %3 risks causing data races between %1 and local %4 uses",
983980
(Type, ActorIsolation, DescriptiveDeclKind, DeclName, ActorIsolation))
981+
NOTE(regionbasedisolation_type_isolated_capture_yields_race, none,
982+
"sending value of non-Sendable type %0 to %1 closure due to closure capture risks causing races in between %1 and %2 uses",
983+
(Type, ActorIsolation, ActorIsolation))
984984

985985
ERROR(regionbasedisolation_inout_sending_cannot_be_actor_isolated, none,
986986
"'inout sending' parameter %0 cannot be %1at end of function",

lib/SILOptimizer/Mandatory/TransferNonSendable.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -779,11 +779,13 @@ class UseAfterTransferDiagnosticEmitter {
779779
void emitTypedIsolationCrossingDueToCapture(
780780
SILLocation loc, Type inferredType,
781781
ApplyIsolationCrossing isolationCrossing) {
782-
diagnoseError(loc, diag::regionbasedisolation_isolated_capture_yields_race,
783-
inferredType, isolationCrossing.getCalleeIsolation(),
784-
isolationCrossing.getCallerIsolation())
785-
.highlight(loc.getSourceRange())
782+
diagnoseError(loc, diag::regionbasedisolation_type_transfer_yields_race,
783+
inferredType)
786784
.limitBehaviorIf(getBehaviorLimit());
785+
diagnoseNote(loc,
786+
diag::regionbasedisolation_type_isolated_capture_yields_race,
787+
inferredType, isolationCrossing.getCalleeIsolation(),
788+
isolationCrossing.getCallerIsolation());
787789
emitRequireInstDiagnostics();
788790
}
789791

test/Concurrency/transfernonsendable_typed_errors.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,12 @@ func simpleUseAfterFree() async {
2929
// expected-note @-1 {{sending value of non-Sendable type 'NonSendableKlass' to main actor-isolated global function 'transferToMain' risks causing data races between main actor-isolated and local nonisolated uses}}
3030
print(x) // expected-note {{access can happen concurrently}}
3131
}
32+
33+
func isolatedClosureTest() async {
34+
let x = NonSendableKlass()
35+
let _ = { @MainActor in
36+
print(x) // expected-error {{sending value of non-Sendable type 'NonSendableKlass' risks causing data races}}
37+
// expected-note @-1 {{sending value of non-Sendable type 'NonSendableKlass' to main actor-isolated closure due to closure capture risks causing races in between main actor-isolated and nonisolated uses}}
38+
}
39+
print(x) // expected-note {{access can happen concurrently}}
40+
}

0 commit comments

Comments
 (0)