ChatPaper.aiChatPaper

EVOC2RUST: Un Framework Guidato da Scheletri per la Traduzione da C a Rust a Livello di Progetto

EVOC2RUST: A Skeleton-guided Framework for Project-Level C-to-Rust Translation

August 6, 2025
Autori: Chaofan Wang, Tingrui Yu, Jie Wang, Dong Chen, Wenrui Zhang, Yuling Shi, Xiaodong Gu, Beijun Shen
cs.AI

Abstract

Le garanzie di sicurezza in fase di compilazione di Rust lo rendono ideale per sistemi critici per la sicurezza, creando una domanda per la traduzione di codebase legacy in C verso Rust. Sebbene siano emersi vari approcci per questo compito, essi affrontano compromessi intrinseci: le soluzioni basate su regole incontrano difficoltà nel soddisfare i requisiti di sicurezza del codice e di idiomaticità, mentre le soluzioni basate su LLM spesso non riescono a generare codice Rust semanticamente equivalente, a causa delle pesanti dipendenze tra i moduli nell'intera codebase. Studi recenti hanno rivelato che entrambe le soluzioni sono limitate a programmi di piccola scala. In questo articolo, proponiamo EvoC2Rust, un framework automatizzato per convertire interi progetti C in equivalenti progetti Rust. EvoC2Rust impiega una strategia di traduzione guidata da scheletri per la traduzione a livello di progetto. La pipeline è composta da tre fasi evolutive: 1) prima decompone il progetto C in moduli funzionali, utilizza un LLM potenziato dal mapping delle caratteristiche per trasformare definizioni e macro e genera stub di funzioni verificati a livello di tipo, che formano uno scheletro Rust compilabile; 2) poi traduce gradualmente la funzione, sostituendo il corrispondente segnaposto dello stub; 3) infine, ripara gli errori di compilazione integrando LLM e analisi statica. Attraverso l'aumento evolutivo, EvoC2Rust combina i vantaggi delle soluzioni basate su regole e su LLM. La nostra valutazione su benchmark open-source e sei progetti industriali dimostra la superiorità di EvoC2Rust nella traduzione a livello di progetto da C a Rust. In media, ottiene miglioramenti del 17,24% e del 14,32% rispettivamente nell'accuratezza sintattica e semantica rispetto agli approcci basati su LLM, insieme a un tasso di sicurezza del codice superiore del 96,79% rispetto agli strumenti basati su regole. A livello di modulo, EvoC2Rust raggiunge tassi di compilazione del 92,25% e di superamento dei test dell'89,53% su progetti industriali, anche per codebase complesse e funzioni lunghe.
English
Rust's compile-time safety guarantees make it ideal for safety-critical systems, creating demand for translating legacy C codebases to Rust. While various approaches have emerged for this task, they face inherent trade-offs: rule-based solutions face challenges in meeting code safety and idiomaticity requirements, while LLM-based solutions often fail to generate semantically equivalent Rust code, due to the heavy dependencies of modules across the entire codebase. Recent studies have revealed that both solutions are limited to small-scale programs. In this paper, we propose EvoC2Rust, an automated framework for converting entire C projects to equivalent Rust ones. EvoC2Rust employs a skeleton-guided translation strategy for project-level translation. The pipeline consists of three evolutionary stages: 1) it first decomposes the C project into functional modules, employs a feature-mapping-enhanced LLM to transform definitions and macros and generates type-checked function stubs, which form a compilable Rust skeleton; 2) it then incrementally translates the function, replacing the corresponding stub placeholder; 3) finally, it repairs compilation errors by integrating LLM and static analysis. Through evolutionary augmentation, EvoC2Rust combines the advantages of both rule-based and LLM-based solutions. Our evaluation on open-source benchmarks and six industrial projects demonstrates EvoC2Rust's superior performance in project-level C-to-Rust translation. On average, it achieves 17.24% and 14.32% improvements in syntax and semantic accuracy over the LLM-based approaches, along with a 96.79% higher code safety rate than the rule-based tools. At the module level, EvoC2Rust reaches 92.25% compilation and 89.53% test pass rates on industrial projects, even for complex codebases and long functions.
PDF62December 16, 2025