arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2502.18917cs.AIcs.PLcs.SE
收藏

ClassInvGen:利用大语言模型进行类不变式合成

ClassInvGen: Class Invariant Synthesis using Large Language Models

Stanford University(斯坦福大学);Microsoft Research(微软研究院);Purdue University(普渡大学)

Chuyue Sun, Viraj Agashe, Saikat Chakraborty, Jubi Taneja, Clark Barrett, David Dill, Xiaokang Qiu, Shuvendu K. Lahiri

AI总结:

本文提出ClassInvGen,利用大语言模型生成C++等主流语言的可执行类不变式及测试输入,优于纯LLM方法和Daikon等传统技术,提供基准测试和案例研究验证其有效性。

摘要:

形式化程序规范(预条件、后条件和类不变式)在程序构建和维护中有诸多优势。它们不仅因语义明确而有助于程序理解,还可以动态(或静态)强制执行。然而,生成高质量规范受限于规范的表达能力或需以声明式方式表达。先前工作展示了大语言模型(LLMs)在生成高质量方法预/后条件方面的潜力,但未考虑类不变式。本文提出ClassInvGen,利用LLMs合成纯函数的能力,共生成可执行类不变式和测试输入,以生成高质量的类不变式。我们展示了ClassInvGen优于纯LLM方法和Daikon等数据驱动的不变式推断技术。我们贡献了一个标准C++数据结构的基准测试集,以及一个可以利用测试和变异体测量生成规范正确性和完整性的工具。我们还通过在广泛使用的C++代码库中对多个类进行案例研究,展示了其在实际代码中的适用性。

英文摘要:

Formal program specifications in the form of preconditions, postconditions, and class invariants have several benefits for the construction and maintenance of programs. They not only aid in program understanding due to their unambiguous semantics but can also be enforced dynamically (or even statically when the language supports a formal verifier). However, synthesizing high-quality specifications in an underlying programming language is limited by the expressivity of the specifications or the need to express them in a declarative manner. Prior work has demonstrated the potential of large language models (LLMs) for synthesizing high-quality method pre/postconditions for Python and Java, but does not consider class invariants. In this work, we describe ClassInvGen, a method for co-generating executable class invariants and test inputs to produce high-quality class invariants for a mainstream language such as C++, leveraging LLMs' ability to synthesize pure functions. We show that ClassInvGen outperforms a pure LLM-based technique to generate specifications (from code) as well as prior data-driven invariant inference techniques such as Daikon. We contribute a benchmark of standard C++ data structures along with a harness that can help measure both the correctness and completeness of generated specifications using tests and mutants. We also demonstrate its applicability to real-world code by performing a case study on several classes within a widely used and high-integrity C++ codebase.

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

↑