Skip to content

Commit 2026f39

Browse files
committed
[region-isolation] Do not squelch use-after-transfer error even if the value is isolated to the same actor.
rdar://132074953 (cherry picked from commit ebedf63)
1 parent 452333f commit 2026f39

File tree

6 files changed

+32
-38
lines changed

6 files changed

+32
-38
lines changed

include/swift/SILOptimizer/Utils/PartitionUtils.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,13 +1248,6 @@ struct PartitionOpEvaluator {
12481248
void handleLocalUseAfterTransferHelper(const PartitionOp &op, Element elt,
12491249
Operand *transferringOp) const {
12501250
if (shouldTryToSquelchErrors()) {
1251-
if (auto isolationInfo = getIsolationInfo(op)) {
1252-
if (isolationInfo.isActorIsolated() &&
1253-
isolationInfo.hasSameIsolation(
1254-
SILIsolationInfo::get(transferringOp->getUser())))
1255-
return;
1256-
}
1257-
12581251
if (SILValue equivalenceClassRep =
12591252
getRepresentative(transferringOp->get())) {
12601253

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: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,7 @@ func closureInOut(_ a: MyActor) async {
145145
// expected-tns-note @-3 {{sending 'ns0' to actor-isolated instance method 'useKlass' risks causing data races between actor-isolated and local nonisolated uses}}
146146

147147
if await booleanFlag {
148-
// This is not an actual use since we are passing values to the same
149-
// isolation domain.
150-
await a.useKlass(ns1)
151-
// expected-complete-warning @-1 {{passing argument of non-sendable type 'NonSendableKlass'}}
148+
await a.useKlass(ns1) // expected-tns-note {{access can happen concurrently}}
152149
} else {
153150
closure() // expected-tns-note {{access can happen concurrently}}
154151
}
@@ -1224,11 +1221,11 @@ func varNonSendableNonTrivialLetStructFieldClosureFlowSensitive4() async {
12241221
// good... that is QoI though.
12251222
await transferToMain(test) // expected-tns-warning {{sending 'test' risks causing data races}}
12261223
// 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}}
1227-
// expected-complete-warning @-2 {{passing argument of non-sendable type 'StructFieldTests' into main actor-isolated context may introduce data races}}
1224+
// expected-tns-note @-2 {{access can happen concurrently}}
12281225

12291226
// This is treated as a use since test is in box form and is mutable. So we
12301227
// treat assignment as a merge.
1231-
test = StructFieldTests() // expected-tns-note {{access can happen concurrently}}
1228+
test = StructFieldTests()
12321229
cls = {
12331230
useInOut(&test.varSendableNonTrivial)
12341231
}
@@ -1259,7 +1256,7 @@ func varNonSendableNonTrivialLetStructFieldClosureFlowSensitive5() async {
12591256
}
12601257

12611258
test.varSendableNonTrivial = SendableKlass()
1262-
useValue(test) // expected-tns-note {{access can happen concurrently}}
1259+
useValue(test)
12631260
}
12641261

12651262
func varNonSendableNonTrivialLetStructFieldClosureFlowSensitive6() async {
@@ -1428,7 +1425,7 @@ func controlFlowTest2() async {
14281425
x = NonSendableKlass()
14291426
}
14301427

1431-
useValue(x) // expected-tns-note {{access can happen concurrently}}
1428+
useValue(x)
14321429
}
14331430

14341431
////////////////////////
@@ -1738,6 +1735,17 @@ func sendableGlobalActorIsolated() {
17381735
print(x) // expected-tns-note {{access can happen concurrently}}
17391736
}
17401737

1738+
// We do not get an error here since we are transferring x both times to a main
1739+
// actor isolated thing function. We used to emit an error when using region
1740+
// isolation since we would trip on the store_borrow we used to materialize the
1741+
// value.
1742+
func testIndirectParameterSameIsolationNoError() async {
1743+
let x = NonSendableKlass()
1744+
await transferToMain(x) // expected-tns-warning {{sending 'x' risks causing data races}}
1745+
// 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}}
1746+
await transferToMain(x) // expected-tns-note {{access can happen concurrently}}
1747+
}
1748+
17411749
extension MyActor {
17421750
func testNonSendableCaptures(sc: NonSendableKlass) {
17431751
Task {
@@ -1825,13 +1833,3 @@ func testBooleanCapture(_ x: inout NonSendableKlass) {
18251833
print(z)
18261834
}
18271835
}
1828-
1829-
// We do not get an error here since we are transferring x both times to a main
1830-
// actor isolated thing function. We used to emit an error when using region
1831-
// isolation since we would trip on the store_borrow we used to materialize the
1832-
// value.
1833-
func testIndirectParameterSameIsolationNoError() async {
1834-
let x = NonSendableKlass()
1835-
await transferToMain(x) // expected-complete-warning {{passing argument of non-sendable type 'NonSendableKlass' into main actor-isolated context may introduce data races}}
1836-
await transferToMain(x) // expected-complete-warning {{passing argument of non-sendable type 'NonSendableKlass' into main actor-isolated context may introduce data races}}
1837-
}

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)