Skip to content

Commit da6ffaa

Browse files
committed
[region-isolation] When printing a SILIsolationInfo description for diagnostics, if we have a SIL actor instance, print -isolated instead of actor-isolated.
rdar://122501400
1 parent 407103a commit da6ffaa

File tree

4 files changed

+26
-19
lines changed

4 files changed

+26
-19
lines changed

lib/SILOptimizer/Analysis/RegionAnalysis.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "swift/SIL/Test.h"
3737
#include "swift/SILOptimizer/PassManager/Transforms.h"
3838
#include "swift/SILOptimizer/Utils/PartitionUtils.h"
39+
#include "swift/SILOptimizer/Utils/VariableNameUtils.h"
3940
#include "llvm/ADT/DenseMap.h"
4041
#include "llvm/Support/Debug.h"
4142

@@ -615,6 +616,12 @@ void SILIsolationInfo::printForDiagnostics(llvm::raw_ostream &os) const {
615616
os << "disconnected";
616617
return;
617618
case Actor:
619+
if (SILValue instance = getActorInstance()) {
620+
if (auto name = VariableNameInferrer::inferName(instance)) {
621+
os << "'" << *name << "'-isolated";
622+
return;
623+
}
624+
}
618625
getActorIsolation().printForDiagnostics(os);
619626
return;
620627
case Task:

test/Concurrency/transfernonsendable.sil

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ bb0(%0 : @guaranteed $MyActor):
292292
%3 = class_method %0 : $MyActor, #MyActor.klass!getter : (isolated MyActor) -> () -> NonSendableKlass, $@convention(method) (@sil_isolated @guaranteed MyActor) -> @owned NonSendableKlass
293293
%4 = apply %3(%0) : $@convention(method) (@sil_isolated @guaranteed MyActor) -> @owned NonSendableKlass
294294
%5 = class_method %4 : $NonSendableKlass, #NonSendableKlass.asyncCall : (NonSendableKlass) -> () async -> (), $@convention(method) @async (@guaranteed NonSendableKlass) -> ()
295-
%6 = apply [caller_isolation=nonisolated] [callee_isolation=actor_instance] %5(%4) : $@convention(method) @async (@guaranteed NonSendableKlass) -> () // expected-warning {{actor-isolated value of type 'NonSendableKlass' transferred to actor-isolated context; later accesses to value could race}}
295+
%6 = apply [caller_isolation=nonisolated] [callee_isolation=actor_instance] %5(%4) : $@convention(method) @async (@guaranteed NonSendableKlass) -> () // expected-warning {{'self'-isolated value of type 'NonSendableKlass' transferred to actor-isolated context; later accesses to value could race}}
296296
destroy_value %4 : $NonSendableKlass
297297
hop_to_executor %0 : $MyActor
298298
%9 = tuple ()
@@ -313,7 +313,7 @@ bb0(%0 : @guaranteed $MyActor):
313313
%11 = alloc_stack $NonSendableKlass
314314
%12 = store_borrow %6 to %11 : $*NonSendableKlass
315315
%13 = function_ref @transferIndirect : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> ()
316-
%14 = apply [caller_isolation=actor_instance] [callee_isolation=global_actor] %13<NonSendableKlass>(%12) : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> () // expected-warning {{actor-isolated value of type 'NonSendableKlass' transferred to global actor '<null>'-isolated context}}
316+
%14 = apply [caller_isolation=actor_instance] [callee_isolation=global_actor] %13<NonSendableKlass>(%12) : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> () // expected-warning {{'self'-isolated value of type 'NonSendableKlass' transferred to global actor '<null>'-isolated context}}
317317
end_borrow %12 : $*NonSendableKlass
318318
dealloc_stack %11 : $*NonSendableKlass
319319
hop_to_executor %0 : $MyActor

test/Concurrency/transfernonsendable.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ extension Actor {
8383
func warningIfCallingGetter() async {
8484
await self.klass.asyncCall() // expected-complete-warning {{passing argument of non-sendable type 'NonSendableKlass' outside of actor-isolated context may introduce data races}}
8585
// expected-tns-warning @-1 {{transferring 'self.klass' may cause a data race}}
86-
// expected-tns-note @-2 {{transferring actor-isolated 'self.klass' to nonisolated callee could cause races between nonisolated and actor-isolated uses}}
86+
// expected-tns-note @-2 {{transferring 'self'-isolated 'self.klass' to nonisolated callee could cause races between nonisolated and 'self'-isolated uses}}
8787
}
8888

8989
func warningIfCallingAsyncOnFinalField() async {
9090
// Since we are calling finalKlass directly, we emit a warning here.
9191
await self.finalKlass.asyncCall() // expected-complete-warning {{passing argument of non-sendable type 'NonSendableKlass' outside of actor-isolated context may introduce data races}}
9292
// expected-tns-warning @-1 {{transferring 'self.finalKlass' may cause a data race}}
93-
// expected-tns-note @-2 {{transferring actor-isolated 'self.finalKlass' to nonisolated callee could cause races between nonisolated and actor-isolated uses}}
93+
// expected-tns-note @-2 {{transferring 'self'-isolated 'self.finalKlass' to nonisolated callee could cause races between nonisolated and 'self'-isolated uses}}
9494
}
9595

9696
// We do not warn on this since we warn in the caller of our getter instead.
@@ -104,7 +104,7 @@ extension FinalActor {
104104
// Since our whole class is final, we emit the error directly here.
105105
await self.klass.asyncCall() // expected-complete-warning {{passing argument of non-sendable type 'NonSendableKlass' outside of actor-isolated context may introduce data races}}
106106
// expected-tns-warning @-1 {{transferring 'self.klass' may cause a data race}}
107-
// expected-tns-note @-2 {{transferring actor-isolated 'self.klass' to nonisolated callee could cause races between nonisolated and actor-isolated uses}}
107+
// expected-tns-note @-2 {{transferring 'self'-isolated 'self.klass' to nonisolated callee could cause races between nonisolated and 'self'-isolated uses}}
108108
}
109109
}
110110

@@ -401,7 +401,7 @@ extension Actor {
401401
await transferToMain(closure) // expected-complete-warning {{passing argument of non-sendable type '() -> ()' into main actor-isolated context may introduce data races}}
402402
// expected-complete-note @-1 {{a function type must be marked '@Sendable' to conform to 'Sendable'}}
403403
// expected-tns-warning @-2 {{transferring 'closure' may cause a data race}}
404-
// expected-tns-note @-3 {{transferring actor-isolated 'closure' to main actor-isolated callee could cause races between main actor-isolated and actor-isolated uses}}
404+
// expected-tns-note @-3 {{transferring 'self'-isolated 'closure' to main actor-isolated callee could cause races between main actor-isolated and 'self'-isolated uses}}
405405
}
406406

407407
func simpleClosureCaptureSelfThroughTuple2() async {
@@ -412,7 +412,7 @@ extension Actor {
412412
await transferToMain(closure) // expected-complete-warning {{passing argument of non-sendable type '() -> ()' into main actor-isolated context may introduce data races}}
413413
// expected-complete-note @-1 {{a function type must be marked '@Sendable' to conform to 'Sendable'}}
414414
// expected-tns-warning @-2 {{transferring 'closure' may cause a data race}}
415-
// expected-tns-note @-3 {{transferring actor-isolated 'closure' to main actor-isolated callee could cause races between main actor-isolated and actor-isolated uses}}
415+
// expected-tns-note @-3 {{transferring 'self'-isolated 'closure' to main actor-isolated callee could cause races between main actor-isolated and 'self'-isolated uses}}
416416
}
417417

418418
func simpleClosureCaptureSelfThroughOptional() async {
@@ -423,7 +423,7 @@ extension Actor {
423423
await transferToMain(closure) // expected-complete-warning {{passing argument of non-sendable type '() -> ()' into main actor-isolated context may introduce data races}}
424424
// expected-complete-note @-1 {{a function type must be marked '@Sendable' to conform to 'Sendable'}}
425425
// expected-tns-warning @-2 {{transferring 'closure' may cause a data race}}
426-
// expected-tns-note @-3 {{transferring actor-isolated 'closure' to main actor-isolated callee could cause races between main actor-isolated and actor-isolated uses}}
426+
// expected-tns-note @-3 {{transferring 'self'-isolated 'closure' to main actor-isolated callee could cause races between main actor-isolated and 'self'-isolated uses}}
427427
}
428428
}
429429

@@ -512,7 +512,7 @@ extension Actor {
512512
await transferToMain(closure) // expected-complete-warning {{passing argument of non-sendable type '() -> ()' into main actor-isolated context may introduce data races}}
513513
// expected-complete-note @-1 {{a function type must be marked '@Sendable' to conform to 'Sendable'}}
514514
// expected-tns-warning @-2 {{transferring 'closure' may cause a data race}}
515-
// expected-tns-note @-3 {{transferring actor-isolated 'closure' to main actor-isolated callee could cause races between main actor-isolated and actor-isolated uses}}
515+
// expected-tns-note @-3 {{transferring 'self'-isolated 'closure' to main actor-isolated callee could cause races between main actor-isolated and 'self'-isolated uses}}
516516
}
517517

518518
// Make sure that we properly propagate actor derived from klass into field's
@@ -525,7 +525,7 @@ extension Actor {
525525
await transferToMain(closure) // expected-complete-warning {{passing argument of non-sendable type '() -> ()' into main actor-isolated context may introduce data races}}
526526
// expected-complete-note @-1 {{a function type must be marked '@Sendable' to conform to 'Sendable'}}
527527
// expected-tns-warning @-2 {{transferring 'closure' may cause a data race}}
528-
// expected-tns-note @-3 {{transferring actor-isolated 'closure' to main actor-isolated callee could cause races between main actor-isolated and actor-isolated uses}}
528+
// expected-tns-note @-3 {{transferring 'self'-isolated 'closure' to main actor-isolated callee could cause races between main actor-isolated and 'self'-isolated uses}}
529529
}
530530
}
531531

@@ -1439,23 +1439,23 @@ actor ActorWithSetter {
14391439
let x = NonSendableKlass()
14401440
self.field = x
14411441
await transferToMain(x) // expected-tns-warning {{transferring 'x' may cause a data race}}
1442-
// expected-tns-note @-1 {{transferring actor-isolated 'x' to main actor-isolated callee could cause races between main actor-isolated and actor-isolated uses}}
1442+
// expected-tns-note @-1 {{transferring 'self'-isolated 'x' to main actor-isolated callee could cause races between main actor-isolated and 'self'-isolated uses}}
14431443
// expected-complete-warning @-2 {{passing argument of non-sendable type 'NonSendableKlass' into main actor-isolated context may introduce data races}}
14441444
}
14451445

14461446
func test2() async {
14471447
let x = NonSendableKlass()
14481448
self.twoFieldBox.k1 = x
14491449
await transferToMain(x) // expected-tns-warning {{transferring 'x' may cause a data race}}
1450-
// expected-tns-note @-1 {{transferring actor-isolated 'x' to main actor-isolated callee could cause races between main actor-isolated and actor-isolated uses}}
1450+
// expected-tns-note @-1 {{transferring 'self'-isolated 'x' to main actor-isolated callee could cause races between main actor-isolated and 'self'-isolated uses}}
14511451
// expected-complete-warning @-2 {{passing argument of non-sendable type 'NonSendableKlass' into main actor-isolated context may introduce data races}}
14521452
}
14531453

14541454
func test3() async {
14551455
let x = NonSendableKlass()
14561456
self.twoFieldBoxInTuple.1.k1 = x
14571457
await transferToMain(x) // expected-tns-warning {{transferring 'x' may cause a data race}}
1458-
// expected-tns-note @-1 {{transferring actor-isolated 'x' to main actor-isolated callee could cause races between main actor-isolated and actor-isolated uses}}
1458+
// expected-tns-note @-1 {{transferring 'self'-isolated 'x' to main actor-isolated callee could cause races between main actor-isolated and 'self'-isolated uses}}
14591459
// expected-complete-warning @-2 {{passing argument of non-sendable type 'NonSendableKlass' into main actor-isolated context may introduce data races}}
14601460
}
14611461

@@ -1476,7 +1476,7 @@ actor ActorWithSetter {
14761476
let x = NonSendableKlass()
14771477
self.classBox.k1 = x
14781478
await transferToMain(x) // expected-tns-warning {{transferring 'x' may cause a data race}}
1479-
// expected-tns-note @-1 {{transferring actor-isolated 'x' to main actor-isolated callee could cause races between main actor-isolated and actor-isolated uses}}
1479+
// expected-tns-note @-1 {{transferring 'self'-isolated 'x' to main actor-isolated callee could cause races between main actor-isolated and 'self'-isolated uses}}
14801480
// expected-complete-warning @-2 {{passing argument of non-sendable type 'NonSendableKlass' into main actor-isolated context may introduce data races}}
14811481
}
14821482
}
@@ -1492,23 +1492,23 @@ final actor FinalActorWithSetter {
14921492
let x = NonSendableKlass()
14931493
self.field = x
14941494
await transferToMain(x) // expected-tns-warning {{transferring 'x' may cause a data race}}
1495-
// expected-tns-note @-1 {{transferring actor-isolated 'x' to main actor-isolated callee could cause races between main actor-isolated and actor-isolated uses}}
1495+
// expected-tns-note @-1 {{transferring 'self'-isolated 'x' to main actor-isolated callee could cause races between main actor-isolated and 'self'-isolated uses}}
14961496
// expected-complete-warning @-2 {{passing argument of non-sendable type 'NonSendableKlass' into main actor-isolated context may introduce data races}}
14971497
}
14981498

