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

带有外部库的项目验证代码翻译

Validated Code Translation for Projects with External Libraries

Amazon Inc.(亚马逊公司);University of Bristol(布里斯托大学);National Institute of Informatics(国立情报学研究所)

Hanliang Zhang, Arindam Sharma, Cristina David, Meng Wang, Brandon Paulsen, Daniel Kroening, Wenjia Ye, Taro Sekiyama

AI总结:

本文提出一种框架,用于将依赖外部库的Go项目翻译为Rust,通过检索机制和跨语言验证流水线提高翻译和验证的准确性。

摘要:

大型语言模型(LLMs)在程序翻译方面显示出潜力,特别是在将系统代码迁移到内存安全语言如Rust时。然而,现有方法在源程序依赖外部库时遇到困难:LLMs经常虚构不存在的目标API,并未能生成调用启用的导入;此外,当代码操作不透明的库定义类型时,验证语义等价性具有挑战性。我们提出了一个翻译和验证框架,用于将依赖外部库的Go项目翻译成Rust。我们的方法结合(i)一个检索机制,将Go库API映射到Rust API,以及(ii)一个跨语言验证流水线,通过仅从公共库API合成适配器,在存在不透明库类型的情况下建立语言互操作性。我们评估了我们的系统在六个具有非平凡外部依赖的现实Go仓库上的表现。我们的方法通过启用验证翻译来操作不透明的库定义类型,显著提高了编译和等价性成功率(在最依赖性的案例中达到100%;平均约为2倍)。

英文摘要:

Large Language Models (LLMs) have shown promise for program translation, particularly for migrating systems code to memory-safe languages such as Rust. However, existing approaches struggle when source programs depend on external libraries: LLMs frequently hallucinate non-existent target APIs and fail to generate call-enabling imports; moreover, validating semantic equivalence is challenging when the code manipulates opaque, library-defined types. We present a translation and validation framework for translating Go projects with external dependencies to Rust. Our approach combines (i) a retrieval mechanism that maps Go library APIs to Rust APIs, and (ii) a cross-language validation pipeline that establishes language interoperability in the presence of opaque library types by synthesising adapters exclusively from public library APIs, prior to validating I/O equivalence. We evaluate our system on six real-world Go repositories with non-trivial external dependencies. Our approach significantly increases both the compilation and equivalence success rate (up to 100% in the most dependency-heavy case; approx. 2x on average) by enabling validated translation that manipulate opaque, library-defined types.

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

↑