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.
정적 자원 관리는 프로그래밍 언어에서 여전히 도전적인 과제이며, 이는 제어성, 표현성, 유연성 간의 긴장에서 비롯된다. 영역 기반 시스템은 어휘적 범위 영역을 통해 일괄 해제를 제공하지만, 영역과 그 자원은 모두 이등급 시민이며 범위를 벗어나거나 자유롭게 반환될 수 없다. Rust를 대표로 하는 소유권 및 선형 타입 시스템은 비어휘적 생명주기와 강력한 정적 보장을 제공하지만, 의존하는 불변량이 고차 패턴과 표현성 있는 공유를 제한한다.
본 연구는 이러한 장점들을 통합하는 새로운 타입 시스템을 제안한다. 이 시스템은 모든 힙 할당 자원을 일등급 값으로 취급하면서도 프로그래머가 세 가지 할당 모드를 통해 생명주기와 세분성을 제어할 수 있도록 한다: (1) 개별 비어휘적 참조의 신선 할당; (2) 섀도우 아레나 내에서 자원을 집단적으로 그룹화하는 후속 공동 할당; (3) 스택 규칙을 따르는 어휘적 경계 생명주기의 범위 할당. 어떤 모드를 사용하든 모든 자원은 통합 타입을 공유하며, 제네릭 추상화에서 구별되지 않아 언어의 고차 매개변수화 특성을 유지한다.
{ // 범위 시작
val a = new Ref() scoped
val c1, c2, c3 = new Ref(f) at a
c1 := x => { (!c2)(x) } // 순환 형성
c2 := x => { (!c3)(x) }
c3 := x => { (!c1)(x) }
} // {a, c1, c2, c3} 일괄 해제