mailbox: Phase 2 — registry resolves name/pid to a messageable actor (RFC 014)
Rip out the old name<->pid bimap; rebuild registry.rs as the live mailbox directory. A name resolves to a SINGLE actor (many-per-label is pg's job); that actor owns a SET of typed channels (channels are typed, so no single mailbox), keyed by message TypeId. Resolution: name -> pid (one actor) -> Mailbox -> channel for type M. Same name + different type parameter selects different channels of the one actor, so capability separation (§4.7) needs no new type. - register<M>(Name<M>, Sender<M>): captures the current actor's channel under a name (one step, per decision). Adds channels cumulatively; NameTaken only vs a different LIVE holder; stale/dangling bindings pruned on contact. - send<M>(Name<M>, msg): the payoff — resolve, clone the Sender UNDER the Leaf lock, release, then send (Leaf -> Channel; a send can unpark). Returns the msg on Unresolved / NoChannel / Closed. - whereis -> single live pid; unregister frees only the name (mailbox/other names survive). name_of (reverse lookup) dropped — deferred to introspection. - Contained erasure: each channel is Box<dyn Any+Send> filed under TypeId::of M and downcast to its own keying type, so the downcast can't fail on good data (debug-asserted via the stored type_name). Phantom M on Name re-imposes type. - One Leaf RawMutex (the fold), so a name send stays on a single Leaf — two Leaves at once is a hard panic. runtime.rs field/init unchanged (same Registry name + new()). tests/registry.rs rewritten for the new semantics: send-by-name delivery, many typed channels on one actor, same-name/different-type routing, NameTaken, takeover across slot reuse, Unresolved/NoChannel. Also fold in a Phase 1 fixup: the phantom test key was an enum whose variants tripped dead-code under the test build (only caught now that I run -D warnings on --tests). Full suite + order-checker green, warning-free across all targets.
This commit is contained in:
+1
-1
@@ -177,7 +177,7 @@ mod typed_addr_tests {
|
||||
|
||||
// A stand-in actor type with one message type, exercising `Addressable`.
|
||||
struct Counter;
|
||||
enum CounterMsg { Inc, Get }
|
||||
struct CounterMsg; // used only as a phantom key; no variants needed
|
||||
impl Addressable for Counter {
|
||||
type Msg = CounterMsg;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user