diff --git a/lib/IRGen/GenDistributed.cpp b/lib/IRGen/GenDistributed.cpp index 7b4fc3c9acca9..962aaa4b7db32 100644 --- a/lib/IRGen/GenDistributed.cpp +++ b/lib/IRGen/GenDistributed.cpp @@ -269,9 +269,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); diff --git a/test/Distributed/Runtime/distributed_actor_generic_constraint_issue_115497090.swift b/test/Distributed/Runtime/distributed_actor_generic_constraint_issue_115497090.swift new file mode 100644 index 0000000000000..07359f2a67bc8 --- /dev/null +++ b/test/Distributed/Runtime/distributed_actor_generic_constraint_issue_115497090.swift @@ -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 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 = 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 \ No newline at end of file