一句话:提出 DepTrans,用强化对齐训练与依赖引导迭代精化实现仓库级 C 到 Rust 翻译。
将 C 代码迁移到 Rust 对提升软件安全性且不牺牲性能至关重要。规则方法难以应对多样的 C 惯用法,生成的 Rust 代码不地道且僵化;基于 LLM 的方法虽有跨语言泛化优势,却难以处理跨文件引用、仓库级翻译的语法正确性与功能等价性验证,且缺乏大规模 C-Rust 平行数据。为此,论文提出 DepTrans,将模型能力增强与结构化推理框架相结合:首先通过强化对齐语法训练,利用多任务微调与反馈驱动的强化学习提升模型内在生成能力;再基于增强后的基础模型,用依赖引导迭代精化模块识别细粒度跨文件依赖作为丰富上下文,并迭代精化生成的 Rust 代码以保证语法正确与功能等价。为支持训练与评估,作者构建了 85k 训练样本和 145 个仓库级实例的基准。实验表明,DepTrans 编译成功率达 60.7%,计算准确率达 43.5%,分别超出最强基线 22.8% 和 17.3%;并在华为内部 15 个工业级 C 项目中成功构建 7 个,展示了企业级迁移潜力。
Automating C-to-Rust migration is critical for enhancing software security without compromising performance. Traditional rule-based methods often struggle with diverse C idioms, yielding unidiomatic and rigid Rust translations. In contrast, Large Language Models (LLMs), enriched by massive code corpora, offer a superior alternative due to their cross-language generalization, enabling the generation of idiomatic and maintainable Rust code. However, applying LLMs to C-to-Rust migration still poses several challenges. First, existing LLM-based approaches fail to adequately handle cross-file references. They either overlook the dependencies or incorporate entire files as context, thereby hindering the model's ability to accurately capture dependency information for translation. Second, the complex dependencies and structured inputs/outputs make it difficult to validate the syntactic correctness and functional equivalence of repository-level translations. Furthermore, the scarcity of large-scale C-Rust parallel data constrains the inherent generation capabilities of LLMs, resulting in limited performance. To address these challenges, we propose DepTrans, which synergizes model-level capability enhancement with a structured inference framework. DepTrans first employs the Reinforcement-Aligned Syntax Training module to bolster the model's intrinsic generation capabilities through multi-task fine-tuning and feedback-driven reinforcement learning. Building upon this enhanced foundation model, the Dependency-Guided Iterative Refinement module identifies the fine-grained cross-file dependencies as enriched context for the initial translation, and further iteratively refines the generated Rust code to ensure the syntactic correctness and functional equivalence. To facilitate the model training and repository-level evaluation, we construct a large-scale corpus of 85k training samples and a specialized benchmark of 145 repository-level instances. Experimental results show that DepTrans achieves a compilation success rate of 60.7% and a computational accuracy of 43.5%, outperforming the strongest baseline by 22.8% and 17.3%, respectively. Moreover, DepTrans successfully builds 7 out of 15 industrial-scale C projects from Huawei's internal codebase, demonstrating its potential in enterprise-level C-to-Rust migration.
DOI 原文 · arXiv · PDF(开放获取) · DBLP
@inproceedings{abs-2604-02852,
title = {Dependency-Guided Repository-Level C-to-Rust Translation with Reinforcement Alignment},
author = {Jia Feng and Wenjie Gan and Cuiyun Gao and Chaozheng Wang and Feng Luo and Xin Xia and Ge Li and Kui Liu},
booktitle = {FSE},
year = {2026},
doi = {10.1145/3803437.3805266}
}