Correct and Complete Type Checking and Certified Erasure for Coq , in Coq
Open Access
- 27 January 2025
- journal article
- Published by Association for Computing Machinery (ACM) in Journal of the ACM
- Vol. 72 (1) , 1-74
Abstract
Coq is built around a well-delimited kernel that performs type checking for definitions in a variant of the Calculus of Inductive Constructions ( CIC ). Although the metatheory of CIC is very stable and reliable, the correctness of its implementation in Coq is less clear. Indeed, implementing an efficient type checker for CIC is a rather complex task, and many parts of the code rely on implicit invariants which can easily be broken by further evolution of the code. Therefore, on average, one critical bug has been found every year in Coq . This article presents the first implementation of a type checker for the kernel of Coq (without the module system, template polymorphism and η-conversion), which is proven sound and complete in Coq with respect to its formal specification. Note that because of Gödel’s second incompleteness theorem, there is no hope to prove completely the soundness of the specification of Coq inside Coq (in particular strong normalization), but it is possible to prove the correctness and completeness of the implementation assuming soundness of the specification, thus moving from a trusted code base (TCB) to a trusted theory base (TTB) paradigm. Our work is based on the MetaCoq project which provides meta-programming facilities to work with terms and declarations at the level of the kernel. We verify a relatively efficient type checker based on the specification of the typing relation of the Polymorphic, Cumulative Calculus of Inductive Constructions ( PCUIC ) at the basis of Coq . It is worth mentioning that during the verification process, we have found a source of incompleteness in Coq ’s official type checker, which has then been fixed in Coq 8.14 thanks to our work. In addition to the kernel implementation, another essential feature of Coq is the so-called extraction mechanism: the production of executable code in functional languages from Coq definitions. We present a verified version of this subtle type and proof erasure step, therefore enabling the verified extraction of a safe type checker for Coq in the future.Keywords
All Related Versions
Funding Information
- Marie Skíodowska-Curie (101024493)
- European Union’s Horizon 2020 Framework Programme (101002277)
This publication has 42 references indexed in Scilit:
- Loop-checking and the uniform word problem for join-semilattices with an inflationary endomorphismTheoretical Computer Science, 2022
- Towards Certified Meta-Programming with Typed Template-Coq2018
- A Verified Compiler from Isabelle/HOL to CakeML2018
- Autosubst: Reasoning with de Bruijn Terms and Parallel Substitutions2015
- Universe Polymorphism in Coq2014
- Towards a Formally Verified Proof Assistant2014
- Induction–recursion and initial algebrasAnnals of Pure and Applied Logic, 2003
- Type checking with universesTheoretical Computer Science, 1991
- The calculus of constructionsInformation and Computation, 1988
- Constructing recursion operators in intuitionistic type theoryJournal of Symbolic Computation, 1986