## Separation logic

In reference 2 below, Reynolds introduces separation logic, which is an extension of Hoare logic which permits reasoning about programs with mutable shared data structures. Assertions are extended using a *separation conjuction* that asserts that its subformulas hold for disjoint parts of the heap, and a closely related *separating implication*. Together with the definition of predicates, this extension permits the concise and flexible description of structures with controlled sharing.

The separating conjunction is a logical operation that asserts that and hold for disjoint parts of the heap. i.e. you can split the heap s.t. holds for one portion and for the other. The precise semantics are as follows:

- partial functions from locations to values. i.e. they represent a part of the heap.

In English: is true in a heap if there exist two parts of the heap and such that all of the following are true:

- and have disjoint domains
- is the union of and
- is true for all locations in
- is true for all locations in

In Hoare logic, you have rules like this {P}S{Q} where is the formula that must be true before the statement executes (the precondition) and is the formula that must be true after executes (postcondition). So what we want to do here is to infer the frame rule {P*R}S{Q*R} from {P}S{Q}, so that we can make sure that no variable occurring in is modified by . This allows you to extend the specification to the variables and parts of the heap that are actually used by (this is referred to as the *footprint* of ). As Reynolds says, the frame rule is the key to “local reasoning” about the heap. Then he quotes another paper (reference 24 in his paper):

“To understand how a program works, it should be possible for reasoning and specification to be confined to the cells that the program actually accesses. The value of any other cell will automatically remain unchanged.”

##### List example

To prove properties about a list, sequences are used as abstract values. In the following example, and denote sequences, and denotes an empty sequence. To describe the representation of a singly-linked list we write where where there is a list segment from *i* to *j* representing the sequence .

Inductive definitions:

Here a list has been generalized list segments where the separating conjunction is used to prohibit cycles within the list segment.

This is about all we covered in class. On page 10 of Reynold's paper there is an example of a removal from a linked list, when I did not present here since it's easy to follow if you just consult the notations in the paper. For those who are bored by such small examples, there is also a more involved example with the body of a while loop, where the final assertion is the invariant of the while command.

**References**

Shape analysis with inductive recursion synthesis:

- uses separation logic
- infers inductively defined predicates automatically using inductive recursion synthesis (looks at code that constructs data structure)
- truncation points: tree-like structures with 'holes'
- interprocedural analysis
- infers loop invariants and shapes for recursive procedures
- program slicing reduces the size of analyzed program, based on Steesgaard-like analysis (x.f=y with x,y same type means recursive data structure)
- no user-supplied annotations

Illustrates the depth and achievements of modern shape analysis research.