Skip to content

Commit 694af33

Browse files
committed
[Distributed] Distributed actor usage through protocol with lib-evo must work
This corrects how we were dealing with dispatch thunks -- mostly be removing a lot of special casing we did but doesn't seem necessary and instead we correct and emit all the necessary information int TBD. This builds on #74935 by further refining how we fixed that issue, and adds more regression tests. It also removes a load of special casing of distributed thunks in library evolution mode, which is great. Resolves and adds regression test for for rdar://145292018 This is also a more proper fix to the previously resolved but in a not-great-way which caused other issues: - resolves rdar://128284016 - resolves rdar://128310903 Review followup, cleanup test
1 parent 7d77c61 commit 694af33

File tree

5 files changed

+59
-25
lines changed

5 files changed

+59
-25
lines changed

lib/IRGen/GenMeta.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,8 +1001,7 @@ namespace {
10011001

10021002
// Emit the dispatch thunk.
10031003
auto shouldEmitDispatchThunk =
1004-
(Resilient || IGM.getOptions().WitnessMethodElimination) &&
1005-
(!func.isDistributed() || !func.isDistributedThunk());
1004+
(Resilient || IGM.getOptions().WitnessMethodElimination);
10061005
if (shouldEmitDispatchThunk) {
10071006
IGM.emitDispatchThunk(func);
10081007
}
@@ -1083,14 +1082,10 @@ namespace {
10831082
// Define the method descriptor.
10841083
SILDeclRef func(entry.getFunction());
10851084

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);
1093-
}
1085+
auto *descriptor =
1086+
B.getAddrOfCurrentPosition(IGM.ProtocolRequirementStructTy);
1087+
IGM.defineMethodDescriptor(func, Proto, descriptor,
1088+
IGM.ProtocolRequirementStructTy);
10941089
}
10951090
}
10961091

lib/IRGen/GenProto.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2368,12 +2368,6 @@ namespace {
23682368
LinkEntity::forBaseConformanceDescriptor(requirement));
23692369
B.addRelativeAddress(baseConformanceDescriptor);
23702370
} else if (entry.getKind() == SILWitnessTable::Method) {
2371-
// distributed thunks don't need resilience
2372-
if (entry.getMethodWitness().Requirement.isDistributedThunk()) {
2373-
witnesses = witnesses.drop_back();
2374-
continue;
2375-
}
2376-
23772371
// Method descriptor.
23782372
auto declRef = entry.getMethodWitness().Requirement;
23792373
auto requirement =

lib/IRGen/IRSymbolVisitor.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,6 @@ class IRSymbolVisitorImpl : public SILSymbolVisitor {
157157
}
158158

159159
void addMethodDescriptor(SILDeclRef declRef) override {
160-
if (declRef.isDistributedThunk()) {
161-
auto afd = declRef.getAbstractFunctionDecl();
162-
auto DC = afd->getDeclContext();
163-
if (isa<ProtocolDecl>(DC)) {
164-
return;
165-
}
166-
}
167-
168160
addLinkEntity(LinkEntity::forMethodDescriptor(declRef));
169161
}
170162

lib/SIL/IR/SILSymbolVisitor.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,6 @@ class SILSymbolVisitorImpl : public ASTVisitor<SILSymbolVisitorImpl> {
835835
V.Ctx.getOpts().WitnessMethodElimination} {}
836836

837837
void addMethod(SILDeclRef declRef) {
838-
// TODO: alternatively maybe prevent adding distributed thunk here rather than inside those?
839838
if (Resilient || WitnessMethodElimination) {
840839
Visitor.addDispatchThunk(declRef);
841840
Visitor.addMethodDescriptor(declRef);
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// REQUIRES: VENDOR=apple
2+
// REQUIRES: OS=macosx || OS=linux-gnu
3+
// REQUIRES: concurrency
4+
// REQUIRES: distributed
5+
// UNSUPPORTED: use_os_stdlib
6+
7+
// RUN: %empty-directory(%t)
8+
// RUN: split-file %s %t
9+
10+
// RUN: %target-build-swift -Xfrontend -validate-tbd-against-ir=all -enable-library-evolution -target %target-cpu-apple-macosx13.0 -parse-as-library -emit-library -emit-module-path %t/Library.swiftmodule -module-name Library %t/library.swift -o %t/%target-library-name(Library)
11+
// RUN: %target-build-swift -Xfrontend -validate-tbd-against-ir=all -target %target-cpu-apple-macosx13.0 -parse-as-library -lLibrary -module-name main -I %t -L %t %t/main.swift -o %t/a.out
12+
13+
// RUN: %target-codesign %t/a.out
14+
// RUN: %target-run %t/a.out | %FileCheck %s
15+
16+
//--- library.swift
17+
import Distributed
18+
19+
public protocol SimpleProtocol: DistributedActor
20+
where ActorSystem == LocalTestingDistributedActorSystem {
21+
22+
// nonisolated override var id: ID { get } // comes from DistributedActor
23+
24+
// Has to have a distributed method to fail
25+
distributed func test() -> Int
26+
}
27+
28+
//--- main.swift
29+
import Distributed
30+
import Library
31+
32+
public distributed actor SimpleActor: SimpleProtocol {
33+
public distributed func test() -> Int {
34+
print("SimpleActor.test")
35+
return 1
36+
}
37+
}
38+
39+
public func makeFromFail<Act: SimpleProtocol>(_ act: Act) async {
40+
print(act.id)
41+
try! await print("act.test() = \(act.test())")
42+
// CHECK: SimpleActor.test
43+
// CHECK: act.test() = 1
44+
}
45+
46+
@main
47+
struct TestSwiftFrameworkTests {
48+
static func main() async {
49+
let system = LocalTestingDistributedActorSystem()
50+
51+
let simpleActor = SimpleActor(actorSystem: system)
52+
await makeFromFail(simpleActor)
53+
}
54+
}

0 commit comments

Comments
 (0)