Skip to content
Coq proofs for the paper "Calculating Correct Compilers"
Coq Haskell Makefile
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
Haskell
docs
extraction
.travis.yml
Arith.v
Exceptions.v
ExceptionsTwoCont.v
Heap.v
Lambda.v
LambdaCBName.v
LambdaCBNeed.v
LambdaExceptions.v
ListIndex.v
Loop.v
Makefile
README.md
StateGlobal.v
StateGlobalSeq.v
StateLocal.v
Tactics.v
makecoq

README.md

Calculating Correct Compilers Build Status

This repository contains the supplementary material for the paper "Calculating Correct Compilers" (Journal of Functional Programming, 25, 2015) by Patrick Bahr and Graham Hutton. The material includes Coq formalisations of all calculations in the paper. In addition, we also include Coq formalisations for calculations that were mentioned but not explicitly carried out in the paper.

Paper vs. Coq Proofs

The Coq proofs proceed as the calculations in the paper. There are, however, two minor technical difference due to the nature of the Coq system.

  1. In the paper the derived VMs are tail recursive, first-order functions. The Coq system must be able to prove termination of all recursive function definitions. Since Coq's termination checker is not powerful enough to prove termination for some of the VMs (VMs from sections 3.1, 4.1, 5) or the VMs are not expected to terminate in general (VMs for lambda calculi / for language with loops), we had to define the VMs as relations instead. In particular, all VMs are defined as a small-step semantics. Each tail recursive function of a VM corresponds to a configuration constructor in the small-step semantics. As a consequence, the calculations do not prove equations, but rather instances of the relation =>>, which is the transitive, reflexive closure of the relation ==> that defines the VM.

  2. The Coq files contain the final result of the calculation, and thus do not reflect the process of discovering the definition of the compiler and the VM. That is, the files already contain the full definitions of the compiler and the virtual machine. But we used the same methodology as described in the paper to develop the Coq proofs. This is achieved by initially defining the Code data type as an empty type, defining the ==> relation as an empty relation (i.e. with no rules), and defining the compiler function using the term Admit (which corresponds to Haskell's "undefined"). This setup then allows us to calculate the definition of the Code data type, the VM, and the compiler as described in the paper.

File Structure

Below we list the relevant Coq files for the calculations in the paper:

In addition we also include calculations for the following languages:

The remaining files are used to define the Coq tactics to support reasoning in calculation style (Tactics.v) and to specify auxiliary concepts (Heap.v, ListIndex.v). We recommend using the generated documentation to browse the Coq files.

Haskell Code

Haskell definitions of the calculated compilers from the paper can be found in the Haskell sub-directory. In addtion, the extraction sub-directory contains Haskell definitions of the compilers generated from the Coq proofs using Coq's code extraction facility (see below).

Technical Details

Dependencies

  • To check the proofs: Coq 8.4pl5
  • To step through the proofs: GNU Emacs 24.3.1, Proof General 4.2

Proof Checking

The complete Coq development in this repository is proof-checked automatically. The current status is: Build Status

To check and compile the complete Coq development yourself, you can use the Makefile:

> make

Code Extraction

The Haskell definitions in the sub-directory extraction have be obtained by code extraction. The code extraction can be repeated as follows:

> make
> cd extraction
> make
Something went wrong with that request. Please try again.