Skip to content

Commit 44052e5

Browse files
committed
[rbi] Respect nonisolated(unsafe) when assigning or merging into a sending out parameter.
rdar://143714959
1 parent 468371f commit 44052e5

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

include/swift/SILOptimizer/Utils/PartitionUtils.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,12 +1323,16 @@ struct PartitionOpEvaluator {
13231323
if (auto value = instance.maybeGetValue()) {
13241324
if (auto *fArg = dyn_cast<SILFunctionArgument>(value)) {
13251325
if (fArg->getArgumentConvention().isIndirectOutParameter()) {
1326+
auto staticRegionIsolation =
1327+
getIsolationRegionInfo(op.getOpArgs()[1]);
13261328
Region srcRegion = p.getRegion(op.getOpArgs()[1]);
13271329
auto dynamicRegionIsolation = getIsolationRegionInfo(srcRegion);
1330+
13281331
// We can unconditionally getValue here since we can never
13291332
// assign an actor introducing inst.
13301333
auto rep = getRepresentativeValue(op.getOpArgs()[1]).getValue();
1331-
if (!dynamicRegionIsolation.isDisconnected()) {
1334+
if (!dynamicRegionIsolation.isDisconnected() &&
1335+
!staticRegionIsolation.isUnsafeNonIsolated()) {
13321336
handleError(AssignNeverSendableIntoSendingResultError(
13331337
op, op.getOpArgs()[0], fArg, op.getOpArgs()[1], rep,
13341338
dynamicRegionIsolation));
@@ -1451,12 +1455,15 @@ struct PartitionOpEvaluator {
14511455
if (auto value = instance.maybeGetValue()) {
14521456
if (auto *fArg = dyn_cast<SILFunctionArgument>(value)) {
14531457
if (fArg->getArgumentConvention().isIndirectOutParameter()) {
1458+
auto staticRegionIsolation =
1459+
getIsolationRegionInfo(op.getOpArgs()[1]);
14541460
Region srcRegion = p.getRegion(op.getOpArgs()[1]);
14551461
auto dynamicRegionIsolation = getIsolationRegionInfo(srcRegion);
14561462
// We can unconditionally getValue here since we can never
14571463
// assign an actor introducing inst.
14581464
auto rep = getRepresentativeValue(op.getOpArgs()[1]).getValue();
1459-
if (!dynamicRegionIsolation.isDisconnected()) {
1465+
if (!dynamicRegionIsolation.isDisconnected() &&
1466+
!staticRegionIsolation.isUnsafeNonIsolated()) {
14601467
handleError(AssignNeverSendableIntoSendingResultError(
14611468
op, op.getOpArgs()[0], fArg, op.getOpArgs()[1], rep,
14621469
dynamicRegionIsolation));

test/Concurrency/transfernonsendable.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,3 +1944,14 @@ func testFunctionIsNotEmpty(input: SendableKlass) async throws {
19441944
}
19451945
}
19461946
}
1947+
1948+
func unsafeNonIsolatedAppliesToAssignToOutParam(ns: NonSendableKlass) -> sending NonSendableKlass {
1949+
func withUnsafeValue<T>(_ block: (NonSendableKlass) throws -> sending T) rethrows -> sending T {
1950+
fatalError()
1951+
}
1952+
1953+
return withUnsafeValue {
1954+
nonisolated(unsafe) let obj = $0
1955+
return obj
1956+
}
1957+
}

0 commit comments

Comments
 (0)