Thanks for the ping @lorentey
It seems the conclusion about this got lost or confused somewhere along the way between meetings, so here's a summary about distributed actors:
- protocols in the Distributed module not going to adopt primary associated types right now,
- we are interested in adopting primary associated types, but we first need:
- some more time to mature some related language features (to lift the restrictions about necessary concrete actor system types)
- and gain some more experience using the types" in the wild"
before we commit to the primary types.
Adding the primary associated types later on has little downside, as abstracting over them like this is not common (and actually... not possible, until we improve some more generics features). And adopting right now with the idea that we'll get it right and solve the missing language features later is actually a high risk we'd like to avoid.
Having that said, we did take explicit steps in the protocol design and synthesis that powers distributed actors such that all types the actor uses are expressed as associated types (rather than e.g. typealiases which we could have done in some places), so the types are future-proof to adopt primaries when we're ready to do so
We could adopt right now for the ...Encoder
/...Decoder
/...Handler
, but since they are very much internal to actor system libraries and never really passed around or erased... we don't think it matters, and let's do them all together when we're ready.
Extra information on how and when Distributed would benefit from primary associated types -- for those curious:
Our end goal here is to be able to express the following:
protocol Greeter<SerializationRequirement>: DistributedActor<SerializationRequirement> {
distributed func hi()
}
let greeter: Greeter<Codable> // since e.g. my actor system is using Codable
Note that we're not specifying the actor system type but rather what it is using for serialization; and this way we can "swap in" a mock actor system without changing any code.
Sadly, this abstraction today is not possible and we would need to improve generics a little bit to support this in distributed actors. The reason is that some distributed actor system methods need to constrain generics using associated types, like for example (simplified): remoteCall<Success: SerializationRequirement>
where SerializationRequirement
is an associated type on the protocol.
Such constraint is not possible on today's Swift; and it forces us to always have a concrete ActorSystem at hand, so the ability that these primary associated types would give us, cannot be used because of other limitations in how the distributed calls work.
If we could we solve this type system limitation though... we would be able to allow these abstractions, and then everything will work as expected
As a minor side note: I am not yet sure if we need to expose ActorID
as primary or not... likely not, but this again we'll learn in the coming months of using distributed actors "for real"
// edit: reworded a bit