๐ค AI Summary
Automatically translating C code to Rust poses significant challenges due to Rustโs strict ownership and borrowing semantics, often leading existing approaches to produce outputs containing unsafe code or violating memory safety guarantees. This work proposes AdaTrans, a novel framework that integrates policy-driven retrieval-augmented generation (RAG), an error-stratified transformation strategy (ESTS), and a multi-stage verification mechanism to ensure functional equivalence while substantially enhancing safety and correctness. Evaluated on 104 algorithmic tasks, AdaTrans achieves an average compilation success rate of 95.51%, a problem-solving success rate of 81.09%, and a remarkably low unsafe code ratio of only 1.19%, outperforming all existing translation tools across these metrics.
๐ Abstract
The automated transformation of C code to Rust is challenging due to Rust's strict ownership and borrowing semantics. While Large Language Models (LLMs) show promise, they often produce code that violates these rules or relies on unsafe constructs. We propose AdaTrans, a framework that addresses these issues through three core mechanisms: a Strategy-Driven Retrieval-Augmented Generation (RAG) mechanism to map compiler errors to specific repairs, an Error-Stratified Transformation Strategy (ESTS) that adapts its behavior based on error types, and a multi-stage validation pipeline to ensure both compilability and functional equivalence. Evaluating on a dataset of 104 algorithmic problems, AdaTrans achieves a mean compilation pass rate of 95.51% and a mean solve rate of 81.09%, significantly outperforming existing tools while maintaining an unsafe file rate of only 1.19%.