Skip to content

[Distributed] Generic reqs must be forwarded to accessor from enclosing actor #70785

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

Closed
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
10 changes: 9 additions & 1 deletion lib/IRGen/GenDistributed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,17 @@ static CanSILFunctionType getAccessorType(IRGenModule &IGM,
auto *actor = getDistributedActorOf(Target);
assert(actor);

for (auto *genericParam : actor->getInnermostGenericParamTypes())
for (auto *genericParam : actor->getInnermostGenericParamTypes()) {
genericParams.push_back(genericParam);

// and also forward all requirements this generic parameter might have.
for (auto req : actor->getGenericRequirements()) {
if (req.getFirstType()->isEqual(genericParam)) {
genericRequirements.push_back(req);
}
}
}

// Add a generic parameter `D` which stands for decoder type in the
// accessor signature - `inout D`.
genericParams.push_back(decoderType);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend-emit-module -emit-module-path %t/FakeDistributedActorSystems.swiftmodule -module-name FakeDistributedActorSystems -disable-availability-checking %S/../Inputs/FakeDistributedActorSystems.swift
// RUN: %target-build-swift -module-name main -Xfrontend -disable-availability-checking -j2 -parse-as-library -I %t %s %S/../Inputs/FakeDistributedActorSystems.swift -o %t/a.out
// RUN: %target-run %t/a.out | %FileCheck %s --color

// REQUIRES: executable_test
// REQUIRES: concurrency
// REQUIRES: distributed

// rdar://76038845
// UNSUPPORTED: use_os_stdlib
// UNSUPPORTED: back_deployment_runtime

import Distributed
import FakeDistributedActorSystems

import Distributed
import FakeDistributedActorSystems

typealias DefaultDistributedActorSystem = FakeActorSystem

protocol SomeProtocol {
static var isInteger: Bool { get }
}

distributed actor TestActor<Value> where Value: Codable & Identifiable, Value.ID: SomeProtocol {
distributed func requirementsFromActor(value: Value) async throws {
print("OK: \(value)")
}
distributed func requirementsFromActorAndMethod(value: Value) async throws where Value: VerySpecific {
print("OK: \(value)")
}
}

protocol VerySpecific {}

struct TheValue: Codable, Identifiable, VerySpecific {
let id: String
init() {
self.id = "id"
}
}
extension String: SomeProtocol {
static var isInteger: Bool { false }
}

@main struct Main {
static func main() async throws {
let ta: TestActor<TheValue> = TestActor(actorSystem: .init())
try await ta.requirementsFromActor(value: TheValue())
try await ta.requirementsFromActorAndMethod(value: TheValue())
// CHECK: OK
}
}

// FIXME: repro testing
// export VER=5.9; swiftly install $VER && swiftly use $VER; swiftly list | grep use; swift build --build-tests; if [[ "$?" -eq 0 ]]; then echo "$VER: OK" >> ../checks; else echo "$VER: broken" >> ../checks; fi