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

健全地处理线性性

Soundly Handling Linearity

Wenhao Tang, Daniel Hillerström, Sam Lindley, J. Garrett Morris

AI总结:

提出控制流线性性方法,通过 Feffpop 和 Qeffpop 核心演算形式化并解决线性类型与效果处理器结合时的健全性漏洞,修复了 Links 中的长期问题。

摘要:

我们提出了一种将线性类型与效果处理器(effect handlers)健全结合的新方法。线性类型系统静态地确保文件句柄等资源被恰好使用一次。效果处理器提供了一种模块化编程抽象,用于实现从异常到并发等各种特性。尽管线性类型系统内置了延续被恰好调用一次的假设,但效果处理器允许延续被丢弃或被多次调用。这种不匹配导致了现有系统(如结合了线性性(用于会话类型)和效果处理器的编程语言 Links)中的健全性漏洞。我们引入了控制流线性性作为一种手段,以确保延续的使用方式符合它们所捕获的任何资源的线性性要求,从而排除了此类健全性漏洞。我们在一个配备了线性类型、效果类型和效果处理器的 System F 风格的核心演算 Feffpop 中对控制流线性性进行了形式化。我们定义了一种感知线性性的语义,以形式化地证明 Feffpop 能够保持线性值的完整性,即没有任何线性值被丢弃或重复。为了证明控制流线性性具备实用性,我们基于 Feffpop 的设计改进了 Links,从而修复了一个长期存在的健全性漏洞。最后,为了更好地展现控制流线性性的潜力,我们基于限定类型(qualified types)定义了一个 ML 风格的核心演算 Qeffpop,它不需要程序员提供注解,而是完全依赖类型推断来推断控制流线性性。线性性和效果均由限定类型来捕获。Qeffpop 克服了 Feffpop 的一系列实际局限性,支持对线性性的抽象、类型变量之间的线性性依赖,以及一种更加细粒度的控制流线性性概念。

英文摘要:

We propose a novel approach to soundly combining linear types with effect handlers. Linear type systems statically ensure that resources such as file handles are used exactly once. Effect handlers provide a modular programming abstraction for implementing features ranging from exceptions to concurrency. Whereas linear type systems bake in the assumption that continuations are invoked exactly once, effect handlers allow continuations to be discarded or invoked more than once. This mismatch leads to soundness bugs in existing systems such as the programming language Links, which combines linearity (for session types) with effect handlers. We introduce control flow linearity as a means to ensure that continuations are used in accordance with the linearity of any resources they capture, ruling out such soundness bugs. We formalise control flow linearity in a System F-style core calculus Feffpop equipped with linear types, effect types, and effect handlers. We define a linearity-aware semantics to formally prove that Feffpop preserves the integrity of linear values in the sense that no linear value is discarded or duplicated. In order to show that control flow linearity can be made practical, we adapt Links based on the design of Feffpop, in doing so fixing a long-standing soundness bug. Finally, to better expose the potential of control flow linearity, we define an ML-style core calculus Qeffpop, based on qualified types, which requires no programmer provided annotations, and instead relies entirely on type inference to infer control flow linearity. Both linearity and effects are captured by qualified types. Qeffpop overcomes a number of practical limitations of Feffpop, supporting abstraction over linearity, linearity dependencies between type variables, and a much more fine-grained notion of control flow linearity.

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

↑