Skip to content

Commit 957a95b

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
1 parent 721944a commit 957a95b

File tree

5 files changed

+71
-25
lines changed

5 files changed

+71
-25
lines changed

lib/IRGen/GenMeta.cpp

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

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

1085-
/// Distributed thunks don't need method descriptors
1086-
if (!func.isDistributedThunk()) {
1087-
auto *descriptor =
1088-
B.getAddrOfCurrentPosition(
1089-
IGM.ProtocolRequirementStructTy);
1090-
IGM.defineMethodDescriptor(func, Proto, descriptor,
1091-
IGM.ProtocolRequirementStructTy);
1092-
}
1084+
auto *descriptor =
1085+
B.getAddrOfCurrentPosition(IGM.ProtocolRequirementStructTy);
1086+
IGM.defineMethodDescriptor(func, Proto, descriptor,
1087+
IGM.ProtocolRequirementStructTy);
10931088
}
10941089
}
10951090

lib/IRGen/GenProto.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2348,12 +2348,6 @@ namespace {
23482348
LinkEntity::forBaseConformanceDescriptor(requirement));
23492349
B.addRelativeAddress(baseConformanceDescriptor);
23502350
} else if (entry.getKind() == SILWitnessTable::Method) {
2351-
// distributed thunks don't need resilience
2352-
if (entry.getMethodWitness().Requirement.isDistributedThunk()) {
2353-
witnesses = witnesses.drop_back();
2354-
continue;
2355-
}
2356-
23572351
// Method descriptor.
23582352
auto declRef = entry.getMethodWitness().Requirement;
23592353
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: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// REQUIRES: VENDOR=apple
2+
// REQUIRES: concurrency
3+
// REQUIRES: distributed
4+
5+
// RUN: %empty-directory(%t)
6+
// RUN: split-file %s %t
7+
8+
// 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)
9+
// 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
10+
11+
12+
// RUN: %target-codesign %t/a.out
13+
// RUN: %target-run %t/a.out
14+
15+
//--- library.swift
16+
import Distributed
17+
18+
//public protocol NormalProtocol {
19+
// func NORMAL() async -> Int
20+
//}
21+
22+
public protocol SimpleProtocol: DistributedActor
23+
where ActorSystem == LocalTestingDistributedActorSystem {
24+
25+
// nonisolated override var id: ID { get } // comes from DistributedActor
26+
27+
// Has to have a distributed method to fail
28+
distributed func test() -> Int
29+
}
30+
31+
//--- main.swift
32+
import Distributed
33+
import Library
34+
35+
//actor NormalActor: NormalProtocol {
36+
// func NORMAL() async -> Int { 1 }
37+
//}
38+
39+
public distributed actor SimpleActor: SimpleProtocol {
40+
public distributed func test() -> Int { 1 }
41+
}
42+
43+
// Passes
44+
public func makeFromPass<Act: DistributedActor>(_ act: Act) {
45+
print(act.id)
46+
}
47+
48+
// Fails
49+
public func makeFromFail<Act: SimpleProtocol>(_ act: Act) async {
50+
print(act.id)
51+
try! await print(act.test())
52+
}
53+
54+
@main
55+
struct TestSwiftFrameworkTests {
56+
static func main() async {
57+
let system = LocalTestingDistributedActorSystem()
58+
59+
// let norm = NormalActor()
60+
61+
let simpleActor = SimpleActor(actorSystem: system)
62+
// makeFromPass(simpleActor)
63+
64+
await makeFromFail(simpleActor)
65+
}
66+
}

0 commit comments

Comments
 (0)