Skip to content

Commit d788713

Browse files
authored
Merge pull request #80588 from ktoso/wip-regression-test-for-b-da-bad-access
[Distributed] Reproducer for generics and library evolution mode
2 parents 047d644 + 9f0f477 commit d788713

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
@@ -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: 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)