🤖 AI Summary
Static resource management systems—such as region types, Rust’s ownership model, and reachability types—struggle to simultaneously achieve expressiveness, memory safety, and flexible lifetime handling in higher-order functional languages: they either restrict sharing patterns, sacrifice lexical scoping guarantees, or rely on expensive flow-sensitive analysis. This paper proposes a unified type system that extends reachability types to static lifetime management for the first time, introducing a two-dimensional memory model and a lexical lifetime mechanism. It employs two orthogonal subtyping relations: (A <: B) for coarse-grained reachability and ({A} <: {B}) for fine-grained lexical lifetime constraints—enabling arbitrary sharing, non-lexical lifetimes, and higher-order polymorphism. The system is formally verified in Rocq. Our framework ensures memory safety while significantly enhancing expressivity and practicality, eliminating the need for flow-sensitive reasoning overhead.
📝 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.