Skip to content

Commit 547eb9c

Browse files
authored
Merge pull request #72180 from ktoso/wip-more-tests-generic-da
[Distributed] Add ModuleInterface test with generic distributed actor
2 parents 7f5194b + 6e4b10a commit 547eb9c

File tree

2 files changed

+73
-5
lines changed

2 files changed

+73
-5
lines changed

lib/AST/DistributedDecl.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,16 @@ Type swift::getAssociatedTypeOfDistributedSystemOfActor(
309309
auto subs = SubstitutionMap::getProtocolSubstitutions(
310310
actorProtocol, actorType->getDeclaredInterfaceType(), actorConformance);
311311

312-
return memberTy.subst(subs)->getReducedType(sig);
312+
memberTy = memberTy.subst(subs);
313+
314+
// If substitution is still not fully resolved, let's see if we can
315+
// find a concrete replacement in the generic signature.
316+
if (memberTy->hasTypeParameter() && sig) {
317+
if (auto concreteTy = sig->getConcreteType(memberTy))
318+
return concreteTy;
319+
}
320+
321+
return memberTy;
313322
}
314323

315324
/******************************************************************************/

test/ModuleInterface/distributed-actor.swift

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,43 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-emit-module-interface(%t/Library.swiftinterface) %s -module-name Library
3-
// RUN: %target-swift-typecheck-module-from-interface(%t/Library.swiftinterface) -module-name Library
2+
// RUN: split-file %s %t
3+
4+
// RUN: %target-swift-frontend -emit-module -module-name Library \
5+
// RUN: -swift-version 5 -enable-library-evolution \
6+
// RUN: -o %t/Library.swiftmodule \
7+
// RUN: -emit-module-interface-path %t/Library.swiftinterface \
8+
// RUN: %t/Library.swift
9+
10+
/// Verify the interface
411
// RUN: %FileCheck %s < %t/Library.swiftinterface
512

13+
/// Verify that we can build from the Library.swiftmodule
14+
// RUN: %target-swift-frontend -typecheck -module-name Client \
15+
// RUN: -swift-version 5 \
16+
// RUN: %t/Client.swift -I%t
17+
18+
/// Verify what we can build from a swiftinterface, when swiftmodule was deleted
19+
// RUN: rm %t/Library.swiftmodule
20+
// RUN: %target-swift-frontend -typecheck -module-name Client \
21+
// RUN: -swift-version 5 \
22+
// RUN: %t/Client.swift -I%t
23+
624
// REQUIRES: distributed
725

26+
//--- Library.swift
27+
828
import Distributed
929

1030
// CHECK-NOT: #if compiler(>=5.3) && $Actors
1131
// CHECK: @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
1232
// CHECK-NEXT: distributed public actor DA {
1333
@available(SwiftStdlib 5.7, *)
1434
public distributed actor DA {
15-
// CHECK: @_compilerInitialized nonisolated final public let id: Distributed.LocalTestingActorID
35+
// CHECK: @_compilerInitialized nonisolated final public let id: Distributed.LocalTestingDistributedActorSystem.ActorID
1636
// CHECK: nonisolated final public let actorSystem: Library.DA.ActorSystem
1737
// CHECK: public typealias ActorSystem = Distributed.LocalTestingDistributedActorSystem
1838
public typealias ActorSystem = LocalTestingDistributedActorSystem
1939

20-
// CHECK: public static func resolve(id: Distributed.LocalTestingActorID, using system: Library.DA.ActorSystem) throws -> Library.DA
40+
// CHECK: public static func resolve(id: Distributed.LocalTestingDistributedActorSystem.ActorID, using system: Library.DA.ActorSystem) throws -> Library.DA
2141
// CHECK: public typealias ID = Distributed.LocalTestingDistributedActorSystem.ActorID
2242
// CHECK: public typealias SerializationRequirement = any Swift.Decodable & Swift.Encodable
2343
// CHECK: {{@objc deinit|deinit}}
@@ -31,6 +51,27 @@ public distributed actor DA {
3151
// CHECK-NEXT: }
3252
}
3353

54+
// CHECK-NOT: #if compiler(>=5.3) && $Actors
55+
// CHECK: @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
56+
// CHECK-NEXT: distributed public actor DAG<ActorSystem> where ActorSystem : Distributed.DistributedActorSystem, ActorSystem.SerializationRequirement == any Swift.Decodable & Swift.Encodable {
57+
@available(SwiftStdlib 6.0, *)
58+
public distributed actor DAG<ActorSystem> where ActorSystem: DistributedActorSystem<any Codable> {
59+
// CHECK: @_compilerInitialized nonisolated final public let id: ActorSystem.ActorID
60+
// CHECK: nonisolated final public let actorSystem: ActorSystem
61+
62+
// CHECK: public static func resolve(id: ActorSystem.ActorID, using system: ActorSystem) throws -> Library.DAG<ActorSystem>
63+
// CHECK: public typealias ID = ActorSystem.ActorID
64+
// CHECK: public typealias SerializationRequirement = any Swift.Decodable & Swift.Encodable
65+
// CHECK: {{@objc deinit|deinit}}
66+
// CHECK: nonisolated public var hashValue: Swift.Int {
67+
// CHECK: get
68+
// CHECK: }
69+
// CHECK: public init(actorSystem system: ActorSystem)
70+
// CHECK: @available(iOS 9999, tvOS 9999, watchOS 9999, macOS 9999, *)
71+
// CHECK: @_semantics("defaultActor") nonisolated final public var unownedExecutor: _Concurrency.UnownedSerialExecutor {
72+
// CHECK: get
73+
// CHECK: }
74+
}
3475

3576
// CHECK-NOT: #if compiler(>=5.3) && $Actors
3677
// CHECK: @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
@@ -41,3 +82,21 @@ public distributed actor DA {
4182
// CHECK-NOT: #if compiler(>=5.3) && $Actors
4283
// CHECK: @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
4384
// CHECK-NEXT:extension Library.DA : Swift.Decodable {}
85+
86+
// CHECK-NOT: #if compiler(>=5.3) && $Actors
87+
// CHECK: @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
88+
// CHECK-NEXT: extension Library.DAG : Distributed.DistributedActor {}
89+
90+
//--- Client.swift
91+
92+
import Distributed
93+
import Library
94+
95+
@available(SwiftStdlib 6.0, *)
96+
func main() {
97+
let da: DA? = nil
98+
_ = da
99+
100+
let dag: DAG<LocalTestingDistributedActorSystem>? = nil
101+
_ = dag
102+
}

0 commit comments

Comments
 (0)