Skip to content

Commit aa9a2f6

Browse files
committed
[region-isolation] Clean up the call passes self error to be the shorter "task or actor isolated value cannot be transferred".
We do not emit these very much anymore. I am just keeping it in place a bit longer... eventually, this should just be an unknown pattern error since if a user sees this it won't compile and we would rather then send it to us so we can fix it.
1 parent 50712a1 commit aa9a2f6

File tree

5 files changed

+24
-21
lines changed

5 files changed

+24
-21
lines changed

include/swift/AST/DiagnosticsSIL.def

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -939,8 +939,6 @@ ERROR(regionbasedisolation_unknown_pattern, none,
939939
// Old Transfer Non Sendable Diagnostics
940940
//
941941

942-
ERROR(regionbasedisolation_selforargtransferred, none,
943-
"call site passes `self` or a non-sendable argument of this function to another thread, potentially yielding a race with the caller", ())
944942
ERROR(regionbasedisolation_transfer_yields_race_no_isolation, none,
945943
"transferring value of non-Sendable type %0; later accesses could race",
946944
(Type))
@@ -998,6 +996,9 @@ ERROR(regionbasedisolation_named_arg_passed_to_strongly_transferred_param, none,
998996
"%0 %1 passed as a strongly transferred parameter; Uses in callee could race with later %0 uses",
999997
(StringRef, Identifier))
1000998

999+
ERROR(regionbasedisolation_task_or_actor_isolated_transferred, none,
1000+
"task or actor isolated value cannot be transferred", ())
1001+
10011002
// TODO: print the name of the nominal type
10021003
ERROR(deinit_not_visible, none,
10031004
"deinit of non-copyable type not visible in the current module", ())

lib/SILOptimizer/Mandatory/TransferNonSendable.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -912,8 +912,10 @@ class TransferNonTransferrableDiagnosticEmitter {
912912
diag::regionbasedisolation_unknown_pattern);
913913
}
914914

915-
void emitMiscUses(SILLocation loc) {
916-
diagnoseError(loc, diag::regionbasedisolation_selforargtransferred);
915+
void emitUnknownUse(SILLocation loc) {
916+
// TODO: This will eventually be an unknown pattern error.
917+
diagnoseError(
918+
loc, diag::regionbasedisolation_task_or_actor_isolated_transferred);
917919
}
918920

919921
void emitFunctionArgumentApply(SILLocation loc, Type type,
@@ -1169,7 +1171,7 @@ bool TransferNonTransferrableDiagnosticInferrer::run() {
11691171
}
11701172
}
11711173

1172-
diagnosticEmitter.emitMiscUses(loc);
1174+
diagnosticEmitter.emitUnknownUse(loc);
11731175
return true;
11741176
}
11751177

test/Concurrency/issue-57376.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,35 +26,35 @@ func testAsyncSequence1Sendable<Seq: AsyncSequence>(_ seq: Seq) async throws whe
2626
}
2727

2828
func testAsyncSequenceTypedPattern<Seq: AsyncSequence>(_ seq: Seq) async throws where Seq.Element == Int { // expected-targeted-and-complete-note {{consider making generic parameter 'Seq' conform to the 'Sendable' protocol}} {{54-54=, Sendable}}
29-
async let result: Int = seq.reduce(0) { $0 + $1 } // expected-tns-warning {{call site passes `self` or a non-sendable argument of this function to another thread, potentially yielding a race with the caller}}
29+
async let result: Int = seq.reduce(0) { $0 + $1 } // expected-tns-warning {{task or actor isolated value cannot be transferred}}
3030
// expected-warning @-1 {{immutable value 'result' was never used; consider replacing with '_' or removing it}}
3131
// expected-targeted-and-complete-warning @-2 {{capture of 'seq' with non-sendable type 'Seq' in 'async let' binding}}
3232
}
3333

3434
func testAsyncSequenceTypedPattern1<Seq: AsyncSequence>(_ seq: Seq) async throws where Seq.Element == Int { // expected-targeted-and-complete-note {{consider making generic parameter 'Seq' conform to the 'Sendable' protocol}} {{55-55=, Sendable}}
35-
async let _: Int = seq.reduce(0) { $0 + $1 } // expected-tns-warning {{call site passes `self` or a non-sendable argument of this function to another thread, potentially yielding a race with the caller}}
35+
async let _: Int = seq.reduce(0) { $0 + $1 } // expected-tns-warning {{task or actor isolated value cannot be transferred}}
3636
// expected-targeted-and-complete-warning @-1 {{capture of 'seq' with non-sendable type 'Seq' in 'async let' binding}}
3737
}
3838

