Reference. Tail Modulo Cons, OCaml, and Relational Separation Logic

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.

Cite

Cite as @allain_etal_tmc_2025 (helia, typst) · \cite{allain_etal_tmc_2025} (LaTeX)
BibTeX
bibtex · 11 lines
@article{allain_etal_tmc_2025,
 title = {Tail modulo cons, {OCaml}, and relational separation logic},
 author = {Allain, Cl\'ement and Bour, Fr\'ed\'eric and Cl\'ement, Basile and Pottier, Fran\c{c}ois and Scherer, Gabriel},
 year = {2025},
 month = {January},
 journal = {Proceedings of the ACM on Programming Languages},
 volume = {9},
 number = {POPL},
 pages = {2337--2363},
 url = {http://cambium.inria.fr/~fpottier/publis/tmc-popl2025.pdf}
}
hayagriva YAML (typst)
yaml · 17 lines
allain_etal_tmc_2025:
  type: article
  title: Tail modulo cons, {OCaml}, and relational separation logic
  author:
  - Allain, Clément
  - Bour, Frédéric
  - Clément, Basile
  - Pottier, François
  - Scherer, Gabriel
  date: 2025-01
  page-range: 2337-2363
  url: http://cambium.inria.fr/~fpottier/publis/tmc-popl2025.pdf
  parent:
    type: periodical
    title: Proceedings of the ACM on Programming Languages
    issue: POPL
    volume: 9
Cited by (1)

Relational Separation Logic for Compiler Verification leroy_pottier_relsep_2026

Web
Cites 23 works (5 here)
With notes (5)

Simuliris: A Separation Logic Framework for Verifying Concurrent Program Optimizations gaher_etal_simuliris_2022

Today’s compilers employ a variety of non-trivial optimizations to achieve good performance. One key trick compilers use to justify transformations of concurrent programs is to assume that the source program has no data races: if it does, they cause the program to have undefined behavior (UB) and give the compiler free rein. However, verifying correctness of optimizations that exploit this assumption is a non-trivial problem. In particular, prior work either has not proven that such optimizations preserve program termination (particularly non-obvious when considering optimizations that move instructions out of loop bodies), or has treated all synchronization operations as external functions (losing the ability to reorder instructions around them).

In this work we present Simuliris, the first simulation technique to establish termination preservation (under a fair scheduler) for a range of concurrent program transformations that exploit UB in the source language. Simuliris is based on the idea of using ownership to reason modularly about the assumptions the compiler makes about programs with well-defined behavior. This brings the benefits of concurrent separation logics to the space of verifying program transformations: we can combine powerful reasoning techniques such as framing and coinduction to perform thread-local proofs of non-trivial concurrent program optimizations. Simuliris is built on a (non-step-indexed) variant of the Coq-based Iris framework, and is thus not tied to a particular language. In addition to demonstrating the effectiveness of Simuliris on standard compiler optimizations involving data race UB, we also instantiate it with Jung et al.’s Stacked Borrows semantics for Rust and generalize their proofs of interesting type-based aliasing optimizations to account for concurrency.

PDF · DOI · pldb

Transfinite Iris: resolving an existential dilemma of step-indexed separation logic spies-2021-transfinitex

PDF · DOI · pldb

ReLoC Reloaded: A Mechanized Relational Logic for Fine-Grained Concurrency and Logical Atomicity frumin_krebbers_birkedal_reloc_2021

We present a new version of ReLoC: a relational separation logic for proving refinements of programs with higher-order state, fine-grained concurrency, polymorphism and recursive types. The core of ReLoC is its refinement judgment 𝑒≾𝑒′:𝜏, which states that a program 𝑒 refines a program 𝑒′ at type 𝜏. ReLoC provides type-directed structural rules and symbolic execution rules in separation-logic style for manipulating the judgment, whereas in prior work on refinements for languages with higher-order state and concurrency, such proofs were carried out by unfolding the judgment into its definition in the model. ReLoC’s abstract proof rules make it simpler to carry out refinement proofs, and enable us to generalize the notion of logically atomic specifications to the relational case, which we call logically atomic relational specifications. We build ReLoC on top of the Iris framework for separation logic in Coq, allowing us to leverage features of Iris to prove soundness of ReLoC, and to carry out refinement proofs in ReLoC. We implement tactics for interactive proofs in ReLoC, allowing us to mechanize several case studies in Coq, and thereby demonstrate the practicality of ReLoC. ReLoC Reloaded extends ReLoC (LICS’18) with various technical improvements, a new Coq mechanization, and support for Iris’s prophecy variables. The latter allows us to carry out refinement proofs that involve reasoning about the program’s future. We also expand ReLoC’s notion of logically atomic relational specifications with a new flavor based on the HOCAP pattern by Svendsen et al.
DOI · arXiv

A Higher-Order Logic for Concurrent Termination-Preserving Refinement tassarotti_jung_harper_2017

Compiler correctness proofs for higher-order concurrent languages are difficult: they involve establishing a termination-preserving refinement between a concurrent high-level source language and an implementation that uses low-level shared memory primitives. However, existing logics for proving concurrent refinement either neglect properties such as termination, or only handle first-order state. In this paper, we address these limitations by extending Iris, a recent higher-order concurrent separation logic, with support for reasoning about termination-preserving refinements. To demonstrate the power of these extensions, we prove the correctness of an efficient implementation of a higher-order, session-typed language. To our knowledge, this is the first program logic capable of giving a compiler correctness proof for such a language. The soundness of our extensions and our compiler correctness proof have been mechanized in Coq.
arXiv · pldb

Relational separation logic yang_relational_separation_2007

External (18)
  • The Functional Essence of Imperative Binary Search Trees (2024)
  • Destination-passing style programming: a Haskell implementation (2023)
  • Melocoton: A Program Logic for Verified Interoperability Between OCaml and C (2023)
  • Tail Recursion Modulo Context: An Equational Approach (2023)
  • Tail Modulo Cons (2021)
  • A separation logic for effect handlers (2021)
  • The Design and Formalization of Mezzo, a Permission-Based Programming Language (2016)
  • Autosubst: Reasoning with de Bruijn Terms and Parallel Substitutions (2015)
  • Compiler verification meets cross-language linking via data abstraction (2014)
  • A new concurrency model for Scala based on a declarative dataflow core (2013)
  • Unifying refinement and Hoare-style reasoning in a logic for higher-order concurrency (2013)
  • A tail-recursive machine with stack inspection (2004)
  • A functional representation of data structures with a hole (1998)
  • Multi-Paradigm Programming in Oz (1995)
  • OPAL: Design and implementation of an algebraic programming language (1994)
  • Encapsulated search for higher-order concurrent constraint programming (1994)
  • Unwinding stylized recursions into iterations (1975)
  • REMREC – A Program for Automatic Recursion Removal in Lisp (1973)
allain_etal_tmc_2025 reference entries/refs/allain_etal_tmc_2025/allain_etal_tmc_2025.hel