Skip to content

Commit 1d73afb

Browse files
authored
[Distributed] Handle DA declared inside a generic type (#71492)
1 parent 757c50c commit 1d73afb

File tree

2 files changed

+72
-5
lines changed

2 files changed

+72
-5
lines changed

lib/Sema/CodeSynthesisDistributedActor.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,18 +346,16 @@ deriveBodyDistributed_thunk(AbstractFunctionDecl *thunk, void *context) {
346346

347347
// --- Recording invocation details
348348
// -- recordGenericSubstitution(s)
349-
if (thunk->isGeneric() || nominal->isGeneric()) {
349+
if (auto genEnv = thunk->getGenericEnvironment()) {
350350
auto recordGenericSubstitutionDecl =
351351
C.getRecordGenericSubstitutionOnDistributedInvocationEncoder(invocationEncoderDecl);
352352
assert(recordGenericSubstitutionDecl);
353353
auto recordGenericSubstitutionDeclRef =
354354
UnresolvedDeclRefExpr::createImplicit(
355355
C, recordGenericSubstitutionDecl->getName());
356356

357-
auto signature = thunk->getGenericSignature();
358-
for (auto genParamType : signature.getGenericParams()) {
359-
360-
auto tyExpr = TypeExpr::createImplicit(thunk->mapTypeIntoContext(genParamType), C);
357+
for (auto genParamType : genEnv->getGenericParams()) {
358+
auto tyExpr = TypeExpr::createImplicit(genEnv->mapTypeIntoContext(genParamType), C);
361359
auto subTypeExpr = new (C) DotSelfExpr(
362360
tyExpr,
363361
sloc, sloc, tyExpr->getType());
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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-codesign %t/a.out
5+
// RUN: %target-run %t/a.out | %FileCheck %s --color
6+
7+
// REQUIRES: executable_test
8+
// REQUIRES: concurrency
9+
// REQUIRES: distributed
10+
11+
// rdar://76038845
12+
// UNSUPPORTED: use_os_stdlib
13+
// UNSUPPORTED: back_deployment_runtime
14+
15+
// UNSUPPORTED: OS=windows-msvc
16+
17+
import Distributed
18+
import FakeDistributedActorSystems
19+
20+
typealias DefaultDistributedActorSystem = FakeRoundtripActorSystem
21+
22+
struct Outer: Sendable, Codable {
23+
distributed actor Greeter<Element> where Element: Sendable & Codable {
24+
distributed func hello() -> String {
25+
return "Hello, \(Element.self)!"
26+
}
27+
}
28+
}
29+
30+
struct OuterGeneric<Element>: Sendable, Codable where Element: Sendable & Codable {
31+
distributed actor Greeter {
32+
distributed func hello() -> String {
33+
return "Hello, \(Element.self)!"
34+
}
35+
}
36+
}
37+
38+
func test() async throws {
39+
let system = DefaultDistributedActorSystem()
40+
41+
do {
42+
let local = Outer.Greeter<String>(actorSystem: system)
43+
let ref = try Outer.Greeter<String>.resolve(id: local.id, using: system)
44+
let response = try await ref.hello()
45+
// CHECK: > encode generic sub: Swift.String
46+
// CHECK: >> remoteCall: on:main.Outer.Greeter<Swift.String>, target:Greeter.hello(), invocation:FakeInvocationEncoder(genericSubs: [Swift.String], arguments: [], returnType: Optional(Swift.String), errorType: nil), throwing:Swift.Never, returning:Swift.String
47+
print("response 1: \(response)")
48+
// CHECK: response 1: Hello, String!
49+
}
50+
51+
do {
52+
let local = OuterGeneric<String>.Greeter(actorSystem: system)
53+
let ref = try OuterGeneric<String>.Greeter.resolve(id: local.id, using: system)
54+
let response = try await ref.hello()
55+
// CHECK: > encode generic sub: Swift.String
56+
// CHECK: >> remoteCall: on:main.OuterGeneric<Swift.String>.Greeter, target:Greeter.hello(), invocation:FakeInvocationEncoder(genericSubs: [Swift.String], arguments: [], returnType: Optional(Swift.String), errorType: nil), throwing:Swift.Never, returning:Swift.String
57+
print("response 2: \(response)")
58+
// CHECK: response 2: Hello, String!
59+
}
60+
61+
62+
63+
}
64+
65+
@main struct Main {
66+
static func main() async {
67+
try! await test()
68+
}
69+
}

0 commit comments

Comments
 (0)