[Distributed] Add another test for SPI Actor System

This commit is contained in:
Konrad 'ktoso' Malawski
2025-04-25 14:13:50 +09:00
parent c82502c8f0
commit 1732834d41
2 changed files with 103 additions and 1 deletions

View File

@@ -153,6 +153,80 @@ public struct FakeActorSystem: DistributedActorSystem, CustomStringConvertible {
}
}
@available(SwiftStdlib 5.7, *)
//@_spi(FakeDistributedActorSystems)
public struct FakeActorSystemWithSPI: DistributedActorSystem, CustomStringConvertible {
public typealias ActorID = ActorAddress
public typealias InvocationDecoder = FakeInvocationDecoder
public typealias InvocationEncoder = FakeInvocationEncoder
public typealias SerializationRequirement = Codable
public typealias ResultHandler = FakeRoundtripResultHandler
// just so that the struct does not become "trivial"
let someValue: String = ""
let someValue2: String = ""
let someValue3: String = ""
let someValue4: String = ""
public init() {
print("Initialized new FakeActorSystem")
}
public func resolve<Act>(id: ActorID, as actorType: Act.Type) throws -> Act?
where Act: DistributedActor,
Act.ID == ActorID {
nil
}
public func assignID<Act>(_ actorType: Act.Type) -> ActorID
where Act: DistributedActor,
Act.ID == ActorID {
ActorAddress(parse: "xxx")
}
public func actorReady<Act>(_ actor: Act)
where Act: DistributedActor,
Act.ID == ActorID {
}
public func resignID(_ id: ActorID) {
}
public func makeInvocationEncoder() -> InvocationEncoder {
.init()
}
public func remoteCall<Act, Err, Res>(
on actor: Act,
target: RemoteCallTarget,
invocation invocationEncoder: inout InvocationEncoder,
throwing: Err.Type,
returning: Res.Type
) async throws -> Res
where Act: DistributedActor,
Act.ID == ActorID,
Err: Error,
Res: SerializationRequirement {
throw ExecuteDistributedTargetError(message: "\(#function) not implemented.")
}
public func remoteCallVoid<Act, Err>(
on actor: Act,
target: RemoteCallTarget,
invocation invocationEncoder: inout InvocationEncoder,
throwing: Err.Type
) async throws
where Act: DistributedActor,
Act.ID == ActorID,
Err: Error {
throw ExecuteDistributedTargetError(message: "\(#function) not implemented.")
}
public nonisolated var description: Swift.String {
"\(Self.self)()"
}
}
@available(SwiftStdlib 5.7, *)
public struct FakeNotLoadableAddressActorSystem: DistributedActorSystem, CustomStringConvertible {
public typealias ActorID = NotLoadableActorAddress

View File

@@ -7,9 +7,11 @@
// RUN: %empty-directory(%t)
// RUN: %empty-directory(%t-scratch)
// 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
// 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
// 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
import Distributed
import FakeDistributedActorSystems
@Resolvable
@_spi(CoolFeatures)
@@ -36,3 +38,29 @@ public protocol Greeter: DistributedActor where ActorSystem: DistributedActorSys
// CHECK-NEXT: }
// CHECK-NEXT: }
// CHECK-NEXT: }
@_spi(DistributedSPIForTesting)
@Resolvable
public protocol GreeterWithSPISystem: DistributedActor where ActorSystem == FakeActorSystemWithSPI {
distributed func greet(name: String) -> String
}
// @Resolvable ->
// CHECK: @_spi(DistributedSPIForTesting)
// CHECK: public distributed actor $GreeterWithSPISystem: GreeterWithSPISystem,
// CHECK-NEXT: Distributed._DistributedActorStub
// CHECK-NEXT: {
// CHECK: public typealias ActorSystem = FakeActorSystemWithSPI
// CHECK-NEXT: }
// CHECK: @_spi(DistributedSPIForTesting)
// CHECK: extension GreeterWithSPISystem where Self: Distributed._DistributedActorStub {
// CHECK: public distributed func greet(name: String) -> String {
// CHECK-NEXT: if #available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) {
// CHECK-NEXT: Distributed._distributedStubFatalError()
// CHECK-NEXT: } else {
// CHECK-NEXT: fatalError()
// CHECK-NEXT: }
// CHECK-NEXT: }
// CHECK-NEXT: }