paperbot · PL 论文追踪

全部论文 待读 收藏

P2 Verified Extraction from Coq to OCaml

从 Coq 到 OCaml 的已验证提取
PLDI 8(PLDI)2024匹配度 3/10 · 论文属于形式化验证与编译器正确性领域,与用户核心方向(面向ML/Agentic程序的静态分析、LLM/Agent改进静态分析或形式化验证、浮点/贝叶斯程序分析)无直接关联,且未涉及LLM或Agent。但论文兼具理论形式化与工程实现,属于PL形式化方法范畴,可能作为背景参考。引用 17 inbox
Yannick Forster, Matthieu Sozeau, Nicolas Tabareau
dblp: 2026-09-10crossref: 2026-09-10

AI 速览

一句话:在 Coq 中实现并验证从 Coq 到 OCaml 的提取流水线,给出正确性定理与安全互操作保证。

论文关注 Coq 到 OCaml 的 extraction:提取程序虽实用,但提取过程属于可信代码库,且与未验证代码的互操作从未被形式化。作者基于 MetaCoq(在 Coq 中重实现并验证 Coq 内核)与 Malfunction(OCaml 编译器中间语言语义)开发一条在 Coq 内实现并验证的全新提取流水线,给出明确正确性定理及安全互操作保证。工作填补文献空白,揭示 Coq 程序操作语义与 extraction 的重要差异:一阶数据类型的提取程序正确且可安全互操作,而高阶程序的简单互操作已可能导致错误行为甚至段错误。

问题
Coq 的 extraction 是 CompCert 等项目的关键,但其提取过程处于可信代码库中,与未验证代码互操作缺乏形式化保证,且现有实现与理论已有偏差。
方法
在 Coq 内基于 MetaCoq 和 Malfunction 定义并实现新的 Coq→OCaml 提取流水线,机器化验证其相对于 Coq 类型论与 OCaml 中间语言语义的正确性,并重点分析互操作安全性。
评估
通过 Coq 机制化证明给出提取正确性定理与互操作保证,区分一阶与高阶程序:前者安全正确,后者简单互操作即可导致错误行为或段错误。
原文摘要(Abstract)

One of the central claims of fame of the C oq proof assistant is extraction, i.e., the ability to obtain efficient programs in industrial programming languages such as OC aml , Haskell, or Scheme from programs written in Coq’s expressive dependent type theory. Extraction is of great practical usefulness, used crucially e.g. , in the CompCert project. However, for such executables obtained by extraction, the extraction process is part of the trusted code base (TCB), as are Coq’s kernel and the compiler used to compile the extracted code. The extraction process contains intricate semantic transformation of programs that rely on subtle operational features of both the source and target language. Its code has also evolved since the last theoretical exposition in the seminal PhD thesis of Pierre Letouzey. Furthermore, while the exact correctness statements for the execution of extracted code are described clearly in academic literature, the interoperability with unverified code has never been investigated formally, and yet is used in virtually every project relying on extraction. In this paper, we describe the development of a novel extraction pipeline from C oq to OC aml , implemented and verified in C oq itself, with a clear correctness theorem and guarantees for safe interoperability. We build our work on the M eta Coq project, which aims at decreasing the TCB of Coq’s kernel by re-implementing it in C oq itself and proving it correct w.r.t. a formal specification of Coq’s type theory in Coq. Since OC aml does not have a formal specification, we make use of the M alfunction project specifying the semantics of the intermediate language of the OC aml compiler. Our work fills some gaps in the literature and highlights important differences between the operational semantics of C oq programs and their extraction. In particular, we focus on the guarantees that can be provided for interoperability with unverified code, and prove that extracted programs of first-order data type are correct and can safely interoperate, whereas for higher-order programs already simple interoperations can lead to incorrect behaviour and even outright segfaults. CCS Concepts: • Software and its engineering → Compilers; Functional languages; Formal software verification; • Theory of computation → Type theory.

链接与引用

DOI 原文 · PDF(开放获取) · DBLP

BibTeX
@article{ForsterST24,
  title = {Verified Extraction from Coq to OCaml},
  author = {Yannick Forster and Matthieu Sozeau and Nicolas Tabareau},
  journal = {Proceedings of the ACM on Programming Languages},
  volume = {8},
  number = {PLDI},
  year = {2024},
  doi = {10.1145/3656379}
}