3939
func testAsyncSequence<Seq: AsyncSequence>(_ seq: Seq) async throws where Seq.Element == Int { // expected-targeted-and-complete-note {{consider making generic parameter 'Seq' conform to the 'Sendable' protocol}} {{42-42=, Sendable}}
40-
async let result = seq.reduce(0) { $0 + $1 } // expected-tns-warning {{call site passes `self` or a non-sendable argument of this function to another thread, potentially yielding a race with the caller}}
40+
async let result = seq.reduce(0) { $0 + $1 } // // expected-tns-warning {{task or actor isolated value cannot be transferred}}
4141
// expected-warning @-1 {{initialization of immutable value 'result' was never used; consider replacing with assignment to '_' or removing it}}
4242
// expected-targeted-and-complete-warning @-2 {{capture of 'seq' with non-sendable type 'Seq' in 'async let' binding}}
4343
}
4444

4545
func testAsyncSequence1<Seq: AsyncSequence>(_ seq: Seq) async throws where Seq.Element == Int { // expected-targeted-and-complete-note {{consider making generic parameter 'Seq' conform to the 'Sendable' protocol}} {{43-43=, Sendable}}
46-
async let _ = seq.reduce(0) { $0 + $1 } // expected-tns-warning {{call site passes `self` or a non-sendable argument of this function to another thread, potentially yielding a race with the caller}}
46+
async let _ = seq.reduce(0) { $0 + $1 } // // expected-tns-warning {{task or actor isolated value cannot be transferred}}
4747
// expected-targeted-and-complete-warning @-1 {{capture of 'seq' with non-sendable type 'Seq' in 'async let' binding}}
4848
}
4949

5050
func testAsyncSequence3<Seq>(_ seq: Seq) async throws where Seq: AsyncSequence, Seq.Element == Int { // expected-targeted-and-complete-note {{consider making generic parameter 'Seq' conform to the 'Sendable' protocol}} {{28-28=: Sendable}}
51-
async let result = seq // expected-tns-warning {{call site passes `self` or a non-sendable argument of this function to another thread, potentially yielding a race with the caller}}
51+
async let result = seq // // expected-tns-warning {{task or actor isolated value cannot be transferred}}
5252
// expected-targeted-and-complete-warning @-1 {{capture of 'seq' with non-sendable type 'Seq' in 'async let' binding}}
5353
//expected-warning @-2 {{initialization of immutable value 'result' was never used; consider replacing with assignment to '_' or removing it}}
5454
}
5555

5656
func testAsyncSequence4<Seq>(_ seq: Seq) async throws where Seq: AsyncSequence, Seq.Element == Int { // expected-targeted-and-complete-note {{consider making generic parameter 'Seq' conform to the 'Sendable' protocol}} {{28-28=: Sendable}}
57-
async let _ = seq // expected-tns-warning {{call site passes `self` or a non-sendable argument of this function to another thread, potentially yielding a race with the caller}}
57+
async let _ = seq // // expected-tns-warning {{task or actor isolated value cannot be transferred}}
5858
// expected-targeted-and-complete-warning @-1 {{capture of 'seq' with non-sendable type 'Seq' in 'async let' binding}}
5959
}
6060

test/Concurrency/transfernonsendable.sil

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,39 +222,39 @@ bb0(%0 : @guaranteed $NonSendableStruct):
222222
debug_value %0 : $NonSendableStruct, var, name "myname"
223223
%2 = struct_extract %0 : $NonSendableStruct, #NonSendableStruct.ns
224224
%3 = copy_value %2 : $NonSendableKlass
225-
return %3 : $NonSendableKlass // expected-warning {{call site passes `self`}}
225+
return %3 : $NonSendableKlass // expected-warning {{task or actor isolated value cannot be transferred}}
226226
}
227227

228228
sil [ossa] @synchronous_returns_transferring_globalactor_struct_structextract : $@convention(method) (@guaranteed MainActorIsolatedStruct) -> @sil_transferring @owned NonSendableKlass {
229229
bb0(%0 : @guaranteed $MainActorIsolatedStruct):
230230
debug_value %0 : $MainActorIsolatedStruct, var, name "myname"
231231
%2 = struct_extract %0 : $MainActorIsolatedStruct, #MainActorIsolatedStruct.ns
232232
%3 = copy_value %2 : $NonSendableKlass
233-
return %3 : $NonSendableKlass // expected-warning {{call site passes `self`}}
233+
return %3 : $NonSendableKlass // expected-warning {{task or actor isolated value cannot be transferred}}
234234
}
235235

236236
sil [ossa] @synchronous_returns_transferring_globalactor_struct_structelementaddr : $@convention(method) (@in_guaranteed MainActorIsolatedStruct) -> @sil_transferring @owned NonSendableKlass {
237237
bb0(%0 : $*MainActorIsolatedStruct):
238238
debug_value %0 : $*MainActorIsolatedStruct, var, name "myname"
239239
%2 = struct_element_addr %0 : $*MainActorIsolatedStruct, #MainActorIsolatedStruct.ns
240240
%3 = load [copy] %2 : $*NonSendableKlass
241-
return %3 : $NonSendableKlass // expected-warning {{call site passes `self`}}
241+
return %3 : $NonSendableKlass // expected-warning {{task or actor isolated value cannot be transferred}}
242242
}
243243

