Separation Logic
Separation Logic is a refinement of Hoare Logic that adds the ability to reason about pointer manipulation, in particular Pointer Aliasing.
[2025-03-18 Tue]
Have an abstract set of heap addresses , and a set of heaps which are indexed by Finite subsets of addresses. Also have a store, which maps variables to values.
Alternatively, a heap is a Finitely Supported Partial Function .
Moreover, have a simple imperative language that is extended with allocation of cons cells, pointer dereferencing, pointer arithmetic, mutation, and deallocation.
Note that the expression language is separate from commands; this is similar to A Normal Form.
Logic is standard predicate calculus, plus:
- , which asserts that a heap is empty; note that heap scoping is delimited by a Modality.
- , which asserts that the heap contains one cell with address and contents .
- , which asserts taht the heap can be split into two disjoint halves such that holds for one part and holds for the other.
- , which asserts that if the heap is extended by a disjoint part where holds, then holds for the extended heap. This is a Right Adjoint to .
Frame Rule
The all-important frame rule lets us lift a proof of a local property into a more global property, provided that does not touch the parts of the heap that the extended property mentions.
Examples
Reversing a List
struct list_t {
int head;
list_t *tail;
}
void reverse(list_t *i) {
list_t *j = NULL;
while (i != NULL) {
list_t k = i->tail;
i->tail = j;
j = i;
i = k;
}
}
To prove that
(where
is list reversal), the invariant
doesn't get you want you need due to aliasing concerns; instead,
we need to use the the invariant
where is the separating conjunction, which asserts that the heap can be split into two disjoint halves where holds on one half and holds on the other.