Well-Formedness
After typing, fic checks five structural conditions that no typing rule
expresses. Each one is a property the later stages rely on, and each is
reported with the declaration it concerns. They are the checks of the
CoreFi paper’s well-formedness, restricted to what a program text can
violate: WF2 over the whole system, and three conditions on process
bodies. The fifth, where a Sync channel is received, is the platform’s:
Microkit’s protected procedure call. (WF1 and the rest of WF3 are not
checked here.)
A placeholder. Well-formedness checking is still under research. The checks below are what
ficenforces today; which conditions the language needs, and how they are checked, may change.
WF2: the channel dependency graph is acyclic
A protection domain that receives from another waits for it. Draw an edge
from each receiver to the sender it waits for: a cycle is a circular wait,
a deadlock by construction. A unidirectional channel contributes one edge,
receiver to sender; a bidirectional channel (<->) contributes both, so
every bidirectional channel is a cycle. Parallel channels between one
ordered pair of PDs are one edge.
A cycle is a warning, and the program still builds:
warning: WF2 violation: channel dependency graph contains a cycle:
ping → pong → ping (via channels: ball, ball)
--> pingpong.fis:9:1
| Chan ball = ping <-> pong;
The chain of the data-diode demo, eth_outer --> dd --> eth_inner, has no
cycle and passes.
WF2 is a structural over-approximation: it also warns on programs that are
deadlock-free under a fair scheduler. When deadlock-freedom is established
another way, typically by model-checking the UPPAAL model fire build
writes with fire verify, silence the warning with --allow-wf2-cycles (or
allow_wf2_cycles = true under [run.target] in fire.toml). The
pingpong and pingpongpan demos do exactly this, and their
spec/*.q files state the deadlock property instead.
Tail recursion
A reference to a process that is already running (itself, or one that called it) must be the last thing the process does; a first call to a helper may be followed by more work. The reference then compiles to a jump back to a process’s head and the control graph stays finite; a reference to a running process followed by more work would need a return stack.
proc Notified() { ball? -> Notified(); ball! -> Skip; } // rejected
proc Notified() { ball? -> ball! -> Notified(); } // accepted
error: process `Notified` is referenced in non-tail position inside
`Notified` — its continuation would need a return stack
A default branch and receives
The default arm of a choice runs when no branch’s guard holds. A receive
beside a default is a receive outside the head (see the next section) and
a branch with no guard, so the default never runs: two warnings.
proc Pick() { c? -> Skip default Skip; } // warnings: outside the head; no guard
The notified handler is receive-headed
Microkit invokes notified with a message to handle. A process bound to
microkit.notified that receives at all should therefore begin, on every
path, with a receive (c?x) or an interrupt await (irq?N), through [],
the left of ; and a helper process’s body, and with no guard and no
default at the top. Otherwise the handler could run without consuming the
message that woke it and never return to the kernel. A branch of the head is
itself a receive, not a call to a process that receives. A notified that
never receives (a PD that only sends) needs no head.
No receive carries a guard. While a guard is false the message stays queued and the PD sleeps; if every branch of its head is closed, nothing wakes it.
@bind(microkit.notified)
proc Notified() { ball! -> ball? -> Skip; } // warning: starts with a send
@bind(microkit.notified)
proc Notified() { Skip; } // accepted: never receives
@bind(microkit.notified)
proc Notified() { ball? -> ball! -> Notified(); } // accepted
warning: process `Notified` bound to `microkit.notified` is not receive-headed:
each path at its head must begin with an unguarded receive (`c?x`) or IRQ
await (`irq?N`) — the kernel invokes it for a message; a program that
breaks this rule is outside the deadlock freedom fic guarantees
A receive or an IRQ await anywhere but the head is a warning: no notification arrives inside the invocation, so the handler would wait there for the next one, and any other notification meanwhile is dropped.
These are warnings, and the program still builds. Deadlock freedom is proved of programs whose PDs wait only at a head of unguarded receives, so a program with one of these findings is outside that guarantee.
Every choice is decided by its own guards
Outside the head, a choice is decided by its guards: each branch is
guarded, no two guards hold together, and one always holds. A default is
the guard that holds when no other does, and a lone guard is a choice of
one branch, so it must always hold.
Each choice is checked on its own guards, in every state, whatever guards
enclose it. A choice nested directly in a branch is part of that branch’s
choice; one after a ; is a choice of its own:
[b] ([g] a -> Skip [] [!g] e -> Skip) [] [!b] f -> Skip // one choice: fine
[b] (([g] a -> Skip [] [!g || !b] e -> Skip) ; k -> Skip)
[] [!b] f -> Skip // warning: the inner branches overlap when g and not b
A Sync channel is received in protected
A send on a Sync channel is a protected procedure call, which the kernel
answers by invoking the receiver’s protected and makes the caller wait on
until it returns. So these are errors, not warnings: the C has no lowering
for the first three, and the model none for the last.
- The process bound to
microkit.protectedbegins, on every path, with an unguarded receive on aSyncchannel (c?), one branch per channel. - Nothing after its head receives or awaits an interrupt: it runs to its end without waiting.
initandnotifiednever receive aSyncchannel, since its call does not notify.initnever sends on aSyncchannel: it runs before anything else, and the UPPAAL model runs it without interruption, so the callee could not answer.
After the head of protected, as after the head of notified, the guards
decide every choice: each branch is guarded, no two guards hold together,
and one always holds. A finding there is a warning.
@bind(microkit.protected)
proc Serve() { req? -> serve -> Serve(); } // accepted
@bind(microkit.protected)
proc Serve() { req? -> done? -> Skip; } // rejected: waits after the head
@bind(microkit.notified)
proc Notified() { req? -> Notified(); } // rejected: `req` is Sync
@bind(microkit.init)
proc Init() { req! -> Skip; } // rejected: a call from init
Where the checks run
fic --check runs all five after typing, and every backend assumes them.
The other outputs run fewer: WF2 runs only under --check and the image
build.
The process-body checks run first, then the entry-point binding, the
contract read and information flow; WF2 runs last
among them. The Sync receive check reads the graphs, so it runs once they
are built, beside the receive and choice checks.