Skip to content

Commit 64e98e6

Browse files
authored
Merge pull request swiftlang#83997 from ktoso/pick-nonisolatednonsending-by-default-and-distributed
2 parents f592747 + 0ab9f4f commit 64e98e6

File tree

3 files changed

+91
-2
lines changed

3 files changed

+91
-2
lines changed

lib/Sema/CodeSynthesisDistributedActor.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,10 @@ static FuncDecl *createSameSignatureDistributedThunkDecl(DeclContext *DC,
738738
thunk->setSynthesized(true);
739739
thunk->setDistributedThunk(true);
740740
thunk->getAttrs().add(NonisolatedAttr::createImplicit(C));
741+
// TODO(distributed): It would be nicer to make distributed thunks nonisolated(nonsending) instead;
742+
// this way we would not hop off the caller when calling system.remoteCall;
743+
// it'd need new ABI and the remoteCall also to become nonisolated(nonsending)
744+
thunk->getAttrs().add(new (C) ConcurrentAttr(/*IsImplicit=*/true));
741745

742746
return thunk;
743747
}

test/Distributed/Runtime/distributed_actor_remoteCall_roundtrip.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
// RUN: %target-codesign %t/a.out
55
// RUN: %target-run %t/a.out | %FileCheck %s --enable-var-scope
66

7-
// X: %target-run-simple-swift( -Xfrontend -module-name=main -target %target-swift-5.7-abi-triple -parse-as-library -Xfrontend -I -Xfrontend %t ) | %FileCheck %s
8-
97
// REQUIRES: executable_test
108
// REQUIRES: concurrency
119
// REQUIRES: distributed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend-emit-module -emit-module-path %t/FakeDistributedActorSystems.swiftmodule \
3+
// RUN: -module-name FakeDistributedActorSystems -target %target-swift-5.7-abi-triple \
4+
// RUN: %S/../Inputs/FakeDistributedActorSystems.swift
5+
6+
// RUN: %target-build-swift -module-name main -enable-upcoming-feature NonisolatedNonsendingByDefault \
7+
// RUN: -target %target-swift-5.7-abi-triple -j2 -parse-as-library -I %t %s \
8+
// RUN: %S/../Inputs/FakeDistributedActorSystems.swift -o %t/a.out
9+
10+
// RUN: %target-codesign %t/a.out
11+
// RUN: %target-run %t/a.out | %FileCheck %s --enable-var-scope
12+
13+
// REQUIRES: swift_feature_NonisolatedNonsendingByDefault
14+
15+
// REQUIRES: executable_test
16+
// REQUIRES: concurrency
17+
// REQUIRES: distributed
18+
19+
// rdar://76038845
20+
// UNSUPPORTED: use_os_stdlib
21+
// UNSUPPORTED: back_deployment_runtime
22+
23+
// FIXME(distributed): Distributed actors currently have some issues on windows, isRemote always returns false. rdar://82593574
24+
// UNSUPPORTED: OS=windows-msvc
25+
26+
import Distributed
27+
import FakeDistributedActorSystems
28+
29+
typealias DefaultDistributedActorSystem = FakeRoundtripActorSystem
30+
31+
distributed actor Greeter: CustomStringConvertible {
32+
distributed func echo(name: String) -> String {
33+
return "Echo: \(name) (impl on: \(self.id))"
34+
}
35+
36+
nonisolated var description: String {
37+
"\(Self.self)(\(id))"
38+
}
39+
}
40+
41+
extension Greeter {
42+
distributed func echoInExtension(name: String) -> String {
43+
return "Echo: \(name) (impl on: \(self.id))"
44+
}
45+
}
46+
47+
nonisolated extension Greeter {
48+
distributed func echoInNonisolatedExtension(name: String) -> String {
49+
return "Echo: \(name) (impl on: \(self.id))"
50+
}
51+
}
52+
53+
struct SomeError: Error {}
54+
55+
// ==== Test -------------------------------------------------------------------
56+
57+
func test() async throws {
58+
let system = DefaultDistributedActorSystem()
59+
60+
let local = Greeter(actorSystem: system)
61+
let ref = try Greeter.resolve(id: local.id, using: system)
62+
63+
let reply = try await ref.echo(name: "Caplin")
64+
// CHECK: > encode argument name:name, value: Caplin
65+
// CHECK-NOT: > encode error type
66+
// CHECK: > encode return type: Swift.String
67+
// CHECK: > done recording
68+
// CHECK: >> remoteCall
69+
// CHECK: > decode return type: Swift.String
70+
// CHECK: > decode argument: Caplin
71+
// CHECK: << onReturn: Echo: Caplin (impl on: ActorAddress(address: "<unique-id>"))
72+
73+
print("got: \(reply)")
74+
// CHECK: got: Echo: Caplin (impl on: ActorAddress(address: "<unique-id>"))
75+
76+
// just double check there's no surprises with distributed thunks in extensions
77+
_ = try await ref.echoInExtension(name: "Bob")
78+
_ = try await ref.echoInNonisolatedExtension(name: "Alice")
79+
80+
print("OK") // CHECK: OK
81+
}
82+
83+
@main struct Main {
84+
static func main() async {
85+
try! await test()
86+
}
87+
}

0 commit comments

Comments
 (0)