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倍)。

0
下载
关闭预览

相关内容

代码(Code)是专知网的一个重要知识资料文档板块,旨在整理收录论文源代码、复现代码,经典工程代码等,便于用户查阅下载使用。
《大型语言模型代码生成》综述
专知会员服务
70+阅读 · 2024年6月4日
KnowledGPT:基于知识库的检索和存储访问增强大型语言模型
社区分享 | 在 Windows 下编译和使用 TensorFlow Lite
百闻不如一码!手把手教你用Python搭一个Transformer
大数据文摘
18+阅读 · 2019年4月22日
语料库构建——自然语言理解的基础
计算机研究与发展
11+阅读 · 2017年8月21日
自然语言处理(二)机器翻译 篇 (NLP: machine translation)
DeepLearning中文论坛
12+阅读 · 2015年7月1日
国家自然科学基金
18+阅读 · 2017年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
VIP会员
最新内容
2026“人工智能+”行业发展蓝皮书(附下载)
专知会员服务
7+阅读 · 今天12:11
《强化学习数学基础》
专知会员服务
4+阅读 · 今天12:07
“Maven计划”的发展演变之“Maven智能系统”应用
《无人机革命:来自俄乌战场的启示》(报告)
专知会员服务
9+阅读 · 今天6:48
《实现联合作战能力所需的技术》58页报告
专知会员服务
5+阅读 · 今天6:30
以色列运用人工智能优化空袭警报系统
专知会员服务
5+阅读 · 今天6:20
以色列在多条战线部署AI智能体
专知会员服务
7+阅读 · 今天6:12
相关基金
国家自然科学基金
18+阅读 · 2017年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
Top
微信扫码咨询专知VIP会员