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 aforeach
operation (§5.4)linearizability
: a concurrent specification using logically atomic triples (§6)
Bonus:
stack_impl
: an example implementation of the stack library, satisfying the specifications instack
andtraversable_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.
lang
defines the syntax and operational semantics of the language (Fig. 1)lifting
defines the trace-related resources (seetrace_is
,hist
,trace_inv
and related lemmas) and proves the Separation Logic specifications for the trace operations (wp_emit
andwp_fresh
) (Fig. 3)adequacy
establishes the Adequacy theorem: lemmamodular_invariance
corresponds 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 }}}
, whereP
is the pre-condition,Q
the post-condition, andr
is a binder naming the return value inQ
; # x
denotes a (deep embedded) value of the programming language, for the literalx
. For instance,#()
is the "unit" value,# 3
is the integer value 3, and# "abc"
is the value for the event tag"abc"
;(a, b)%V
denotes a deep embedded value of the programming language, which is the pair of valuesa
andb
. 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, ift
is a trace (a list of events),t !! i
looks 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 evente
at the end of tracet
;[]
denotes the empty trace (i.e. the empty list), corresponding toε
in the paper;- the
trace_is
predicate 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