论文标题
处理双向控制流:技术报告
Handling Bidirectional Control Flow: Technical Report
论文作者
论文摘要
在编写异步,事件驱动的代码的难度下,主流语言最近一直在支持各种高级控制流功能。同时,实验性语言设计建议效应处理程序是对程序员定义的控制效果,包含异常,发电机和异步的统一解决方案。尽管存在这些趋势,但复杂的控制流 - 尤其是表现出双向模式的控制流 - - 管理仍然具有挑战性。 我们引入了双向代数效应,这是一种新的编程抽象,以更自然的方式支持双向控制转移。双向效应的处理者可以提高进一步的效果,以将控制转移回启动效果的站点,并可以自己处理自己的效果。我们介绍了这种表达能力的应用,当我们推动将有效编程与对象的编程统一统一时,这种功能自然而然地脱颖而出。我们使用核心语言正式固定机制和统一,以推广以实现操作和效果处理程序。 在效应多态性的情况下,诸如异常效应的通常传播语义与模块化推理冲突 - 它打破了参数。双向加剧了问题。因此,我们着手展示基于代数效应的现有隧道语义的核心语言,它不仅是类型的安全性(没有效果没有效果),而且是抽象安全的(没有意外处理的效果)。我们设计了一个逐步索引的逻辑关系模型,并构建其参数和声音证明。这些核心结果在COQ中完全机械化。初步实验表明,作为一流的语言功能,可以有效地实现双向处理程序。
Pressed by the difficulty of writing asynchronous, event-driven code, mainstream languages have recently been building in support for a variety of advanced control-flow features. Meanwhile, experimental language designs have suggested effect handlers as a unifying solution to programmer-defined control effects, subsuming exceptions, generators, and async--await. Despite these trends, complex control flow---in particular, control flow exhibiting a bidirectional pattern---remains challenging to manage. We introduce bidirectional algebraic effects, a new programming abstraction that supports bidirectional control transfer in a more natural way. Handlers of bidirectional effects can raise further effects to transfer control back to the site where the initiating effect was raised, and can use themselves to handle their own effects. We present applications of this expressive power, which falls out naturally as we push toward the unification of effectful programming with object-oriented programming. We pin down the mechanism and the unification formally using a core language that generalizes to effect operations and effect handlers. The usual propagation semantics of control effects such as exceptions conflicts with modular reasoning in the presence of effect polymorphism---it breaks parametricity. Bidirectionality exacerbates the problem. Hence, we set out to show the core language, which builds on the existing tunneling semantics for algebraic effects, is not only type-safe (no effects go unhandled), but also abstraction-safe (no effects are accidentally handled). We devise a step-indexed logical-relations model, and construct its parametricity and soundness proofs. These core results are fully mechanized in Coq. Preliminary experiments show that as a first-class language feature, bidirectional handlers can be implemented efficiently.