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.
翻译:大型语言模型(LLM)在程序翻译方面展现出潜力,特别是在将系统代码迁移至内存安全语言(如Rust)时。然而,当源程序依赖外部库时,现有方法面临困难:LLM经常产生不存在的目标API幻觉,且无法生成支持调用的导入语句;此外,当代码操作不透明的库定义类型时,验证语义等价性具有挑战性。本文提出了一种用于将具有外部依赖的Go项目翻译至Rust的翻译与验证框架。我们的方法结合了(i)将Go库API映射至Rust API的检索机制,以及(ii)跨语言验证流程——该流程通过仅从公共库API合成适配器,在验证I/O等价性之前,建立存在不透明库类型情况下的语言互操作性。我们在六个具有非平凡外部依赖的真实世界Go代码库上评估了本系统。通过实现对操作不透明库定义类型的可验证翻译,我们的方法显著提升了编译成功率与等价性验证成功率(在依赖最复杂的案例中达到100%;平均提升约2倍)。