Skip to content

Commit 7f43c3a

Browse files
committed
[region-isolation] Eliminate "call site passes self" error from all SIL tests.
1 parent e21c0a6 commit 7f43c3a

File tree

4 files changed

+28
-18
lines changed

4 files changed

+28
-18
lines changed

lib/SILOptimizer/Mandatory/TransferNonSendable.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,11 +1074,10 @@ bool TransferNonTransferrableDiagnosticInferrer::initForIsolatedPartialApply(
10741074

10751075
bool TransferNonTransferrableDiagnosticInferrer::run() {
10761076
// We need to find the isolation info.
1077+
auto *op = info.transferredOperand;
10771078
auto loc = info.transferredOperand->getUser()->getLoc();
10781079

10791080
if (auto *sourceApply = loc.getAsASTNode<ApplyExpr>()) {
1080-
auto *op = info.transferredOperand;
1081-
10821081
std::optional<ApplyIsolationCrossing> isolation = {};
10831082

10841083
// First try to get the apply from the isolation crossing.
@@ -1139,6 +1138,15 @@ bool TransferNonTransferrableDiagnosticInferrer::run() {
11391138
}
11401139
}
11411140

1141+
// See if we are in SIL and have an apply site specified isolation.
1142+
if (auto fas = FullApplySite::isa(op->getUser())) {
1143+
if (auto isolation = fas.getIsolationCrossing()) {
1144+
diagnosticInfo = UseDiagnosticInfo::forFunctionArgumentApply(
1145+
*isolation, op->get()->getType().getASTType());
1146+
return true;
1147+
}
1148+
}
1149+
11421150
diagnosticInfo = UseDiagnosticInfo::forMiscUse();
11431151
return true;
11441152
}
@@ -1183,10 +1191,12 @@ void TransferNonSendableImpl::emitTransferredNonTransferrableDiagnostics() {
11831191
if (rep.maybeGetValue() == info.nonTransferrableValue)
11841192
continue;
11851193
auto *fArg = cast<SILFunctionArgument>(info.nonTransferrableValue);
1186-
diagnoseNote(
1187-
astContext, fArg->getDecl()->getLoc(),
1188-
diag::regionbasedisolation_isolated_since_in_same_region_basename,
1189-
"task isolated", fArg->getDecl()->getBaseName());
1194+
if (fArg->getDecl()) {
1195+
diagnoseNote(
1196+
astContext, fArg->getDecl()->getLoc(),
1197+
diag::regionbasedisolation_isolated_since_in_same_region_basename,
1198+
"task isolated", fArg->getDecl()->getBaseName());
1199+
}
11901200
break;
11911201
}
11921202
case UseDiagnosticInfoKind::FunctionArgumentClosure: {

test/Concurrency/transfernonsendable.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ bb0(%0 : $*{ var NonSendableKlass }):
8787

8888
%f = function_ref @transferIndirect : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> ()
8989
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %f<NonSendableKlass>(%3) : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> ()
90-
// expected-warning @-1 {{call site passes `self` or a non-sendable argument of this function to another thread, potentially yielding a race with the caller}}
90+
// expected-warning @-1 {{task isolated value of type 'NonSendableKlass' transferred to global actor '<null>'-isolated context}}
9191
destroy_value %1 : ${ var NonSendableKlass }
9292

9393
%9999 = tuple ()

test/Concurrency/transfernonsendable_instruction_matching.sil

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ bb0(%0 : @owned $NonSendableStruct):
310310

311311
%4 = function_ref @transferIndirect : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> ()
312312
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %4<NonSendableStruct>(%2) : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> ()
313-
// expected-warning @-1 {{call site passes `self` or a non-sendable argument of this function to another thread, potentially yielding a race with the caller}}
313+
// expected-warning @-1 {{task isolated value of type 'NonSendableStruct' transferred to global actor '<null>'-isolated context}}
314314

315315
%5 = function_ref @useIndirect : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> ()
316316
apply %5<NonSendableStruct>(%2) : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> ()
@@ -328,7 +328,7 @@ bb0(%0 : $*NonSendableStruct):
328328
%2 = moveonlywrapper_to_copyable_addr %1 : $*@moveOnly NonSendableStruct
329329
%4 = function_ref @transferIndirect : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> ()
330330
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %4<NonSendableStruct>(%2) : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> ()
331-
// expected-warning @-1 {{call site passes `self` or a non-sendable argument of this function to another thread, potentially yielding a race with the caller}}
331+
// expected-warning @-1 {{task isolated value of type 'NonSendableStruct' transferred to global actor '<null>'-isolated context}}
332332
%9999 = tuple ()
333333
return %9999 : $()
334334
}
@@ -340,7 +340,7 @@ bb0(%0 : @owned $@callee_guaranteed @substituted <τ_0_0> () -> @out τ_0_0 for
340340
store %0 to [init] %blockAddr : $*@callee_guaranteed @substituted <τ_0_0> () -> @out τ_0_0 for <()>
341341
%4 = function_ref @transferIndirect : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> ()
342342
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %4<() -> ()>(%blockAddr) : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> ()
343-
// expected-warning @-1 {{call site passes `self` or a non-sendable argument of this function to another thread, potentially yielding a race with the caller}}
343+
// expected-warning @-1 {{task isolated value of type '@callee_guaranteed @substituted <τ_0_0> () -> @out τ_0_0 for <()>' transferred to global actor '<null>'-isolated context}}
344344

345345
%5 = function_ref @useIndirect : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> ()
346346
apply %5<() -> ()>(%blockAddr) : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> ()
@@ -393,7 +393,7 @@ bb0(%0 : $*NonSendableKlass):
393393
mark_unresolved_move_addr %0 to %1 : $*NonSendableKlass
394394
%4 = function_ref @transferIndirect : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> ()
395395
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %4<NonSendableKlass>(%1) : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> ()
396-
// expected-warning @-1 {{call site passes `self` or a non-sendable argument of this function to another thread, potentially yielding a race with the caller}}
396+
// expected-warning @-1 {{task isolated value of type 'NonSendableKlass' transferred to global actor '<null>'-isolated context}}
397397
destroy_addr %0 : $*NonSendableKlass
398398
destroy_addr %1 : $*NonSendableKlass
399399
dealloc_stack %1 : $*NonSendableKlass
@@ -529,9 +529,9 @@ bb0(%0 : $Builtin.RawPointer):
529529
// Should error on both since the raw pointer is from an argument.
530530
%transferNonSendableKlass = function_ref @transferNonSendableKlass : $@convention(thin) @async (@guaranteed NonSendableKlass) -> ()
531531
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %transferNonSendableKlass(%4) : $@convention(thin) @async (@guaranteed NonSendableKlass) -> ()
532-
// expected-warning @-1 {{call site passes `self` or a non-sendable argument of this function to another thread, potentially yielding a race with the caller}}
532+
// expected-warning @-1 {{task isolated value of type 'NonSendableKlass' transferred to global actor '<null>'-isolated context}}
533533
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %transferNonSendableKlass(%6) : $@convention(thin) @async (@guaranteed NonSendableKlass) -> ()
534-
// expected-warning @-1 {{call site passes `self` or a non-sendable argument of this function to another thread, potentially yielding a race with the caller}}
534+
// expected-warning @-1 {{task isolated value of type 'NonSendableKlass' transferred to global actor '<null>'-isolated context}}
535535

536536
destroy_value %4 : $NonSendableKlass
537537
destroy_value %6 : $NonSendableKlass
@@ -563,13 +563,13 @@ bb0(%0 : $Builtin.RawPointer):
563563
// But if we transfer the raw pointers and use them later we get separate errors.
564564
%transferRawPointer = function_ref @transferRawPointer : $@convention(thin) @async (Builtin.RawPointer) -> ()
565565
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %transferRawPointer(%0) : $@convention(thin) @async (Builtin.RawPointer) -> ()
566-
// expected-warning @-1 {{call site passes `self` or a non-sendable argument of this function to another thread, potentially yielding a race with the caller}}
566+
// expected-warning @-1 {{task isolated value of type 'Builtin.RawPointer' transferred to global actor '<null>'-isolated context}}
567567
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %transferRawPointer(%2) : $@convention(thin) @async (Builtin.RawPointer) -> ()
568-
// expected-warning @-1 {{call site passes `self` or a non-sendable argument of this function to another thread, potentially yielding a race with the caller}}
568+
// expected-warning @-1 {{task isolated value of type 'Builtin.RawPointer' transferred to global actor '<null>'-isolated context}}
569569
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %transferRawPointer(%3a) : $@convention(thin) @async (Builtin.RawPointer) -> ()
570-
// expected-warning @-1 {{transferring value of non-Sendable type 'Builtin.RawPointer' from nonisolated context to global actor '<null>'-isolated context; later accesses could race}}
570+
// expected-warning @-1 {{transferring value of non-Sendable type 'Builtin.RawPointer' from nonisolated context to global actor '<null>'-isolated context}}
571571
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %transferRawPointer(%5a) : $@convention(thin) @async (Builtin.RawPointer) -> ()
572-
// expected-warning @-1 {{transferring value of non-Sendable type 'Builtin.RawPointer' from nonisolated context to global actor '<null>'-isolated context; later accesses could race}}
572+
// expected-warning @-1 {{transferring value of non-Sendable type 'Builtin.RawPointer' from nonisolated context to global actor '<null>'-isolated context}}
573573

574574
%useRawPointer = function_ref @useRawPointer : $@convention(thin) (Builtin.RawPointer) -> ()
575575
apply %useRawPointer(%3a) : $@convention(thin) (Builtin.RawPointer) -> ()

test/Concurrency/transfernonsendable_instruction_matching_opaquevalues.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ bb0(%owned_value : @owned $T):
8181
%unowned_value = unowned_copy_value %owned_value : $T
8282

8383
%4 = function_ref @transferIndirect : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> ()
84-
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %4<@sil_unowned T>(%unowned_value) : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> () // expected-warning {{call site passes `self` or a non-sendable argument of this function to another thread, potentially yielding a race with the caller}}
84+
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %4<@sil_unowned T>(%unowned_value) : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> () // expected-warning {{task isolated value of type 'T' transferred to global actor '<null>'-isolated context}}
8585

8686
destroy_value %unowned_value : $@sil_unowned T
8787
//destroy_value %value : $T

0 commit comments

Comments
 (0)