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

使用 LLMs 进行验证式代码转译

Verified Code Transpilation with LLMs

Sahil Bhatia, Jie Qiu, Niranjan Hasabnis, Sanjit A. Seshia, Alvin Cheung

AI总结:

提出基于 LLM 的验证式提升方法 LLMLift,利用 LLM 推理和生成等价性证明实现代码转译,在四种 DSL 上优于符号工具且构建成本更低。

摘要:

领域特定语言(DSLs)是各种软件工作流不可或缺的一部分。这类语言提供领域特定的优化和抽象,从而提升代码可读性与可维护性。然而,要利用这些语言,开发者必须使用特定 DSL 的 API 重写现有代码。尽管大型语言模型(LLMs)在自动代码转译方面已展现出一定成效,但它们均未对转译后的代码提供任何功能正确性保证。另一种实现该任务自动化的方法是验证式提升(verified lifting),它依赖程序合成来寻找目标语言中与源语言程序功能等价的程序。尽管已针对多个应用领域开发了若干验证式提升工具,但它们要么专门针对特定的源-目标语言,要么需要深厚的领域知识专业经验才能使搜索高效。在本文中,借助 LLMs 的最新进展,我们提出了一种基于 LLM 的方法(LLMLift)来构建验证式提升工具。我们利用 LLM 对程序进行推理的能力,将给定程序转译为目标语言中对应的等价程序。此外,我们使用 LLMs 生成功能等价性证明。我们针对不同应用领域开发了面向四种不同 DSLs 的基于提升的编译器。我们的方法不仅在转译的基准数量和转译时间上均优于以往基于符号的工具,而且构建所需的工作量也大幅减少。

英文摘要:

Domain-specific languages (DSLs) are integral to various software workflows. Such languages offer domain-specific optimizations and abstractions that improve code readability and maintainability. However, leveraging these languages requires developers to rewrite existing code using the specific DSL's API. While large language models (LLMs) have shown some success in automatic code transpilation, none of them provide any functional correctness guarantees on the transpiled code. Another approach for automating this task is verified lifting, which relies on program synthesis to find programs in the target language that are functionally equivalent to the source language program. While several verified lifting tools have been developed for various application domains, they are specialized for specific source-target languages or require significant expertise in domain knowledge to make the search efficient. In this paper, leveraging recent advances in LLMs, we propose an LLM-based approach (LLMLift) to building verified lifting tools. We use the LLM's capabilities to reason about programs to translate a given program into its corresponding equivalent in the target language. Additionally, we use LLMs to generate proofs for functional equivalence. We develop lifting-based compilers for {\em four different} DSLs targeting different application domains. Our approach not only outperforms previous symbolic-based tools in both the number of benchmarks transpiled and transpilation time, but also requires significantly less effort to build.

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

↑