paperbot · PL 论文追踪

全部论文 待读 收藏

P2 Tail Modulo Cons, OCaml, and Relational Separation Logic

Tail Modulo Cons、OCaml 与关系分离逻辑
POPL 9(POPL)2025匹配度 2/10 · 论文是 OCaml 编译器优化(tail modulo cons)的工程实现与 Coq/Iris 机器化正确性证明,属于程序语言与形式化验证,但不涉及 LLM/Agent、ML 系统静态分析、浮点程序分析或贝叶斯程序分析,因此与研究画像核心方向关联较弱。引用 4 inbox
Clément Allain, Frédéric Bour, Basile Clément, François Pottier, Gabriel Scherer
crossref: 2026-09-10

AI 速览

一句话:在 OCaml 编译器中实现 tail modulo cons 变换,并用 Coq/Iris 机器化证明其正确性。

主流函数式语言鼓励尾递归,但 List.map 等自然递归定义会消耗栈空间,改写成尾递归风格往往更复杂也更慢。本文在 OCaml 编译器中实现了 tail modulo cons(TMC)变换,使「模构造子尾递归」的一大类函数也能获得栈效率。为证明该变换的正确性,作者在一个小的无类型演算中刻画 OCaml 实现的关键要点,并在 Coq 的 Iris 基础逻辑中完成机器化验证;作为独立贡献,工作还扩展了 Simuliris 方法,定义支持不同调用约定的模拟关系。据作者所知,这是 Simuliris 首次被用于证明编译器变换的正确性。

问题
尾递归的要求迫使程序员把 List.map 这类构造数据结构的函数改写成更复杂、更慢的形式,因为其自然定义会消耗栈空间,难以扩展到大规模输入。
方法
在 OCaml 编译器中实现 tail modulo cons(TMC)变换,并在一个刻画实现要点的小型无类型演算中,用 Coq 的 Iris 基础逻辑机器化证明其正确性;同时扩展 Simuliris,定义支持不同调用约定的模拟关系。
评估
通过在 Coq/Iris 中对简化演算进行机器化正确性证明来验证变换,并在 OCaml 编译器中实现该优化。
原文摘要(Abstract)

Common functional languages incentivize tail-recursive functions, as opposed to general recursive functions that consume stack space and may not scale to large inputs. This distinction occasionally requires writing functions in a tail-recursive style that may be more complex and slower than the natural, non-tail-recursive definition. This work describes our implementation of the tail modulo constructor (TMC) transformation in the OCaml compiler, an optimization that provides stack-efficiency for a larger class of functions — tail-recursive modulo constructors — which includes in particular the natural definition of List.map and many similar recursive data-constructing functions. We prove the correctness of this program transformation in a simplified setting — a small untyped calculus — that captures the salient aspects of the OCaml implementation. Our proof is mechanized in the Coq proof assistant, using the Iris base logic. An independent contribution of our work is an extension of the Simuliris approach to define simulation relations that support different calling conventions. To our knowledge, this is the first use of Simuliris to prove the correctness of a compiler transformation.

链接与引用

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

BibTeX
@article{paperbot3221,
  title = {Tail Modulo Cons, OCaml, and Relational Separation Logic},
  author = {Clément Allain and Frédéric Bour and Basile Clément and François Pottier and Gabriel Scherer},
  journal = {Proceedings of the ACM on Programming Languages},
  volume = {9},
  number = {POPL},
  year = {2025},
  doi = {10.1145/3704915}
}