This repository contains the Coq mechanization associated with the paper "Free Theorems from Separation Logic Specifications".
The html rendering of the Coq scripts provides an easy way of navigating the development, without having to build anything. It is available online.
stack: a simple stack specification (§2)file: simple specification for a file API with open/read/close operations (§5.1)iterator: specification for an iterator over a mutable collection (§5.2)well_bracketed: specification enforcing a well-bracketing protocol (§5.3)traversable_stack: a stack specification with aforeachoperation (§5.4)linearizability: a concurrent specification using logically atomic triples (§6)
Bonus:
stack_impl: an example implementation of the stack library, satisfying the specifications instackandtraversable_stack
The heap_lang directory contains the definition of the language. It is based
on the standard cbv language of the same name shipped with Iris, extended with
the additional trace primitives and corresponding reasoning principles.
langdefines the syntax and operational semantics of the language (Fig. 1)liftingdefines the trace-related resources (seetrace_is,hist,trace_invand related lemmas) and proves the Separation Logic specifications for the trace operations (wp_emitandwp_fresh) (Fig. 3)adequacyestablishes the Adequacy theorem: lemmamodular_invariancecorresponds to Theorem 4.1.
The remaining unlisted files typically contain helper lemmas or tactics.
Some notations differ between the Coq formalization and the paper. Here is a short cheatsheet of the common Coq notations that we use:
- Hoare triples are written as
{{{ P }}} e {{{ RET r; Q }}}, wherePis the pre-condition,Qthe post-condition, andris a binder naming the return value inQ; # xdenotes a (deep embedded) value of the programming language, for the literalx. For instance,#()is the "unit" value,# 3is the integer value 3, and# "abc"is the value for the event tag"abc";(a, b)%Vdenotes a deep embedded value of the programming language, which is the pair of valuesaandb. In the paper, it is written using angle brackets⟨ a, b ⟩. This is to distinguish with(a, b)which is a pair in Coq;_ !! _corresponds to the "lookup" operation. In particular, iftis a trace (a list of events),t !! ilooks up thei-th value of the trace (and returns an option as trace might be of length less thani);_ ++ _is the list concatenation operation. We uset ++ [e]for the trace adding eventeat the end of tracet;[]denotes the empty trace (i.e. the empty list), corresponding toεin the paper;- the
trace_ispredicate corresponds to "trace" in the paper.
The development is known to build with Coq 8.9.1 to 8.12 and Iris 3.3.
The easiest way to install those is by creating a fresh local
opam switch with everything needed (check that opam
>= 2.0 is installed):
opam switch create -y --repositories=default,coq-released=https://coq.inria.fr/opam/released . ocaml-base-compiler.4.09.1
eval $(opam env)
If the invocation fails at some point, either remove the _opam directory and
re-run the command (this will redo everything), or do eval $(opam env) and
then opam install -y . (this will continue from where it failed).
Simply run:
make
make html # rebuild the html rendering of the proofs