Skip to content

Commit ebedf63

Browse files
committed
[region-isolation] Do not squelch use-after-transfer error even if the value is isolated to the same actor.
rdar://132074953
1 parent 3aee7da commit ebedf63

File tree

6 files changed

+24
-30
lines changed

6 files changed

+24
-30
lines changed

include/swift/SILOptimizer/Utils/PartitionUtils.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,13 +1375,6 @@ struct PartitionOpEvaluator {
13751375
void handleLocalUseAfterTransferHelper(const PartitionOp &op, Element elt,
13761376
Operand *transferringOp) const {
13771377
if (shouldTryToSquelchErrors()) {
1378-
if (auto isolationInfo = getIsolationInfo(op)) {
1379-
if (isolationInfo.isActorIsolated() &&
1380-
isolationInfo.hasSameIsolation(
1381-
SILIsolationInfo::get(transferringOp->getUser())))
1382-
return;
1383-
}
1384-
13851378
if (SILValue equivalenceClassRep =
13861379
getRepresentative(transferringOp->get())) {
13871380

test/Concurrency/concurrent_value_checking.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// REQUIRES: asserts
77

88
class NotConcurrent { } // expected-note 13{{class 'NotConcurrent' does not conform to the 'Sendable' protocol}}
9-
// expected-tns-allow-typechecker-note @-2 {{class 'NotConcurrent' does not conform to the 'Sendable' protocol}}
9+
// expected-tns-allow-typechecker-note @-1 {{class 'NotConcurrent' does not conform to the 'Sendable' protocol}}
1010

1111
// ----------------------------------------------------------------------
1212
// Sendable restriction on actor operations
@@ -141,8 +141,9 @@ func globalTest() async {
141141
// expected-warning@+2 {{expression is 'async' but is not marked with 'await'}}
142142
// expected-note@+1 {{property access is 'async'}}
143143
let a = globalValue // expected-warning{{non-sendable type 'NotConcurrent?' in implicitly asynchronous access to global actor 'SomeGlobalActor'-isolated let 'globalValue' cannot cross actor boundary}}
144-
await globalAsync(a)
145-
await globalSync(a)
144+
await globalAsync(a) // expected-tns-warning {{sending 'a' risks causing data races}}
145+
// expected-tns-note @-1 {{sending global actor 'SomeGlobalActor'-isolated 'a' to global actor 'SomeGlobalActor'-isolated global function 'globalAsync' risks causing data races between global actor 'SomeGlobalActor'-isolated and local nonisolated uses}}
146+
await globalSync(a) // expected-tns-note {{access can happen concurrently}}
146147

147148
// expected-warning@+2 {{expression is 'async' but is not marked with 'await'}}
148149
// expected-note@+1 {{property access is 'async'}}
@@ -177,8 +178,9 @@ func globalTestMain(nc: NotConcurrent) async {
177178
// expected-warning@+2 {{expression is 'async' but is not marked with 'await'}}
178179
// expected-note@+1 {{property access is 'async'}}
179180
let a = globalValue // expected-warning {{non-sendable type 'NotConcurrent?' in implicitly asynchronous access to global actor 'SomeGlobalActor'-isolated let 'globalValue' cannot cross actor boundary}}
180-
await globalAsync(a)
181-
await globalSync(a)
181+
await globalAsync(a) // expected-tns-warning {{sending 'a' risks causing data races}}
182+
// expected-tns-note @-1 {{sending global actor 'SomeGlobalActor'-isolated 'a' to global actor 'SomeGlobalActor'-isolated global function 'globalAsync' risks causing data races between global actor 'SomeGlobalActor'-isolated and local main actor-isolated uses}}
183+
await globalSync(a) // expected-tns-note {{access can happen concurrently}}
182184
_ = await ClassWithGlobalActorInits(nc)
183185
// expected-warning @-1 {{non-sendable type 'ClassWithGlobalActorInits' returned by call to global actor 'SomeGlobalActor'-isolated function cannot cross actor boundary}}
184186
// expected-tns-warning @-2 {{sending 'nc' risks causing data races}}

test/Concurrency/sendable_checking.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,12 @@ func testNonSendableBaseArg() async {
295295
let t = NonSendable()
296296
await t.update()
297297
// expected-targeted-and-complete-warning @-1 {{passing argument of non-sendable type 'NonSendable' into main actor-isolated context may introduce data races}}
298+
// expected-tns-warning @-2 {{sending 't' risks causing data races}}
299+
// expected-tns-note @-3 {{sending 't' to main actor-isolated instance method 'update()' risks causing data races between main actor-isolated and local nonisolated uses}}
298300

299301
_ = await t.x
300302
// expected-warning @-1 {{non-sendable type 'NonSendable' passed in implicitly asynchronous call to main actor-isolated property 'x' cannot cross actor boundary}}
303+
// expected-tns-note @-2 {{access can happen concurrently}}
301304
}
302305

303306
// We get the region isolation error here since t.y is custom actor isolated.

test/Concurrency/transfernonsendable.swift

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,7 @@ func closureInOut(_ a: MyActor) async {
151151
// expected-tns-note @-3 {{sending 'ns0' to actor-isolated instance method 'useKlass' risks causing data races between actor-isolated and local nonisolated uses}}
152152

153153
if await booleanFlag {
154-
// This is not an actual use since we are passing values to the same
155-
// isolation domain.
156-
await a.useKlass(ns1)
157-
// expected-complete-warning @-1 {{passing argument of non-sendable type 'NonSendableKlass'}}
154+
await a.useKlass(ns1) // expected-tns-note {{access can happen concurrently}}
158155
} else {
159156
closure() // expected-tns-note {{access can happen concurrently}}
160157
}
@@ -1230,11 +1227,11 @@ func varNonSendableNonTrivialLetStructFieldClosureFlowSensitive4() async {
12301227
// good... that is QoI though.
12311228
await transferToMain(test) // expected-tns-warning {{sending 'test' risks causing data races}}
12321229
// expected-tns-note @-1 {{sending 'test' to main actor-isolated global function 'transferToMain' risks causing data races between main actor-isolated and local nonisolated uses}}
1233-
// expected-complete-warning @-2 {{passing argument of non-sendable type 'StructFieldTests' into main actor-isolated context may introduce data races}}
1230+
// expected-tns-note @-2 {{access can happen concurrently}}
12341231

12351232
// This is treated as a use since test is in box form and is mutable. So we
12361233
// treat assignment as a merge.
1237-
test = StructFieldTests() // expected-tns-note {{access can happen concurrently}}
1234+
test = StructFieldTests()
12381235
cls = {
12391236
useInOut(&test.varSendableNonTrivial)
12401237
}
@@ -1265,7 +1262,7 @@ func varNonSendableNonTrivialLetStructFieldClosureFlowSensitive5() async {
12651262
}
12661263

12671264
test.varSendableNonTrivial = SendableKlass()
1268-
useValue(test) // expected-tns-note {{access can happen concurrently}}
1265+
useValue(test)
12691266
}
12701267

12711268
func varNonSendableNonTrivialLetStructFieldClosureFlowSensitive6() async {
@@ -1434,7 +1431,7 @@ func controlFlowTest2() async {
14341431
x = NonSendableKlass()
14351432
}
14361433

1437-
useValue(x) // expected-tns-note {{access can happen concurrently}}
1434+
useValue(x)
14381435
}
14391436

14401437
////////////////////////
@@ -1750,8 +1747,9 @@ func sendableGlobalActorIsolated() {
17501747
// value.
17511748
func testIndirectParameterSameIsolationNoError() async {
17521749
let x = NonSendableKlass()
1753-
await transferToMain(x) // expected-complete-warning {{passing argument of non-sendable type 'NonSendableKlass' into main actor-isolated context may introduce data races}}
1754-
await transferToMain(x) // expected-complete-warning {{passing argument of non-sendable type 'NonSendableKlass' into main actor-isolated context may introduce data races}}
1750+
await transferToMain(x) // expected-tns-warning {{sending 'x' risks causing data races}}
1751+
// expected-tns-note @-1 {{sending 'x' to main actor-isolated global function 'transferToMain' risks causing data races between main actor-isolated and local nonisolated uses}}
1752+
await transferToMain(x) // expected-tns-note {{access can happen concurrently}}
17551753
}
17561754

17571755
extension MyActor {

test/Concurrency/transfernonsendable_asynclet.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,13 +293,13 @@ func asyncLet_Let_ActorIsolated_CallBuriedInOtherExpr3() async {
293293
let _ = await y
294294
}
295295

296-
// Make sure that we do not emit an error for transferToMainInt in the async val
297-
// function itself since we are sending the value to the same main actor
298-
// isolated use and transferring it into one async let variable.
299296
func asyncLet_Let_ActorIsolated_CallBuriedInOtherExpr4() async {
300297
let x = NonSendableKlass()
301298

302299
async let y = useValue(transferToMainInt(x) + transferToMainInt(x))
300+
// expected-warning @-1:26 {{sending 'x' risks causing data races}}
301+
// expected-note @-2:26 {{sending 'x' to main actor-isolated global function 'transferToMainInt' risks causing data races between main actor-isolated and local nonisolated uses}}
302+
// expected-note @-3:49 {{access can happen concurrently}}
303303

304304
let _ = await y
305305
}

test/Concurrency/transfernonsendable_instruction_matching.sil

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -645,14 +645,12 @@ bb0:
645645

646646
fix_lifetime %value : $SendableKlass
647647

648-
// This is not considered a bad use of the raw pointer since this is
649-
// sending to the same isolation domain.
650648
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %transferRawPointer(%rawPointer) : $@convention(thin) @async (Builtin.RawPointer) -> ()
651649
// expected-warning @-1 {{}}
650+
// expected-note @-2 {{access can happen concurrently}}
652651

653652
fix_lifetime %rawPointer : $Builtin.RawPointer
654653
// expected-note @-1 {{access can happen concurrently}}
655-
// expected-note @-2 {{access can happen concurrently}}
656654

657655
destroy_value %value : $SendableKlass
658656
%9999 = tuple ()
@@ -725,10 +723,10 @@ bb0:
725723

726724
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %transferRawPointer(%rawPointer) : $@convention(thin) @async (Builtin.RawPointer) -> ()
727725
// expected-warning @-1 {{}}
726+
// expected-note @-2 {{access can happen concurrently}}
728727

729728
fix_lifetime %rawPointer : $Builtin.RawPointer
730729
// expected-note @-1 {{access can happen concurrently}}
731-
// expected-note @-2 {{access can happen concurrently}}
732730

733731
destroy_value %value : $SendableKlass
734732
%9999 = tuple ()
@@ -804,10 +802,10 @@ bb0:
804802

805803
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %transferRawPointer(%rawPointer) : $@convention(thin) @async (Builtin.RawPointer) -> ()
806804
// expected-warning @-1 {{}}
805+
// expected-note @-2 {{access can happen concurrently}}
807806

808807
fix_lifetime %rawPointer : $Builtin.RawPointer
809808
// expected-note @-1 {{access can happen concurrently}}
810-
// expected-note @-2 {{access can happen concurrently}}
811809

812810
end_borrow %valueB : $SendableKlass
813811
destroy_value %value : $SendableKlass

0 commit comments

Comments
 (0)