一句话:为词法效应处理器提出编译策略与运行时,支持多次恢复与栈分配可变状态,同时保持常数时间捕获/恢复与竞争力性能。
多次恢复(multiple resumptions)对回溯搜索与概率编程等用例至关重要,但被认为无法与栈切换等高效实现兼容。本文提出面向词法效应处理器的编译策略与运行时系统,同时支持多次恢复与栈分配可变状态。其核心是采用无垃圾引用计数,并将栈与稳定 prompt 关联,从而在恰好恢复一次时实现常数时间的续延捕获与恢复,以及常数时间的可变状态访问;需要多次恢复时则复制栈。作者在 Effekt 语言上实现 LLVM 后端,并与动态及词法效应处理器等先进系统进行性能对比。结果表明,该方法性能有竞争力,表达力提升仅带来有限开销。
While enabling use cases such as backtracking search and probabilistic programming, multiple resumptions have the reputation of being incompatible with efficient implementation techniques, such as stack switching. This paper sets out to resolve this conflict and thus bridge the gap between expressiveness and performance. To this end, we present a compilation strategy and runtime system for lexical effect handlers with support for multiple resumptions and stack-allocated mutable state. By building on garbage-free reference counting and associating stacks with stable prompts, our approach enables constant-time continuation capture and resumption when resumed exactly once, as well as constant-time state access. Nevertheless, we also support multiple resumptions by copying stacks when necessary. We practically evaluate our approach by implementing an LLVM backend for the Effekt language. A performance comparison with state-of-the-art systems, including dynamic and lexical effect handler implementations, suggests that our approach achieves competitive performance and the increased expressiveness only comes with limited overhead.
@article{paperbot3057,
title = {Multiple Resumptions and Local Mutable State, Directly},
author = {Serkan Muhcu and Philipp Schuster and Michel Steuwer and Jonathan Immanuel Brachthäuser},
journal = {Proceedings of the ACM on Programming Languages},
volume = {9},
number = {ICFP},
year = {2025},
doi = {10.1145/3747529}
}