Skip to content

Commit 385938f

Browse files
authored
Merge pull request swiftlang#84072 from swiftlang/wip-nonisolated-thunks-retain-semantics
2 parents d11c8d0 + ced1756 commit 385938f

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

lib/Sema/CodeSynthesisDistributedActor.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,8 +737,11 @@ static FuncDecl *createSameSignatureDistributedThunkDecl(DeclContext *DC,
737737

738738
thunk->setSynthesized(true);
739739
thunk->setDistributedThunk(true);
740-
// TODO(distributed): These would benefit from becoming nonisolated(nonsending)
741740
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));
742745

743746
return thunk;
744747
}

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5212,13 +5212,6 @@ getIsolationFromAttributes(const Decl *decl, bool shouldDiagnose = true,
52125212
if (decl->getASTContext().LangOpts.hasFeature(
52135213
Feature::NonisolatedNonsendingByDefault)) {
52145214
if (auto *value = dyn_cast<ValueDecl>(decl)) {
5215-
// TODO(distributed): make distributed thunks nonisolated(nonsending) and remove this if
5216-
if (value->isAsync() && value->isDistributedThunk()) {
5217-
// don't change isolation of distributed thunks until we make them nonisolated(nonsending),
5218-
// since the runtime calling them assumes they're just nonisolated right now.
5219-
return ActorIsolation::forNonisolated(nonisolatedAttr->isUnsafe());
5220-
}
5221-
52225215
if (value->isAsync() &&
52235216
value->getModuleContext() == decl->getASTContext().MainModule) {
52245217
return ActorIsolation::forCallerIsolationInheriting();

test/Distributed/Runtime/distributed_actor_remoteCall_roundtrip_nonisolated_nonsending_by_default.swift

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,23 @@ distributed actor Greeter: CustomStringConvertible {
3333
return "Echo: \(name) (impl on: \(self.id))"
3434
}
3535

36-
distributed func error() throws -> String {
37-
throw SomeError()
38-
}
39-
4036
nonisolated var description: String {
4137
"\(Self.self)(\(id))"
4238
}
4339
}
4440

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+
4553
struct SomeError: Error {}
4654

4755
// ==== Test -------------------------------------------------------------------
@@ -64,6 +72,12 @@ func test() async throws {
6472

6573
print("got: \(reply)")
6674
// 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
6781
}
6882

6983
@main struct Main {

0 commit comments

Comments
 (0)