组合推理用于有副作用的迭代器和迭代器适配器
Compositional Reasoning for Side-effectful Iterators and Iterator Adapters
AI总结:
本文提出了一种模块化规范和验证高级迭代惯用法的方法,结合了归纳不变式、闭包合同和所有权技术,用于处理有副作用的迭代器和迭代器链。
摘要:
迭代是一种编程操作,传统上指的是按顺序访问数据结构的元素。然而,现代编程系统如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.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。