This paper describes a deductive approach to synthesizing imperative programs with pointers from declarative specifications expressed in Separation Logic. Our synthesis algorithm takes as input a pair of assertions-a preand a postcondition-which describe two states of the symbolic heap, and derives a program that transforms one state into the other, guided by the shape of the heap. The program synthesis algorithm rests on the novel framework of Synthetic Separation Logic (SSL), which generalises the classical notion of heap entailment P ⊢ Q to incorporate a possibility of transforming a heap satisfying an assertion P into a heap satisfying an assertion Q. A synthesized program represents a proof term for a transforming entailment statement P Q, and the synthesis procedure corresponds to a proof search. The derived programs are, thus, correct by construction, in the sense that they satisfy the ascribed pre/postconditions, and are accompanied by complete proof derivations, which can be checked independently.We have implemented a proof search engine for SSL in a form the program synthesizer called S SL . For efficiency, the engine exploits properties of SSL rules, such as invertibility and commutativity of rule applications on separate heaps, to prune the space of derivations it has to consider. We explain and showcase the use of SSL on characteristic examples, describe the design of S SL , and report on our experience of using it to synthesize a series of benchmark programs manipulating heap-based linked data structures.
Nadia Polikarpova and Ilya Sergeythe proof search is guided by a goal in ordinary logics. In this work, we make this connection explicit and employ it for efficiently synthesizing imperative programs from SL pre-and postconditions.Structuring the Synthesis of Heap-Manipulating Programs :3 (reads as "the assertion P transforms into Q via a program c"), which unifies SL entailment P ⊢ Q and verification {P} c {Q}, with the former expressible as P Q| skip.The central practical contribution is the design and implementation of S SL -a deductive synthesizer for heap-manipulating programs, based on SSL. S SL takes as its input a library of inductive predicates, a (typically empty) list of auxiliary function specifications, and an SL specification of the function to be synthesized. It returns a-possibly recursive, but loop-free-program (in a minimalistic C-like language), which provably satisfies the given specification.Our evaluation shows that S SL can synthesize all structurally-recursive benchmarks from previous work on heap-based synthesis (Qiu and Solar-Lezama 2017), without any sketches and in most cases much faster. To the best of our knowledge, it is also the first synthesizer to automatically discover the implementations of copying linked lists and trees, and flattening a tree to a list.The essence of S SL 's synthesis algorithm is a backtracking search in the space of SSL derivations. Even though the structural constraints (i.e., the shape of the heap) embodied in the synthesis rules already pru...