Skip to content

[6.2][Distributed] Distributed actor usage through protocol with lib-evolution #80942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions lib/IRGen/GenMeta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1001,8 +1001,7 @@ namespace {

// Emit the dispatch thunk.
auto shouldEmitDispatchThunk =
(Resilient || IGM.getOptions().WitnessMethodElimination) &&
(!func.isDistributed() || !func.isDistributedThunk());
(Resilient || IGM.getOptions().WitnessMethodElimination);
if (shouldEmitDispatchThunk) {
IGM.emitDispatchThunk(func);
}
Expand Down Expand Up @@ -1083,14 +1082,10 @@ namespace {
// Define the method descriptor.
SILDeclRef func(entry.getFunction());

/// Distributed thunks don't need method descriptors
if (!func.isDistributedThunk()) {
auto *descriptor =
B.getAddrOfCurrentPosition(
IGM.ProtocolRequirementStructTy);
IGM.defineMethodDescriptor(func, Proto, descriptor,
IGM.ProtocolRequirementStructTy);
}
auto *descriptor =
B.getAddrOfCurrentPosition(IGM.ProtocolRequirementStructTy);
IGM.defineMethodDescriptor(func, Proto, descriptor,
IGM.ProtocolRequirementStructTy);
}
}

Expand Down
6 changes: 0 additions & 6 deletions lib/IRGen/GenProto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2368,12 +2368,6 @@ namespace {
LinkEntity::forBaseConformanceDescriptor(requirement));
B.addRelativeAddress(baseConformanceDescriptor);
} else if (entry.getKind() == SILWitnessTable::Method) {
// distributed thunks don't need resilience
if (entry.getMethodWitness().Requirement.isDistributedThunk()) {
witnesses = witnesses.drop_back();
continue;
}

// Method descriptor.
auto declRef = entry.getMethodWitness().Requirement;
auto requirement =
Expand Down
8 changes: 0 additions & 8 deletions lib/IRGen/IRSymbolVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,6 @@ class IRSymbolVisitorImpl : public SILSymbolVisitor {
}

void addMethodDescriptor(SILDeclRef declRef) override {
if (declRef.isDistributedThunk()) {
auto afd = declRef.getAbstractFunctionDecl();
auto DC = afd->getDeclContext();
if (isa<ProtocolDecl>(DC)) {
return;
}
}

addLinkEntity(LinkEntity::forMethodDescriptor(declRef));
}

Expand Down
1 change: 0 additions & 1 deletion lib/SIL/IR/SILSymbolVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,6 @@ class SILSymbolVisitorImpl : public ASTVisitor<SILSymbolVisitorImpl> {
V.Ctx.getOpts().WitnessMethodElimination} {}

void addMethod(SILDeclRef declRef) {
// TODO: alternatively maybe prevent adding distributed thunk here rather than inside those?
if (Resilient || WitnessMethodElimination) {
Visitor.addDispatchThunk(declRef);
Visitor.addMethodDescriptor(declRef);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// REQUIRES: VENDOR=apple
// REQUIRES: OS=macosx || OS=linux-gnu
// REQUIRES: concurrency
// REQUIRES: distributed
// UNSUPPORTED: use_os_stdlib

// RUN: %empty-directory(%t)
// RUN: split-file %s %t

// 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)
// 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

// RUN: %target-codesign %t/a.out
// RUN: %target-run %t/a.out | %FileCheck %s

//--- library.swift
import Distributed

public protocol SimpleProtocol: DistributedActor
where ActorSystem == LocalTestingDistributedActorSystem {

// nonisolated override var id: ID { get } // comes from DistributedActor

// Has to have a distributed method to fail
distributed func test() -> Int
}

//--- main.swift
import Distributed
import Library

public distributed actor SimpleActor: SimpleProtocol {
public distributed func test() -> Int {
print("SimpleActor.test")
return 1
}
}

public func makeFromFail<Act: SimpleProtocol>(_ act: Act) async {
print(act.id)
try! await print("act.test() = \(act.test())")
// CHECK: SimpleActor.test
// CHECK: act.test() = 1
}

@main
struct TestSwiftFrameworkTests {
static func main() async {
let system = LocalTestingDistributedActorSystem()

let simpleActor = SimpleActor(actorSystem: system)
await makeFromFail(simpleActor)
}
}