244244
sil [ossa] @synchronous_returns_transferring_globalactor_enum_uncheckedenumdata : $@convention(method) (@guaranteed MainActorIsolatedEnum) -> @sil_transferring @owned NonSendableKlass {
245245
bb0(%0 : @guaranteed $MainActorIsolatedEnum):
246246
debug_value %0 : $MainActorIsolatedEnum, var, name "myname"
247247
%2 = unchecked_enum_data %0 : $MainActorIsolatedEnum, #MainActorIsolatedEnum.second!enumelt
248248
%3 = copy_value %2 : $NonSendableKlass
249-
return %3 : $NonSendableKlass // expected-warning {{call site passes `self`}}
249+
return %3 : $NonSendableKlass // expected-warning {{task or actor isolated value cannot be transferred}}
250250
}
251251

252252
sil [ossa] @synchronous_returns_transferring_globalactor_enum_uncheckedtakeenumdataaddr : $@convention(method) (@in MainActorIsolatedEnum) -> @sil_transferring @owned NonSendableKlass {
253253
bb0(%0 : $*MainActorIsolatedEnum):
254254
debug_value %0 : $*MainActorIsolatedEnum, var, name "myname"
255255
%2 = unchecked_take_enum_data_addr %0 : $*MainActorIsolatedEnum, #MainActorIsolatedEnum.second!enumelt
256256
%3 = load [take] %2 : $*NonSendableKlass
257-
return %3 : $NonSendableKlass // expected-warning {{call site passes `self`}}
257+
return %3 : $NonSendableKlass // expected-warning {{task or actor isolated value cannot be transferred}}
258258
}
259259

260260
sil [ossa] @synchronous_returns_transferring_globalactor_enum_switchenum : $@convention(method) (@guaranteed MainActorIsolatedEnum) -> @sil_transferring @owned FakeOptional<NonSendableKlass> {
@@ -272,7 +272,7 @@ bb2(%1 : @guaranteed $NonSendableKlass):
272272
br bb3(%3 : $FakeOptional<NonSendableKlass>)
273273

274274
bb3(%4 : @owned $FakeOptional<NonSendableKlass>):
275-
return %4 : $FakeOptional<NonSendableKlass> // expected-warning {{call site passes `self`}}
275+
return %4 : $FakeOptional<NonSendableKlass> // expected-warning {{task or actor isolated value cannot be transferred}}
276276
}
277277

278278
sil [ossa] @warningIfCallingGetter : $@convention(method) @async (@sil_isolated @guaranteed MyActor) -> () {

test/Concurrency/transfernonsendable_strong_transferring_results.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func transferInAndOut(_ x: transferring NonSendableKlass) -> transferring NonSen
110110

111111

112112
func transferReturnArg(_ x: NonSendableKlass) -> transferring NonSendableKlass {
113-
return x // expected-warning {{call site passes `self` or a non-sendable argument of this function to another thread, potentially yielding a race with the caller}}
113+
return x // expected-warning {{task or actor isolated value cannot be transferred}}
114114
}
115115

116116
// This is safe since we are returning the whole tuple fresh. In contrast,
@@ -130,7 +130,7 @@ func useTransferredResult() async {
130130

131131
extension MainActorIsolatedStruct {
132132
func testNonSendableErrorReturnWithTransfer() -> transferring NonSendableKlass {
133-
return ns // expected-warning {{call site passes `self`}}
133+
return ns // expected-warning {{task or actor isolated value cannot be transferred}}
134134
}
135135
func testNonSendableErrorReturnNoTransfer() -> NonSendableKlass {
136136
return ns
@@ -146,7 +146,7 @@ extension MainActorIsolatedEnum {
146146
return ns
147147
}
148148
// TODO: This should be on return ns.
149-
} // expected-warning {{call site passes `self`}}
149+
} // expected-warning {{task or actor isolated value cannot be transferred}}
150150

151151
func testSwitchReturnNoTransfer() -> NonSendableKlass? {
152152
switch self {
@@ -162,7 +162,7 @@ extension MainActorIsolatedEnum {
162162
return ns // TODO: The error below should be here.
163163
}
164164
return nil
165-
} // expected-warning {{call site passes `self`}}
165+
} // expected-warning {{task or actor isolated value cannot be transferred}}
166166

167167
func testIfLetReturnNoTransfer() -> NonSendableKlass? {
168168
if case .second(let ns) = self {

0 commit comments

Comments
 (0)