When Lifetimes Liberate: A Type System for Arenas with Higher-Order Reachability Tracking
He, Jia, Bao et al.
Static resource management in languages remains challenging due to tensions among control, expressiveness, and flexibility. Region-based systems [Grossman et al . 2002; Tofte et al. 2001] offer bulk deallocation via lexically scoped regions, where all allocations follow a stack discipline. However, both regions and their resources are second-class, and neither can escape its scope nor be freely returned. Ownership and linear type systems, exemplified by Rust [Clarke et al. 2013], offer non-lexical lifetimes and robust static guarantees, but rely on invariants that limit higher-order patterns and expressive sharing.
In this work, we propose a new type system that unifies these strengths. Our system treats all heap-allocated resources as first-class values, while allowing programmers to control lifetime and granularity through three allocation modes: (1) fresh allocation for individual, non-lexical references; (2) subsequent coallocation grouping resources collectively within shadow arenas; and (3) scoped allocation with lexically bounded lifetimes following stack discipline. Regardless of mode, all resources share a uniform type and have no distinction for generic abstractions, preserving the higher-order parametric nature of the language.
Obtaining static safety in higher-order languages with flexible sharing is nontrivial. We address this by extending reachability types [Wei et al. 2024] to collectively track first-class resources, and by adopting flow-insensitive deallocation reasoning for selective stack discipline. These mechanisms yield Aq<: and {A}q<: atop, both formalized and proven type safe and memory safe in Rocq.
academic
When Lifetimes Liberate: A Type System for Arenas with Higher-Order Reachability Tracking
Static resource management remains challenging in programming languages, stemming primarily from tensions between controllability, expressiveness, and flexibility. Region-based systems provide bulk deallocation through lexically-scoped regions, but regions and their resources are second-class citizens that cannot escape scope or be freely returned. Ownership and linear type systems, exemplified by Rust, provide non-lexical lifetimes and strong static guarantees, but their underlying invariants restrict higher-order patterns and expressive sharing.
This work proposes a novel type system that unifies these advantages. The system treats all heap-allocated resources as first-class values while allowing programmers to control lifetimes and granularity through three allocation modes: (1) fresh allocation of individual non-lexical references; (2) co-allocation of collectively grouped resources within shadow arenas; (3) scoped allocation with lexically-bounded lifetimes following stack discipline. Regardless of allocation mode, all resources share a unified type, indistinguishable in generic abstractions, preserving the language's higher-order parametric properties.
The core problem this research addresses is implementing safe, flexible, and controllable resource management in higher-order functional languages. Traditional approaches face the following dilemmas:
Stack vs. Heap Allocation Trade-off: Stack values have strict lexical lifetimes, are safe and efficient but are inherently second-class citizens; heap allocation produces freely flowing first-class values but sacrifices predictable deallocation control.
Limitations of Existing Systems:
Region-based systems (e.g., MLKit, Cyclone): provide bulk deallocation but regions and resources are second-class citizens
Ownership type systems (e.g., Rust): provide non-lexical lifetimes but restrict higher-order patterns and expressive sharing
Reachability type systems: support higher-order functions but are constrained by telescope structures, unable to handle cyclic storage structures
The authors aim to unify the advantages of different resource management strategies: the safety of stack discipline, the expressiveness of higher-order languages, and the flexibility of treating resources as first-class entities.
Unified Resource Handling: All memory resources are first-class values with a single reference type, abstracting stack and heap allocation, allowing client code to remain generic with respect to the specific storage model of references.
Flexible Control: Memory resources can be made non-lexical or lexical through user control, can be individual or collective, with no type distinction.
Static Safety Guarantees: Reachability types track memory resource flow and ensure safe usage; users can impose selective stack discipline through flow-insensitive reasoning to guarantee predictable deallocation and freedom from use-after-free errors.
Expressive Higher-Order Features: The system supports higher-order functions with mutable sharing and cyclic storage structures, surpassing the expressiveness of previous reachability systems.
Theorem 4.1 (Progress): If [∅ | Σ] φ ⊢ t : Q and Σ ok,
then t is a value or there exist t', σ' such that t | σ → t' | σ'
Theorem 4.2 (Preservation): If a well-typed term reduces,
then there exists an extended type environment such that the
reduction result remains well-typed
{ // scope begins
val a = new Ref() scoped
val c1, c2, c3 = new Ref(f) at a
c1 := x => { (!c2)(x) } // form cycle
c2 := x => { (!c3)(x) }
c3 := x => { (!c1)(x) }
} // bulk deallocation of {a, c1, c2, c3}
Demonstrates safe construction and deallocation of cyclic reference structures.
The paper successfully unifies reachability types, arena-based resource management, and stack discipline, providing a lightweight and expressive foundation for safe resource management in higher-order languages.
Significant Theoretical Contribution: first to achieve the intersection of stack discipline, expressive sharing, first-class resources, and higher-order functions in a unified system
Outstanding Technical Innovation: shadow arenas and coarse-grained reachability tracking are important innovations
Formal Rigor: complete mechanized proofs enhance result credibility
Enhanced Expressiveness: overcomes telescope structure limitations of previous reachability type systems
This work has significant importance in programming language theory, providing new theoretical foundations for resource management and potentially influencing future programming language design. Particularly for systems programming requiring precise resource control, this approach offers new possibilities.