Skip to content
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

🍒[5.10][Distributed] Generic reqs must be forwarded to accessor from enclosing actor #68861

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.
Jump to
Jump to file
Failed to load files.
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 @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please cherry pick the corrected version from main that uses buildGenericSignature() and preserves all generic requirements, not just those whose subject type is exactly equal to an innermost generic parameter.

Copy link
Member Author

@ktoso ktoso Jan 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Slava, slight de-javu actually indeed... we worked on this in #69502 which already made it to 5.10.

I'll re-evaluate what we're missing and if we even needed this type change still.

}
}
}

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