arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2510.08889cs.PL
收藏

通过可撤销能力实现类型状态

Typestate via Revocable Capabilities

Purdue University(普渡大学);Augusta University(奥古斯塔大学)

Songlin Jia, Craig Liu, Siyuan He, Haotian Deng, Yuyan Bao, Tiark Rompf

AI总结:

提出一种将作用域推理的简便性与命令式类型状态管理的表达力统一的方法,通过解耦能力生命周期与词法作用域,实现流敏感的能力传递与撤销,并在Scala 3中实现原型。

摘要:

安全且富有表达力地管理有状态资源是编程语言中长期存在的挑战,尤其是在存在别名的情况下。例如,基于作用域的构造(如Java的synchronized块)提供了推理的简便性,但限制了表达力和并行性。相反,命令式、流敏感的方法实现了细粒度控制,但需要复杂的类型状态分析,并常常给程序员带来显式状态跟踪的负担。在这项工作中,我们提出了一种新颖的方法,将作用域推理的简便性与命令式类型状态管理的表达力统一起来。我们的设计将传统的流不敏感能力机制扩展到流敏感设置中。特别是,我们将能力生命周期与词法作用域解耦,允许函数以流敏感的方式接收、撤销或返回能力,基于现有机制实现作用域能力编程的安全性和人体工程学。我们将我们的方法实现为Scala 3编译器的扩展,利用路径依赖类型和隐式解析来实现简洁、静态安全且富有表达力的类型状态编程。我们的原型通用地支持广泛的模式,包括文件操作、高级锁定协议、DOM构建和会话类型,表明在具有能力支持的现有语言中,通过最小扩展即可实现富有表达力且安全的类型状态管理。

英文摘要:

Managing stateful resources safely and expressively is a longstanding challenge in programming languages, especially in the presence of aliasing. For example, scope-based constructs like Java's synchronized blocks offer ease of reasoning, but they restrict expressiveness and parallelism. Conversely, imperative, flow-sensitive approaches enable fine-grained control, but they require sophisticated typestate analyses and often burden programmers with explicit state tracking. In this work, we present a novel approach that unifies the ease of scoped reasoning with the expressiveness of imperative typestate management. Our design extends traditional flow-insensitive capability mechanisms to a flow-sensitive setting. In particular, we decouple capability lifetimes from lexical scopes, allowing functions to receive, revoke, or return capabilities in a flow-sensitive manner, building on existing mechanisms 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 patterns, including file operations, advanced locking protocols, DOM construction, and session types, showing that expressive and safe typestate management can be achieved with minimal extensions to an existing language with capability support.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