Software Engineering

Multiple Resumptions and Local Mutable State, Directly

by Serkan Muhcu, Philipp Schuster, Michel Steuwer, and Jonathan Brachthäuser

In Proceedings of the International Conference on Functional Programming (ICFP), 2025.

Abstract

While enabling use cases such as backtracking search and probabilistic programming, multiple resumptions have the reputation of being fundamentally 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.