Skip to content

Commit 5f0e73d

Browse files
xedinktoso
authored andcommitted
[Distributed] Synthesize 'distributed thunk' accessor for distributed computed properties
1 parent b17b5ee commit 5f0e73d

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
@@ -3190,6 +3190,14 @@ void ASTMangler::appendEntity(const ValueDecl *decl) {
31903190
// Handle accessors specially, they are mangled as modifiers on the accessed
31913191
// declaration.
31923192
if (auto accessor = dyn_cast<AccessorDecl>(decl)) {
3193+
if (accessor->isDistributedThunk()) {
3194+
appendContextOf(decl);
3195+
appendDeclName(accessor->getStorage());
3196+
appendDeclType(accessor, FunctionMangling);
3197+
appendOperator("F");
3198+
return;
3199+
}
3200+
31933201
return appendAccessorEntity(
31943202
getCodeForAccessorKind(accessor->getAccessorKind()),
31953203
accessor->getStorage(), accessor->isStatic());

lib/Sema/CodeSynthesisDistributedActor.cpp

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

698-
auto thunk = FuncDecl::createImplicit(
699-
C, swift::StaticSpellingKind::None, thunkName, SourceLoc(),
700-
/*async=*/true, /*throws=*/true,
701-
genericParamList, params,
702-
func->getResultInterfaceType(), DC);
698+
FuncDecl *thunk = nullptr;
699+
if (auto *accessor = dyn_cast<AccessorDecl>(func)) {
700+
auto *distributedVar = cast<VarDecl>(accessor->getStorage());
701+
702+
thunk = AccessorDecl::create(
703+
C, /*declLoc=*/accessor->getLoc(), /*accessorKeywordLoc=*/SourceLoc(),
704+
AccessorKind::Get, distributedVar,
705+
/*staticLoc=*/SourceLoc(), StaticSpellingKind::None,
706+
/*async=*/true, /*asyncLoc=*/SourceLoc(),
707+
/*throws=*/true, /*throwsLoc=*/SourceLoc(), genericParamList, params,
708+
func->getResultInterfaceType(), accessor->getDeclContext());
709+
710+
thunk->setImplicit();
711+
} else {
712+
thunk = FuncDecl::createImplicit(
713+
C, swift::StaticSpellingKind::None, func->getName(), SourceLoc(),
714+
/*async=*/true, /*throws=*/true, genericParamList, params,
715+
func->getResultInterfaceType(), DC);
716+
}
717+
718+
assert(thunk && "couldn't create a distributed thunk");
719+
703720
thunk->setSynthesized(true);
704721
thunk->setDistributedThunk(true);
705722
thunk->getAttrs().add(new (C) NonisolatedAttr(/*isImplicit=*/true));

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)