Actor.Theory
Actor.Theory: a model of an actor's mailbox, and laws about it.
The mailbox lives in the runtime (C, compiled) and the interpreter (OCaml); no March function implements it, so these laws are about this MODEL (lemmas design §4.2). They say what the runtime promises in specs/lang/actors.md, stated so they can be proved:
A1 one sender's messages are received in the order it sent them, and no
other sender, deferral (a hot-deploy epoch hold), stash or a call
waiting inside a handler reorders them;
A2 `Actor.call` takes only its own reply: a late reply to an earlier
call cannot answer it;
A3 a monitor's `Down` is delivered at most once, and a full mailbox
never drops it.Senders, payloads, monitor refs and call ids are Ints. The runtime is tied to the model by trace conformance (design M8), which is what makes a guarantee proved (model) · tested (runtime) and never more.
The names are prefixed (ActorEnv, EnvMsg, QEnd, ...): March has one global type namespace, so a stdlib type named like a user's would collide.
Types
What arrives in a mailbox: a message (sender, payload), a monitor's Down (monitor ref), or a reply to an Actor.call (call id, value).
A mailbox, oldest first.
Functions
Enqueue into a mailbox holding at most limit messages: a full mailbox drops an ordinary message, never a Down.
A1c. A call waiting inside a handler takes only its reply: every sender's messages stay, in order.
The value of the first reply to call id, if one is queued.
A2. Once our reply is queued, nothing arriving later changes which reply we take.
A2. With no reply of ours queued yet, the reply we take is the first among later arrivals.
A call with deadline deadline whose reply arrives at t_reply returns the reply.
A2. A call returns its reply only if the reply came by the deadline.
The watched actor dies: a registered monitor r gets its Down (past any mailbox limit).
A3. A monitor's Down is delivered at most once: delivering it removes the monitor, so a second death adds nothing.
A3. A full mailbox never drops a Down.
How many Downs for monitor r are queued.
Downs in two queues add up.
A1. Another sender's message does not change what s will receive, or its order.
A1. A sender's new message is received after everything it sent before.
A sender's messages in two queues, one after the other, are its messages in each, one after the other.
The messages from sender s, in queue order.
Whether monitor r is still registered.
Laws
!monitored(unmonitor(ms, r), r)(lemmaunmonitor_gone) proved
The messages' payloads, oldest first (what a conformance test compares with what was sent).
xs followed by ys.
Laws
qcat(xs, QEnd) == xs(lemmaqcat_end) proved
Appending nothing changes nothing.
Enqueue e at the back.
How many envelopes are queued.
Replay messages set aside (a hot-deploy epoch hold, or a stash on become): they go in front, in the order they were set aside.
A1b. Replaying held messages keeps each sender's order: the held ones first, then the rest.
A2. A reply to another call, ahead of ours, is not taken as ours.
Monitor r removed (demonitor, or the death path after delivering its Down).
Laws
!monitored(unmonitor(ms, r), r)(lemmaunmonitor_gone) proved
A removed monitor is gone.
The queue after a waiting call takes its reply: only that reply leaves; everything else stays, in arrival order.