Skip to content

Commit 2bdef63

Browse files
committed
[Distributed] Generic reqs must be forwarded to accessor from enclosing actor
If we don't do this, the generic parameter has no requirements at all, which a) is incorrect to begin with, it should have the exact same signature as the method it is the accessor for, and b) it would trip up verification which is enabled on linux in snapshot builds -- causing crashes. Resolves rdar://115497090
1 parent 204d496 commit 2bdef63

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

lib/IRGen/GenDistributed.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,17 @@ static CanSILFunctionType getAccessorType(IRGenModule &IGM,
269269
auto *actor = getDistributedActorOf(Target);
270270
assert(actor);
271271

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

275+
// and also forward all requirements this generic parameter might have.
276+
for (auto req : actor->getGenericRequirements()) {
277+
if (req.getFirstType()->isEqual(genericParam)) {
278+
genericRequirements.push_back(req);
279+
}
280+
}
281+
}
282+
275283
// Add a generic parameter `D` which stands for decoder type in the
276284
// accessor signature - `inout D`.
277285
genericParams.push_back(decoderType);
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend-emit-module -emit-module-path %t/FakeDistributedActorSystems.swiftmodule -module-name FakeDistributedActorSystems -disable-availability-checking %S/../Inputs/FakeDistributedActorSystems.swift
3+
// 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
4+
// RUN: %target-run %t/a.out | %FileCheck %s --color
5+
6+
// REQUIRES: executable_test
7+
// REQUIRES: concurrency
8+
// REQUIRES: distributed
9+
10+
// rdar://76038845
11+
// UNSUPPORTED: use_os_stdlib
12+
// UNSUPPORTED: back_deployment_runtime
13+
14+
import Distributed
15+
import FakeDistributedActorSystems
16+
17+
import Distributed
18+
import FakeDistributedActorSystems
19+
20+
typealias DefaultDistributedActorSystem = FakeActorSystem
21+
22+
protocol SomeProtocol {
23+
static var isInteger: Bool { get }
24+
}
25+
26+
distributed actor TestActor<Value> where Value: Codable & Identifiable, Value.ID: SomeProtocol {
27+
distributed func requirementsFromActor(value: Value) async throws {
28+
print("OK: \(value)")
29+
}
30+
distributed func requirementsFromActorAndMethod(value: Value) async throws where Value: VerySpecific {
31+
print("OK: \(value)")
32+
}
33+
}
34+
35+
protocol VerySpecific {}
36+
37+
struct TheValue: Codable, Identifiable, VerySpecific {
38+
let id: String
39+
init() {
40+
self.id = "id"
41+
}
42+
}
43+
extension String: SomeProtocol {
44+
static var isInteger: Bool { false }
45+
}
46+
47+
@main struct Main {
48+
static func main() async throws {
49+
let ta: TestActor<TheValue> = TestActor(actorSystem: .init())
50+
try await ta.requirementsFromActor(value: TheValue())
51+
try await ta.requirementsFromActorAndMethod(value: TheValue())
52+
// CHECK: OK
53+
}
54+
}
55+
56+
// FIXME: repro testing
57+
// 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

0 commit comments

Comments
 (0)