14991499
func test2() async {
15001500
let x = NonSendableKlass()
15011501
self.twoFieldBox.k1 = x
15021502
await transferToMain(x) // expected-tns-warning {{transferring 'x' may cause a data race}}
1503-
// expected-tns-note @-1 {{transferring actor-isolated 'x' to main actor-isolated callee could cause races between main actor-isolated and actor-isolated uses}}
1503+
// expected-tns-note @-1 {{transferring 'self'-isolated 'x' to main actor-isolated callee could cause races between main actor-isolated and 'self'-isolated uses}}
15041504
// expected-complete-warning @-2 {{passing argument of non-sendable type 'NonSendableKlass' into main actor-isolated context may introduce data races}}
15051505
}
15061506

15071507
func test3() async {
15081508
let x = NonSendableKlass()
15091509
self.twoFieldBoxInTuple.1.k1 = x
15101510
await transferToMain(x) // expected-tns-warning {{transferring 'x' may cause a data race}}
1511-
// expected-tns-note @-1 {{transferring actor-isolated 'x' to main actor-isolated callee could cause races between main actor-isolated and actor-isolated uses}}
1511+
// expected-tns-note @-1 {{transferring 'self'-isolated 'x' to main actor-isolated callee could cause races between main actor-isolated and 'self'-isolated uses}}
15121512
// expected-complete-warning @-2 {{passing argument of non-sendable type 'NonSendableKlass' into main actor-isolated context may introduce data races}}
15131513
}
15141514

