Certified schedules #
The theorems of Schedule.lean and World.lean are about every schedule that respects
independence. This file turns them into a check of one schedule: the one psync generated for a
given function. psync writes a certificate for each rewritten function (its statements'
footprints and effects, and the levels of chains it chose), and check decides whether that
schedule is safe. check_sound proves that when check says yes, every concurrent execution of
the schedule equals the program as written, for any meaning of the statements whose real
independence includes what the certificate claims.
This is translation validation, as in CompCert: rather than proving the macro correct for all inputs, each build's output carries a certificate that a small, proven checker accepts.
What remains assumed is exactly the hypothesis hind of check_sound: that the certificate's
footprints and effects describe the statements (checked against MIR by cargo psync check, and
the subject of the footprint-soundness work), and, for the outside world, that the commutativity
specification is sound (World.lean).
Notation used in the theorem statements #
- A certificate $c$ lists the statements' footprints and the levels of chains psync chose; $\mathrm{check}(c)$ is the decidable checker.
- $\mathrm{op}_i$ interprets statement $i$ as a step of a system $T$; $[\![ xs ]\!]_T(s)$ runs steps in order, and $\mathrm{op}_0, \ldots, \mathrm{op}_{n-1}$ is the program as written.
Certificates #
A client place, as a path of interned segments: self.groups might be [3, 7]. Two places
overlap when one is a prefix of the other (self and self.groups).
Some segments are holes: the placeholders of a format! target, such as {dir} in
format!("{dir}/cache.json"). A hole may stand for any text, so two places that first differ
where either has a hole overlap; two that first differ at ordinary segments do not. Without holes
this is exactly the prefix relation.
Equations
Instances For
Equations
Instances For
Equations
- PsyncCert.anyOverlap holes xs ys = xs.any fun (p : PsyncCert.Place) => ys.any fun (q : PsyncCert.Place) => PsyncCert.overlap holes p q
Instances For
One statement as the certificate describes it: the places it may read and write. Every one of
psync's edge rules is a place (schedule::depends; the emitter is cert_nodes in schedule.rs):
n/x: the bindingx. A statement that introduces it writes it, one that mentions it reads it (data flow, rebinding, shadowing).p/a/b: the access patha.b(conflicting accesses;aoverlapsa.b).w/<domain>/<target>: an effect on the outside world. An unknown target is the domain alone, which overlaps every target in it; a process or unknown callee iswitself.x/i: the exit of statementi. Statementiwrites it if it may exit or panic, and a later statement with a write effect (notspeculate) reads it ("may exit before").e: effect order. Every ordinary effect statement writes it.
Where psync's own rule is finer than prefixes (string-prefix targets, services named by type), the emitter rounds towards conflict, so the checker may reject a schedule psync accepted, never the reverse.
Instances For
Equations
- PsyncCert.instReprNode = { reprPrec := PsyncCert.reprNode✝ }
No edge between two statements: neither writes a place the other reads or writes.
Equations
- PsyncCert.indep holes a b = (!PsyncCert.anyOverlap holes a.writes (b.reads ++ b.writes) && !PsyncCert.anyOverlap holes b.writes a.reads)
Instances For
Equations
- PsyncCert.instReprCert = { reprPrec := PsyncCert.reprCert✝ }
The checker #
The first occurrence of x in L, splitting L around it.
Equations
Instances For
L is P with statements moved earlier only past ones independent of them.
Equations
- PsyncCert.reorderable ind [] x✝ = x✝.isEmpty
- PsyncCert.reorderable ind (x_2 :: P) x✝ = match PsyncCert.split x_2 x✝ with | none => false | some (A, B) => (A.all fun (y : Nat) => ind y x_2) && PsyncCert.reorderable ind P (A ++ B)
Instances For
The chains of one level are pairwise independent.
Equations
Instances For
The checker: every level's chains are pairwise independent, and running the levels' chains one after another is a reordering of the program past independent statements only.
Equations
- PsyncCert.check c = (c.levels.all (PsyncCert.pairwiseOK c.ind) && PsyncCert.reorderable c.ind (List.range c.nodes.length) (List.map List.flatten c.levels).flatten)
Instances For
Soundness #
$$\bigl(\forall i\,j,\ \mathrm{ind}(i,j) \Rightarrow \mathrm{op}_i \mathrel{I_T} \mathrm{op}_j\bigr) \implies \bigl(\mathrm{reorderable}(P, L) = \mathsf{true} \Rightarrow \mathrm{Reorders}_T(\mathrm{op}(P), \mathrm{op}(L))\bigr)$$
$$\bigl(\forall i\,j,\ \mathrm{ind}(i,j) \Rightarrow \mathrm{op}_i \mathrel{I_T} \mathrm{op}_j\bigr) \implies \bigl(\mathrm{pairwiseOK}(chs) = \mathsf{true} \Rightarrow \mathrm{PairwiseInd}_T(\mathrm{op}(chs))\bigr)$$
What can happen at run time: each level's chains interleave in any way (the executor's choice), and levels run one after another. No independence is assumed here.
- nil {A : Type} : Execs [] []
- cons {A : Type} {cs : List (List A)} {m : List A} {levels : List (List (List A))} {ms : List (List A)} : PsyncWorld.InterleaveAll cs m → Execs levels ms → Execs (cs :: levels) (m :: ms)
Instances For
$$(\forall cs \in \mathit{levels},\ \mathrm{PairwiseInd}_T(cs)) \;\wedge\; \mathrm{Execs}(\mathit{levels}, ms) \implies \mathrm{Runs}_T(\mathit{levels}, ms)$$
$$\bigl(\forall i\,j,\ c.\mathrm{ind}(i,j) \Rightarrow \mathrm{op}_i \mathrel{I_T} \mathrm{op}_j\bigr) \;\wedge\; \mathrm{check}(c) = \mathsf{true} \;\wedge\; \mathrm{Execs}(\mathrm{op}(c.\mathit{levels}), ms) \implies [\![ \mathrm{flatten}(ms) ]\!]_T(s) = [\![ \mathrm{op}_0, \ldots, \mathrm{op}_{n-1} ]\!]_T(s)$$
Soundness of the checker. Interpret each node i as a step op i of any system T
(client memory as in Schedule.lean, or the client and server world of World.lean). Suppose the
certificate's independence implies real independence (hind). Then if check accepts the
certificate, every run of its schedule, in any interleaving of each level, ends exactly as the
program run in order does.
Examples #
A certificate the checker accepts: profile_page (Basic concepts). user (node 0) is read by
avatar (node 2); posts and friends (1, 3) are free. psync's schedule is one level of three
chains: 0 -> 2, 1, 3. Places: user is [10], posts [11], avatar [12],
friends [13], api [20], and the service behind api [30].
Equations
- One or more equations did not get rendered due to their size.
Instances For
$$\mathrm{check}(\mathtt{profilePage}) = \mathsf{true}$$
$$\mathrm{check}(\mathtt{profilePageWrong}) = \mathsf{false}$$
Holes: two writes to format!("{dir}/a") and format!("{dir}/b") (places t {dir} / a / and
t {dir} / b /, with {dir} the hole [7]) may run side by side; a write to
format!("{other}/a") may not run beside the first, since {other} may equal {dir}.
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
$$\mathrm{check}(\mathtt{holesClash}) = \mathsf{false}$$