paperbot · PL 论文追踪

全部论文 待读 收藏

P2 MacoCaml: Staging Composable and Compilable Macros

MacoCaml:分阶段的可组合与可编译宏
ICFP 7(ICFP)2023匹配度 2/10 · 该论文属于 PL 领域的宏、阶段分离与编译时代码生成,与用户核心关注的 AI×PL、LLM/Agent 改进静态分析/形式化验证、浮点程序分析及贝叶斯程序分析均无直接关联。虽兼具理论形式化与工程实现,但既不涉及 LLM/Agent,也不以程序分析或验证工具为对象。引用 15 inbox
Ningning Xie, Leo White, Olivier Nicole, Jeremy Yallop
crossref: 2026-09-10

AI 速览

一句话:提出 MacoCaml,一种结合宏、阶段分离和基于引用的 staging 的 OCaml 编译时代码生成设计,并给出形式化与实现。

本文提出 MacoCaml,一种为 OCaml 语言设计的编译时代码生成新方案。它创新性地结合了宏、阶段分离与基于引用的 staging:宏作为编译时绑定,表达式通过 staging 注解跨求值阶段,编译时求值发生在顶层 splice 中。作者形式化了一个类型化源演算 maco,支持交错类型检查与编译时代码生成,并带有显式编译时堆的引用和模块。研究证明了可靠性和阶段区分等关键性质。MacoCaml 已在 OCaml 编译器中实现,并通过移植两个重要库验证了其有效性。

问题
如何在 OCaml 中设计并实现一种结合宏与 staging 的编译时代码生成机制,同时保证类型安全与阶段区分?
方法
MacoCaml 将宏视为编译时绑定,利用 staging 注解实现跨阶段表达式,并在顶层 splice 中进行编译时求值;同时形式化了一个类型化源演算 maco 来建立理论基础。
评估
在 OCaml 编译器中实现了 MacoCaml,并通过移植两个重要的现有库来验证其表达能力和实用性。
原文摘要(Abstract)

We introduce MacoCaml, a new design and implementation of compile-time code generation for the OCaml language. MacoCaml features a novel combination of macros with phase separation and quotation-based staging, where macros are considered as compile-time bindings, expression cross evaluation phases using staging annotations, and compile-time evaluation happens inside top-level splices. We provide a theoretical foundation for MacoCaml by formalizing a typed source calculus maco that supports interleaving typing and compile-time code generation, references with explicit compile-time heaps, and modules. We study various crucial properties including soundness and phase distinction. We have implemented MacoCaml in the OCaml compiler, and ported two substantial existing libraries to validate our implementation.

链接与引用

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

BibTeX
@article{paperbot1907,
  title = {MacoCaml: Staging Composable and Compilable Macros},
  author = {Ningning Xie and Leo White and Olivier Nicole and Jeremy Yallop},
  journal = {Proceedings of the ACM on Programming Languages},
  volume = {7},
  number = {ICFP},
  year = {2023},
  doi = {10.1145/3607851}
}