mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Merge pull request #81943 from gottesmm/release/6.2-rdar152436817
[6.2][rbi] Lookthrough an invocation of DistributedActor.asLocalActor when determining actor instances.
This commit is contained in:
@@ -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"
|
||||
@@ -1336,6 +1337,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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user