Skip to content

[Distributed] Reproducer for generics and library evolution mode #80588

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
merged 2 commits into from
Apr 21, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -1000,8 +1000,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 @@ -1082,14 +1081,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 @@ -2348,12 +2348,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,66 @@
// REQUIRES: VENDOR=apple
// REQUIRES: concurrency
// REQUIRES: distributed

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

//--- library.swift
import Distributed

//public protocol NormalProtocol {
// func NORMAL() async -> Int
//}

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

//actor NormalActor: NormalProtocol {
// func NORMAL() async -> Int { 1 }
//}

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

// Passes
public func makeFromPass<Act: DistributedActor>(_ act: Act) {
print(act.id)
}

// Fails
public func makeFromFail<Act: SimpleProtocol>(_ act: Act) async {
print(act.id)
try! await print(act.test())
}

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

// let norm = NormalActor()

let simpleActor = SimpleActor(actorSystem: system)
// makeFromPass(simpleActor)

await makeFromFail(simpleActor)
}
}