@@ -1529,7 +1529,7 @@ final actor FinalActorWithSetter {
15291529
let x = NonSendableKlass()
15301530
self.classBox.k1 = x
15311531
await transferToMain(x) // expected-tns-warning {{transferring 'x' may cause a data race}}
1532-
// expected-tns-note @-1 {{transferring actor-isolated 'x' to main actor-isolated callee could cause races between main actor-isolated and actor-isolated uses}}
1532+
// expected-tns-note @-1 {{transferring 'self'-isolated 'x' to main actor-isolated callee could cause races between main actor-isolated and 'self'-isolated uses}}
15331533
// expected-complete-warning @-2 {{passing argument of non-sendable type 'NonSendableKlass' into main actor-isolated context may introduce data races}}
15341534
}
15351535
}

test/Concurrency/transfernonsendable_strong_transferring_params.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ actor MyActor {
160160
func assignTransferringIntoActor2(_ x: transferring Klass) async {
161161
field = x
162162
await transferToMain(x) // expected-warning {{transferring 'x' may cause a data race}}
163-
// expected-note @-1 {{transferring actor-isolated 'x' to main actor-isolated callee could cause races between main actor-isolated and actor-isolated uses}}
163+
// expected-note @-1 {{transferring 'self'-isolated 'x' to main actor-isolated callee could cause races between main actor-isolated and 'self'-isolated uses}}
164164
}
165165
}
166166

0 commit comments

Comments
 (0)