Skip to content

Commit 4f76f77

Browse files
committed
[Distributed] Synthesize 'distributed thunk' accessor for distributed computed properties
1 parent 9401062 commit 4f76f77

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

lib/AST/ASTMangler.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3192,6 +3192,14 @@ void ASTMangler::appendEntity(const ValueDecl *decl) {
31923192
// Handle accessors specially, they are mangled as modifiers on the accessed
31933193
// declaration.
31943194
if (auto accessor = dyn_cast<AccessorDecl>(decl)) {
3195+
if (accessor->isDistributedThunk()) {
3196+
appendContextOf(decl);
3197+
appendDeclName(accessor->getStorage());
3198+
appendDeclType(accessor, FunctionMangling);
3199+
appendOperator("F");
3200+
return;
3201+
}
3202+
31953203
return appendAccessorEntity(
31963204
getCodeForAccessorKind(accessor->getAccessorKind()),
31973205
accessor->getStorage(), accessor->isStatic());

lib/Sema/CodeSynthesisDistributedActor.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -725,11 +725,28 @@ static FuncDecl *createDistributedThunkFunction(FuncDecl *func) {
725725
}
726726
ParameterList *params = ParameterList::create(C, paramDecls); // = funcParams->clone(C);
727727

728-
auto thunk = FuncDecl::createImplicit(
729-
C, swift::StaticSpellingKind::None, thunkName, SourceLoc(),
730-
/*async=*/true, /*throws=*/true,
731-
genericParamList, params,
732-
func->getResultInterfaceType(), DC);
728+
FuncDecl *thunk = nullptr;
729+
if (auto *accessor = dyn_cast<AccessorDecl>(func)) {
730+
auto *distributedVar = cast<VarDecl>(accessor->getStorage());
731+
732+
thunk = AccessorDecl::create(
733+
C, /*declLoc=*/accessor->getLoc(), /*accessorKeywordLoc=*/SourceLoc(),
734+
AccessorKind::Get, distributedVar,
735+
/*staticLoc=*/SourceLoc(), StaticSpellingKind::None,
736+
/*async=*/true, /*asyncLoc=*/SourceLoc(),
737+
/*throws=*/true, /*throwsLoc=*/SourceLoc(), genericParamList, params,
738+
func->getResultInterfaceType(), accessor->getDeclContext());
739+
740+
thunk->setImplicit();
741+
} else {
742+
thunk = FuncDecl::createImplicit(
743+
C, swift::StaticSpellingKind::None, func->getName(), SourceLoc(),
744+
/*async=*/true, /*throws=*/true, genericParamList, params,
745+
func->getResultInterfaceType(), DC);
746+
}
747+
748+
assert(thunk && "couldn't create a distributed thunk");
749+
733750
thunk->setSynthesized(true);
734751
thunk->getAttrs().add(new (C) NonisolatedAttr(/*isImplicit=*/true));
735752

test/Distributed/Runtime/distributed_actor_func_calls_remoteCall_computedProperty.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ typealias DefaultDistributedActorSystem = FakeRoundtripActorSystem
2121

2222
distributed actor Greeter {
2323
distributed var theDistributedProperty: String {
24-
"Patrik the Seastar"
24+
"Patrick the Seastar"
2525
}
2626
}
2727

@@ -32,10 +32,10 @@ func test() async throws {
3232
let ref = try Greeter.resolve(id: local.id, using: system)
3333

3434
let reply = try await ref.theDistributedProperty
35-
// CHECK: >> remoteCall: on:main.Greeter, target:main.Greeter.name, invocation:FakeInvocationEncoder(genericSubs: [], arguments: [], returnType: Optional(Swift.String), errorType: nil), throwing:Swift.Never, returning:Swift.String
35+
// CHECK: >> remoteCall: on:main.Greeter, target:main.Greeter.theDistributedProperty(), invocation:FakeInvocationEncoder(genericSubs: [], arguments: [], returnType: Optional(Swift.String), errorType: nil), throwing:Swift.Never, returning:Swift.String
3636
// CHECK: << remoteCall return: Patrick the Seastar
3737
print("reply: \(reply)")
38-
// CHECK: reply: Echo: Caplin
38+
// CHECK: reply: Patrick the Seastar
3939
}
4040

4141
@main struct Main {

0 commit comments

Comments
 (0)