用大模型自动验证修复跨语言代码翻译,准确率超九成。
MatchFixAgent: Language-Agnostic Autonomous Repository-Level Code Translation Validation and Repair
- 构建多智能体框架,分步分析翻译语义一致性。
- 99.2%翻译对可判等价,60.7%与旧结果不一致时新结果正确。
- 修复能力达50.6%,远超以往18.5%,适合大规模代码迁移。
代码翻译将源代码从一种编程语言(PL)转换为另一种。验证翻译的功能等价性并必要时进行修复,是代码翻译中的关键步骤。现有自动化验证与修复方法因工程开销高且依赖不足的测试套件,难以泛化到多种编程语言,导致等价性误判和修复无效。为此,我们开发了MatchFixAgent,一个基于大语言模型(LLM)的、语言无关的仓库级代码翻译等价性验证与修复框架。MatchFixAgent采用多智能体架构,将等价性验证拆分为多个子任务,确保对翻译结果的全面、一致的语义分析。我们将其验证与修复结果与四种仓库级代码翻译技术进行了对比。结果显示,MatchFixAgent对99.2%的翻译对给出了等价性判断,其中72.8%的结果与先前工作一致;当结果不一致时,60.7%的情况下MatchFixAgent的判断为真。此外,相比先前工作18.5%的修复率,MatchFixAgent可修复50.6%的不等价翻译。
原文摘要 · Abstract (English)
Code translation transforms source code from one programming language (PL) to another. Validating the functional equivalence of translation and repairing, if necessary, are critical steps in code translation. Existing automated validation and repair approaches struggle to generalize to many PLs due to high engineering overhead, and they rely on existing and often inadequate test suites, which results in false claims of equivalence and ineffective translation repair. To bridge this gap, we develop MatchFixAgent, a large language model (LLM)-based, PL-agnostic framework for equivalence validation and repair of translations. MatchFixAgent features a multi-agent architecture that divides equivalence validation into several sub-tasks to ensure thorough and consistent semantic analysis of the translation. We compare MatchFixAgent's validation and repair results with four repository-level code translation techniques. Our results demonstrate that MatchFixAgent produces (in)equivalence verdicts for 99.2% of translation pairs, with the same equivalence validation result as prior work on 72.8% of them. When MatchFixAgent's result disagrees with prior work, we find that 60.7% of the time MatchFixAgent's result is actually correct. In addition, we show that MatchFixAgent can repair 50.6% of inequivalent translation, compared to prior work's 18.5%.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。