An Verified Optimizing Backend for a Purely Functional Language---------------------------------------------------------------------------------------------------------CertiCoq is a verified compiler for the source language of the interactivetheorem prover Coq. The goal of CertiCoq is to bridge the gap between acertified source program and the compiled executable program. Coq's sourcelanguage, Gallina, is a pure functional language without side effects. To allowprograms to interact with their environment despite the lack of side effects,CertiCoq compiles Gallina to C, where the program can be linked with C code thathandles the input and the output.
In my thesis, I focus on the design, the implementation, and the verification ofthe optimizing backend of CertiCoq, that is responsible to efficiently compileuntyped higher-order functional code to a first-order representation ready to becomplied to C. The design of the CertiCoq backend follows a micropass compilerarchitecture that consists of small compiler passes each of them performing asimple task, and optimizations in the final code rely on the interaction ofthese transformations. To prove the set of backend transformations correct, Ideveloped a proof framework based on step-indexed logical relations, a powerfulproof technique that is used to show program equivalence. The modular andcompositional nature of logical relations greatly fits the architecture of ourcompiler, allowing for proof reuse and compositional reasoning. Despite theirmathematical elegance, logical relations cannot generally be used to showcorrectness of separate compilation in multi-pass compilers. I show how ourexisting proof framework can be extended to provide guarantees not only aboutwhole-program compilation, but also about the correctness of the interaction ofprograms that are compiled separately through CertiCoq, perhaps using differentbackend optimizations. This is the first time that logical relations are used toobtain a proof of correctness for separate compilation.
In the second part of my thesis, I show how to strengthen the guarantees thatthe proof framework provides, but from a different angle. Bugs in compilersmanifest themselves not only in the final result of the computation, what weusually call functional correctness of the transformation, but also in otherobservable behaviours of the program, such as resource consumption. In order toensure that a transformation will not introduce timing and memory leaks, Iextended the logical relation framework so that it supports reasoning aboutpreservation of running time and space. I used this extended proof framework toprove that the closure conversion algorithm of CertiCoq is not only correct withrespect to the final result, but also safe for space. Furthermore, I also showthat the garbage collection strategy followed by CertiCoq is safe with respectto the idealistic space consumption model. This is the first formal proof ofspace-safety for a closure conversion algorithm and a particular garbagecollection strategy and also the first time that logical relations were used toreason about space safety.