Managing stateful resources safely and expressively is a longstanding challenge in programming languages, especially in the presence of aliasing. While scope-based constructs such as Java's synchronized blocks offer ease of reasoning, they restrict expressiveness and parallelism. Conversely, imperative, flow-sensitive management enables fine-grained control but demands sophisticated typestate analyses and often burdens programmers with explicit state tracking.
In this work, we present a novel approach that unifies the strengths of both paradigms by extending flow-insensitive capability mechanisms into flow-sensitive typestate tracking. Our system decouples capability lifetimes from lexical scopes, allowing functions to provide, revoke, and return capabilities in a flow-sensitive manner, based on the existing mechanisms explored for the safety and ergonomics of scoped capability programming.
We implement our approach as an extension to the Scala 3 compiler, leveraging path-dependent types and implicit resolution to enable concise, statically safe, and expressive typestate programming. Our prototype generically supports a wide range of stateful patterns, including file operations, advanced locking protocols, DOM construction, and session types. This work demonstrates that expressive and safe typestate management can be achieved with minimal extensions to existing capability-based languages, paving the way for more robust and ergonomic stateful programming.
본 논문은 취소 가능한 능력(revocable capabilities)을 통해 타입상태(typestate) 추적을 구현하는 새로운 방법을 제안한다. 이 방법은 범위 기반 안전성과 명령형 흐름 민감 관리의 표현력을 통합하며, 흐름 불민감 능력 메커니즘을 흐름 민감 타입상태 추적으로 확장하여 상태 자원 관리의 오랜 과제를 해결한다. 본 시스템은 능력 생명주기를 어휘 범위와 분리하여 함수가 흐름 민감 방식으로 능력을 제공, 취소 및 반환할 수 있도록 한다. 저자들은 Scala 3 컴파일러에서 이 방법을 구현했으며, 경로 의존 타입과 암시적 해석을 활용하여 간결하고 정적으로 안전하며 표현력 있는 타입상태 프로그래밍을 실현한다.