Make the actor transport an associated type of the DistributedActor protocol.

Eliminate the required use of existentials in distributed actors by
introducing the `Transport` associated type into the
`DistributedActor` protocol. Each distributed actor has a known
(concrete) actor transport type, reducing storage requirements and
transport dynamism when it isn't needed.

Distributed actors can manually specify their `Transport` associated
type or pick up a default by looking for a type named
`DefaultActorTransport`. A library that vends an actor transport can
make create a public typealias `DefaultActorTransport` referring to
its transport, so importing that library and defining a distributed
actor will use that library's transport.

Introduce a type-erased `AnyActorTransport` type to provide an
explicitly dynamic actor transport. This is still an important option,
e.g., for cases where one wants to be able to dynamically change the
transport for testing or different kinds of deployment. For now, we
default to this transport in the library (via `DefaultActorTransport`),
but we may very well want to eliminate this because it will be
ambiguous with client libraries that vend their own
`DefaultActorTransport`.
This commit is contained in:
Doug Gregor
2021-11-01 22:11:42 -07:00
parent d682049d25
commit c2ba06c3d2
28 changed files with 255 additions and 114 deletions

View File

@@ -13,11 +13,11 @@ distributed actor Capybara { }
//distributed actor GuineaPing: Wheeker { }
@available(SwiftStdlib 5.6, *)
func test(identity: AnyActorIdentity, transport: ActorTransport) async throws {
func test(identity: AnyActorIdentity, transport: AnyActorTransport) async throws {
let _: Capybara = try Capybara.resolve(identity, using: transport)
// TODO: implement resolve being able to be called on a distributed actor protocol
// (yes, normally it is not allowed to call such function... so we need to
// discuss and figure out how we want to expose the resolve of a protocol)
// let c: Wheeker = try Wheeker.resolve(.init(identity), using: transport)
}
}