尾模构造器、OCaml 与关系分离逻辑
Tail Modulo Cons, OCaml, and Relational Separation Logic
AI总结:
针对函数式语言中尾递归与非尾递归函数的效率与复杂度问题,本文在 OCaml 编译器中实现尾模构造器(TMC)转换优化,扩展 Simuliris 方法并通过 Coq 机械化证明其正确性,首次将 Simuliris 用于编译器转换正确性证明。
摘要:
常见的函数式语言鼓励使用尾递归函数,而非消耗栈空间且可能无法扩展到大型输入的一般递归函数。这种区分偶尔需要以尾递归风格编写函数,而这种风格可能比自然的非尾递归定义更复杂且更慢。本文描述了我们在 OCaml 编译器中实现的*尾模构造器(TMC)*转换,这是一种优化,为更大类别的函数——尾递归*模构造器*提供栈效率,其中特别包括 `List.map` 的自然定义以及许多类似的递归数据构造函数。我们在简化环境(一种小型无类型演算)中证明了该程序转换的正确性,该环境捕获了 OCaml 实现的显著特征。我们工作的一个独立贡献是扩展了 Simuliris 方法,以定义支持不同调用约定的模拟关系。据我们所知,这是首次使用 Simuliris 证明编译器转换的正确性。
英文摘要:
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.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。