一句话:将尾调用优化扩展到异步调用,提出 TMA 变换,避免多余任务,并可与 TMC 结合实现并行且空间优化的递归函数。
异步编程中的尾递归函数常因异步调用创建任务而无法获得尾调用优化,带来额外任务与空间开销。本文提出 TMA(Tail Modulo Async-Await),一种针对异步尾递归函数的代码变换,避免创建不必要的任务;并将 TMA 与已有的 TMC(Tail Modulo Constructors)优化结合,使构造子下含多个尾调用的递归函数被转换为并行版本,同时获得空间优化。作者在代表性演算上形式化这两种优化,并通过反向模拟证明其正确性。最后实现 OCaml 语法扩展原型,实验表明该方案能同时优化内存占用与执行时间。
This article extends tail-call optimisation by applying it to asynchronous calls. We first introduce TMA, a novel code transformation for asynchronous tail recursive functions that prevents the creation of unnecessary tasks. We then show how to combine TMA with the existing TMC optimisation; we obtain an optimisation able to turn a recursive function with multiple tail calls under constructors into a parallel version of the function, also optimised in space. We formalise both optimisations over representative calculi, and prove them correct through backward simulations. Finally, we provide a proof-of-concept implementation as an OCaml syntax extension and evaluate it experimentally, showing our approach optimises both memory and execution time
@article{NardinoHRZ26,
title = {Tail Modulo Async-Await},
author = {Emma Nardino and Ludovic Henrio and Gabriel Radanne and Yannick Zakowski},
journal = {Proceedings of the ACM on Programming Languages},
volume = {10},
number = {ICFP},
year = {2026},
doi = {10.1145/3828684}
}