论文标题
副作用迭代器和迭代器适配器的组成推理
Compositional Reasoning for Side-effectful Iterators and Iterator Adapters
论文作者
论文摘要
迭代是一种编程操作,传统上是指顺序访问数据结构的元素。但是,现代的编程系统(例如Rust,Java和C#概括)远远超出了传统用例。它们允许将迭代器(潜在的副作用)封闭和支持迭代器组成以形成迭代器链的组成,其中链中的每个迭代器都消耗其前身的值并为其后继生成值。这种概括对模块化规范和迭代器验证以及使用它们的客户端代码构成了三个主要挑战:(1)如何模块化参数化的迭代器以及其(累积的)副作用的推理? (2)如何从其组件迭代器的规格中得出迭代链的行为? (3)如何自动化有关此类迭代器的证据? 我们介绍了使用副作用计算对模块化规范和验证高级迭代成语的第一种方法。它使用归纳性两态不变的,高阶封闭合同和类似于分离逻辑的所有权的组合解决了上述三个挑战。我们在最先进的基于SMT的Rust验证者中实施和方法。我们的评估表明,我们的方法足以表达能够处理高级和惯用的迭代成语,并且需要适度的注释开销。
Iteration is a programming operation that traditionally refers to visiting the elements of a data structure in sequence. However, modern programming systems such as Rust, Java, and C# generalise iteration far beyond the traditional use case. They allow iterators to be parameterised with (potentially side-effectful) closures and support the composition of iterators to form iterator chains, where each iterator in the chain consumes values from its predecessor and produces values for its successor. Such generalisations pose three major challenges for modular specification and verification of iterators and the client code using them: (1) How can parameterised iterators be specified modularly and their (accumulated) side effects reasoned about? (2) How can the behaviour of an iterator chain be derived from the specifications of its component iterators? (3) How can proofs about such iterators be automated? We present the first methodology for the modular specification and verification of advanced iteration idioms with side-effectful computations. It addresses the three challenges above using a combination of inductive two-state invariants, higher-order closure contracts, and separation logic-like ownership. We implement and our methodology in a state-of-the-art SMT-based Rust verifier. Our evaluation shows that our methodology is sufficiently expressive to handle advanced and idiomatic iteration idioms and requires modest annotation overhead.