Skip to content

Commit cfe6195

Browse files
authored
Merge pull request #81091 from ktoso/wip-distributed-more-spi-tests
[Distributed] Add another test for SPI Actor System
2 parents dc9939b + 1732834 commit cfe6195

File tree

2 files changed

+103
-1
lines changed

2 files changed

+103
-1
lines changed

test/Distributed/Inputs/FakeDistributedActorSystems.swift

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,80 @@ public struct FakeActorSystem: DistributedActorSystem, CustomStringConvertible {
153153
}
154154
}
155155

156+
@available(SwiftStdlib 5.7, *)
157+
//@_spi(FakeDistributedActorSystems)
158+
public struct FakeActorSystemWithSPI: DistributedActorSystem, CustomStringConvertible {
159+
public typealias ActorID = ActorAddress
160+
public typealias InvocationDecoder = FakeInvocationDecoder
161+
public typealias InvocationEncoder = FakeInvocationEncoder
162+
public typealias SerializationRequirement = Codable
163+
public typealias ResultHandler = FakeRoundtripResultHandler
164+
165+
// just so that the struct does not become "trivial"
166+
let someValue: String = ""
167+
let someValue2: String = ""
168+
let someValue3: String = ""
169+
let someValue4: String = ""
170+
171+
public init() {
172+
print("Initialized new FakeActorSystem")
173+
}
174+
175+
public func resolve<Act>(id: ActorID, as actorType: Act.Type) throws -> Act?
176+
where Act: DistributedActor,
177+
Act.ID == ActorID {
178+
nil
179+
}
180+
181+
public func assignID<Act>(_ actorType: Act.Type) -> ActorID
182+
where Act: DistributedActor,
183+
Act.ID == ActorID {
184+
ActorAddress(parse: "xxx")
185+
}
186+
187+
public func actorReady<Act>(_ actor: Act)
188+
where Act: DistributedActor,
189+
Act.ID == ActorID {
190+
}
191+
192+
public func resignID(_ id: ActorID) {
193+
}
194+
195+
public func makeInvocationEncoder() -> InvocationEncoder {
196+
.init()
197+
}
198+
199+
public func remoteCall<Act, Err, Res>(
200+
on actor: Act,
201+
target: RemoteCallTarget,
202+
invocation invocationEncoder: inout InvocationEncoder,
203+
throwing: Err.Type,
204+
returning: Res.Type
205+
) async throws -> Res
206+
where Act: DistributedActor,
207+
Act.ID == ActorID,
208+
Err: Error,
209+
Res: SerializationRequirement {
210+
throw ExecuteDistributedTargetError(message: "\(#function) not implemented.")
211+
}
212+
213+
public func remoteCallVoid<Act, Err>(
214+
on actor: Act,
215+
target: RemoteCallTarget,
216+
invocation invocationEncoder: inout InvocationEncoder,
217+
throwing: Err.Type
218+
) async throws
219+
where Act: DistributedActor,
220+
Act.ID == ActorID,
221+
Err: Error {
222+
throw ExecuteDistributedTargetError(message: "\(#function) not implemented.")
223+
}
224+
225+
public nonisolated var description: Swift.String {
226+
"\(Self.self)()"
227+
}
228+
}
229+
156230
@available(SwiftStdlib 5.7, *)
157231
public struct FakeNotLoadableAddressActorSystem: DistributedActorSystem, CustomStringConvertible {
158232
public typealias ActorID = NotLoadableActorAddress

test/Distributed/Macros/distributed_macro_expansion_DistributedProtocol_spi.swift

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
// RUN: %empty-directory(%t)
88
// RUN: %empty-directory(%t-scratch)
99

10-
// RUN: %target-swift-frontend -typecheck -verify -target %target-swift-6.0-abi-triple -plugin-path %swift-plugin-dir -I %t -dump-macro-expansions %s -dump-macro-expansions 2>&1 | %FileCheck %s
10+
// RUN: %target-swift-frontend-emit-module -emit-module-path %t/FakeDistributedActorSystems.swiftmodule -module-name FakeDistributedActorSystems -target %target-swift-6.0-abi-triple %S/../Inputs/FakeDistributedActorSystems.swift
11+
// RUN: %target-swift-frontend -typecheck -verify -target %target-swift-6.0-abi-triple -plugin-path %swift-plugin-dir -parse-as-library -I %t -dump-macro-expansions %s -dump-macro-expansions 2>&1 | %FileCheck %s --dump-input=always
1112

1213
import Distributed
14+
import FakeDistributedActorSystems
1315

1416
@Resolvable
1517
@_spi(CoolFeatures)
@@ -36,3 +38,29 @@ public protocol Greeter: DistributedActor where ActorSystem: DistributedActorSys
3638
// CHECK-NEXT: }
3739
// CHECK-NEXT: }
3840
// CHECK-NEXT: }
41+
42+
@_spi(DistributedSPIForTesting)
43+
@Resolvable
44+
public protocol GreeterWithSPISystem: DistributedActor where ActorSystem == FakeActorSystemWithSPI {
45+
distributed func greet(name: String) -> String
46+
}
47+
48+
// @Resolvable ->
49+
50+
// CHECK: @_spi(DistributedSPIForTesting)
51+
// CHECK: public distributed actor $GreeterWithSPISystem: GreeterWithSPISystem,
52+
// CHECK-NEXT: Distributed._DistributedActorStub
53+
// CHECK-NEXT: {
54+
// CHECK: public typealias ActorSystem = FakeActorSystemWithSPI
55+
// CHECK-NEXT: }
56+
57+
// CHECK: @_spi(DistributedSPIForTesting)
58+
// CHECK: extension GreeterWithSPISystem where Self: Distributed._DistributedActorStub {
59+
// CHECK: public distributed func greet(name: String) -> String {
60+
// CHECK-NEXT: if #available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) {
61+
// CHECK-NEXT: Distributed._distributedStubFatalError()
62+
// CHECK-NEXT: } else {
63+
// CHECK-NEXT: fatalError()
64+
// CHECK-NEXT: }
65+
// CHECK-NEXT: }
66+
// CHECK-NEXT: }

0 commit comments

Comments
 (0)