Skip to content

[rbi] Lookthrough an invocation of DistributedActor.asLocalActor when determining actor instances. #81909

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions lib/SILOptimizer/Utils/SILIsolationInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "swift/SILOptimizer/Utils/SILIsolationInfo.h"

#include "swift/AST/ASTWalker.h"
#include "swift/AST/DistributedDecl.h"
#include "swift/AST/Expr.h"
#include "swift/SIL/AddressWalker.h"
#include "swift/SIL/ApplySite.h"
Expand Down Expand Up @@ -1417,6 +1418,30 @@ SILValue ActorInstance::lookThroughInsts(SILValue value) {
}
}

// See if this is distributed asLocalActor. In such a case, we want to
// consider the result actor to be the same actor as the input isolated
// parameter.
if (auto fas = FullApplySite::isa(svi)) {
if (auto *functionRef = fas.getReferencedFunctionOrNull()) {
if (auto declRef = functionRef->getDeclRef()) {
if (auto *accessor =
dyn_cast_or_null<AccessorDecl>(declRef.getFuncDecl())) {
if (auto asLocalActorDecl =
getDistributedActorAsLocalActorComputedProperty(
functionRef->getDeclContext()->getParentModule())) {
if (auto asLocalActorGetter =
asLocalActorDecl->getAccessor(AccessorKind::Get);
asLocalActorGetter && asLocalActorGetter == accessor) {
value = lookThroughInsts(
fas.getIsolatedArgumentOperandOrNullPtr()->get());
continue;
}
}
}
}
}
}

break;
}

Expand Down
13 changes: 13 additions & 0 deletions test/Distributed/distributed_actor_transfernonsendable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@ distributed actor MyDistributedActor {
// 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}}
}
}


func doSomething() async { }

// Make sure that we consider asLocalActor's result to be the same actor as
// its actor parameter.
func testAsLocalActorForwards() async {
await withTaskGroup { group in
group.addTask {
await self.doSomething()
}
}
}
}

/////////////////////////////////
Expand Down