Skip to content

Commit 139d878

Browse files
committed
[Distributed] Accessor must be available cross module in resilient mode
This is an important fix for libraries using @resolvable in resilient libraries. Without the fix we're missing an accessor and this will fail some remote calls which make use of remote calls on resolvable protocols. This would manifest as missing accessor error thrown by the executeDistributedTarget function. resolves rdar://148224780
1 parent 1b2f8c3 commit 139d878

File tree

3 files changed

+91
-18
lines changed

3 files changed

+91
-18
lines changed

lib/IRGen/GenMeta.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,16 +1083,14 @@ namespace {
10831083
// Define the method descriptor.
10841084
SILDeclRef func(entry.getFunction());
10851085

1086-
/// Distributed thunks don't need resilience.
1087-
if (func.isDistributedThunk()) {
1088-
continue;
1086+
/// Distributed thunks don't need method descriptors
1087+
if (!func.isDistributedThunk()) {
1088+
auto *descriptor =
1089+
B.getAddrOfCurrentPosition(
1090+
IGM.ProtocolRequirementStructTy);
1091+
IGM.defineMethodDescriptor(func, Proto, descriptor,
1092+
IGM.ProtocolRequirementStructTy);
10891093
}
1090-
1091-
auto *descriptor =
1092-
B.getAddrOfCurrentPosition(
1093-
IGM.ProtocolRequirementStructTy);
1094-
IGM.defineMethodDescriptor(func, Proto, descriptor,
1095-
IGM.ProtocolRequirementStructTy);
10961094
}
10971095
}
10981096

lib/IRGen/IRSymbolVisitor.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,6 @@ class IRSymbolVisitorImpl : public SILSymbolVisitor {
108108

109109
void addDispatchThunk(SILDeclRef declRef) override {
110110
auto entity = LinkEntity::forDispatchThunk(declRef);
111-
112-
// TODO: explain why
113-
if (declRef.isDistributedThunk()) {
114-
auto afd = declRef.getAbstractFunctionDecl();
115-
if (afd && isa<ProtocolDecl>(afd->getDeclContext())) {
116-
return;
117-
}
118-
}
119-
120111
addLinkEntity(entity);
121112

122113
if (declRef.getAbstractFunctionDecl()->hasAsync())
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend-emit-module -emit-module-path %t/FakeDistributedActorSystems.swiftmodule -module-name FakeDistributedActorSystems -target %target-swift-6.0-abi-triple %S/../Inputs/FakeDistributedActorSystems.swift -plugin-path %swift-plugin-dir
3+
// RUN: %target-build-swift -module-name ActorsFramework -target %target-swift-6.0-abi-triple -j2 -parse-as-library -I %t %s %S/../Inputs/FakeDistributedActorSystems.swift -plugin-path %swift-plugin-dir -o %t/a.out
4+
// RUN: %target-codesign %t/a.out
5+
// RUN: %env-SWIFT_DUMP_ACCESSIBLE_FUNCTIONS=true %target-run %t/a.out 2>&1 | %FileCheck %s --color --dump-input=always
6+
7+
// REQUIRES: executable_test
8+
// REQUIRES: concurrency
9+
// REQUIRES: distributed
10+
11+
// rdar://76038845
12+
// UNSUPPORTED: use_os_stdlib
13+
// UNSUPPORTED: back_deployment_runtime
14+
15+
// FIXME(distributed): Distributed actors currently have some issues on windows, isRemote always returns false. rdar://82593574
16+
// UNSUPPORTED: OS=windows-msvc
17+
18+
import Distributed
19+
import FakeDistributedActorSystems
20+
21+
// ==== Known actor system -----------------------------------------------------
22+
23+
public struct Response: Codable, Sendable {
24+
let resp: Int
25+
public init(resp: Int) {
26+
self.resp = resp
27+
}
28+
}
29+
30+
public struct Provider: Codable, Sendable {
31+
let r1: Int
32+
public init(r1: Int) {
33+
self.r1 = r1
34+
}
35+
}
36+
37+
@Resolvable
38+
public protocol DistributedNotificationService: DistributedActor
39+
where ActorSystem == FakeRoundtripActorSystem {
40+
distributed func getArray(a1: [Int], a2: String?) async throws -> [Response]
41+
}
42+
43+
distributed actor DistributedNotificationServiceImpl: DistributedNotificationService {
44+
typealias ActorSystem = FakeRoundtripActorSystem
45+
46+
distributed func getArray(a1: [Int], a2: String?) async throws -> [Response] {
47+
[] // mock impl is enough
48+
}
49+
}
50+
51+
// ==== ------------------------------------------------------------------------
52+
53+
@main struct Main {
54+
static func main() async throws {
55+
let roundtripSystem = FakeRoundtripActorSystem()
56+
57+
let real: any DistributedNotificationService = DistributedNotificationServiceImpl(
58+
actorSystem: roundtripSystem)
59+
60+
let proxy: any DistributedNotificationService =
61+
try $DistributedNotificationService.resolve(id: real.id, using: roundtripSystem)
62+
_ = try await proxy.getArray(a1: [], a2: "")
63+
64+
// CHECK: ==== Accessible Function Records ====
65+
66+
// CHECK: Record name: $s15ActorsFramework30DistributedNotificationServicePAA0C001_C9ActorStubRzrlE8getArray2a12a2SayAA8ResponseVGSaySiG_SSSgtYaKFTE
67+
// CHECK: Demangled: distributed thunk (extension in ActorsFramework):ActorsFramework.DistributedNotificationService< where A: Distributed._DistributedActorStub>.getArray(a1: Swift.Array<Swift.Int>, a2: Swift.Optional<Swift.String>) async throws -> Swift.Array<ActorsFramework.Response>
68+
// CHECK: Function Ptr: [[PTR:0x.*]]
69+
// CHECK: Flags.IsDistributed: 1
70+
71+
// CHECK: Record name: $s15ActorsFramework34DistributedNotificationServiceImplC8getArray2a12a2SayAA8ResponseVGSaySiG_SSSgtYaKFTE
72+
// CHECK: Demangled: distributed thunk ActorsFramework.DistributedNotificationServiceImpl.getArray(a1: Swift.Array<Swift.Int>, a2: Swift.Optional<Swift.String>) async throws -> Swift.Array<ActorsFramework.Response>
73+
// CHECK: Function Ptr: [[PTR:0x.*]]
74+
// CHECK: Flags.IsDistributed: 1
75+
76+
// CHECK: Record name: $s15ActorsFramework31$DistributedNotificationServiceC8getArray2a12a2SayAA8ResponseVGSaySiG_SSSgtYaKFTE
77+
// CHECK: Demangled: distributed thunk ActorsFramework.$DistributedNotificationService.getArray(a1: Swift.Array<Swift.Int>, a2: Swift.Optional<Swift.String>) async throws -> Swift.Array<ActorsFramework.Response>
78+
// CHECK: Function Ptr: [[PTR:0x.*]]
79+
// CHECK: Flags.IsDistributed: 1
80+
81+
// CHECK: Record count: 3
82+
// CHECK: ==== End of Accessible Function Records ====
83+
}
84+
}

0 commit comments

Comments
 (0)