Skip to content

Commit 7d82d72

Browse files
authored
Merge pull request #81909 from gottesmm/pr-775f782ff711827a2a0dce73a522b6eb9bc2d484
[rbi] Lookthrough an invocation of DistributedActor.asLocalActor when determining actor instances.
2 parents 6e91fa8 + 331626e commit 7d82d72

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

lib/SILOptimizer/Utils/SILIsolationInfo.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "swift/SILOptimizer/Utils/SILIsolationInfo.h"
1414

1515
#include "swift/AST/ASTWalker.h"
16+
#include "swift/AST/DistributedDecl.h"
1617
#include "swift/AST/Expr.h"
1718
#include "swift/SIL/AddressWalker.h"
1819
#include "swift/SIL/ApplySite.h"
@@ -1417,6 +1418,30 @@ SILValue ActorInstance::lookThroughInsts(SILValue value) {
14171418
}
14181419
}
14191420

1421+
// See if this is distributed asLocalActor. In such a case, we want to
1422+
// consider the result actor to be the same actor as the input isolated
1423+
// parameter.
1424+
if (auto fas = FullApplySite::isa(svi)) {
1425+
if (auto *functionRef = fas.getReferencedFunctionOrNull()) {
1426+
if (auto declRef = functionRef->getDeclRef()) {
1427+
if (auto *accessor =
1428+
dyn_cast_or_null<AccessorDecl>(declRef.getFuncDecl())) {
1429+
if (auto asLocalActorDecl =
1430+
getDistributedActorAsLocalActorComputedProperty(
1431+
functionRef->getDeclContext()->getParentModule())) {
1432+
if (auto asLocalActorGetter =
1433+
asLocalActorDecl->getAccessor(AccessorKind::Get);
1434+
asLocalActorGetter && asLocalActorGetter == accessor) {
1435+
value = lookThroughInsts(
1436+
fas.getIsolatedArgumentOperandOrNullPtr()->get());
1437+
continue;
1438+
}
1439+
}
1440+
}
1441+
}
1442+
}
1443+
}
1444+
14201445
break;
14211446
}
14221447

test/Distributed/distributed_actor_transfernonsendable.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,19 @@ distributed actor MyDistributedActor {
6565
// expected-note @-1 {{'self'-isolated 'x' is captured by a main actor-isolated closure. main actor-isolated uses in closure may race against later nonisolated uses}}
6666
}
6767
}
68+
69+
70+
func doSomething() async { }
71+
72+
// Make sure that we consider asLocalActor's result to be the same actor as
73+
// its actor parameter.
74+
func testAsLocalActorForwards() async {
75+
await withTaskGroup { group in
76+
group.addTask {
77+
await self.doSomething()
78+
}
79+
}
80+
}
6881
}
6982

7083
/////////////////////////////////

0 commit comments

Comments
 (0)