When Lifetimes Liberate: A Type System for Arenas with Higher-Order Reachability Tracking
Siyuan He, Songlin Jia, Yuyan Bao, Tiark Rompf
公開日: 2025/9/4
Abstract
Static resource management in higher-order functional languages remains elusive due to tensions between control, expressiveness, and flexibility. Region-based systems [Grossman et al. 2002; Tofte et al. 2001] offer control over lifetimes and expressive in-region sharing, but restrict resources to lexical scopes. Rust, an instance of ownership types [Clarke et al. 2013], offers non-lexical lifetimes and robust safety guarantees, yet its global invariants make common sharing patterns hard to express. Reachability types [Wei et al. 2024] enable reasoning about sharing and separation, but lack practical tools for controlling resource lifetimes. In this work, we try to unify their strengths. Our solution enables grouping resources as arenas for arbitrary sharing and static guarantees of lexically scoped lifetimes. Crucially, arenas and lexical lifetimes are not the only choice: users may also manage resources individually, with non-lexical lifetimes. Regardless of mode, resources share the same type, preserving the higher-order parametric nature of the language. Obtaining static safety guarantee in a higher-order language with flexible sharing is nontrivial. To this end, we propose two new extensions atop reachability types [Wei et al. 2024]. First, A<: features a novel two-dimensional store model to enable coarse-grained reachability tracking for arbitrarily shared resources within arenas. Building on this, {A}<: establishes lexical lifetime control with static guarantees. As the first reachability formalism presented for lifetime control, {A}<: avoids the complication of flow-sensitive reasoning and retains expressive power and simplicity. Both calculi are formalized and proven type safe in Rocq.