一句话:提出 GenC2Rust,通过静态分析 C 中 void 指针的类型约束,将其翻译为使用泛型的 Rust 代码。
Rust 兼具安全保证与高性能,但大量遗留 C 代码难以直接享受这些优势,而人工重写成本高昂。现有 C 到 Rust 翻译工具因 C 抽象与惯用 Rust 抽象不匹配,常生成非惯用代码,尤其无法把 C 中多态使用的 void 指针映射为 Rust 泛型指针。本文提出翻译工具 GenC2Rust,它静态分析 C 程序中 void 指针的使用,计算类型约束,并将参数多态的 void 指针重新类型化为泛型指针,从而把非泛型 C 代码翻译为泛型 Rust 代码。作者在 42 个不同规模和领域的 C 程序上评估,验证了可扩展性与正确性,共将 4,572 个 void 指针转换为泛型,并讨论了翻译过程中的限制因素。
Rust provides an exciting combination of strong safety guarantees and high performance. Many new systems are being implemented in Rust. Nevertheless, there is a large body of existing C code that could greatly benefit from Rust's safety guarantees. Unfortunately, the manual effort required to rewrite C code into Rust is often prohibitively expensive. Researchers have explored tools to assist developers in trans-lating legacy C code into Rust code. However, the mismatch between C abstractions and idiomatic Rust abstractions makes it challenging to automatically utilize Rust's language features, resulting in non-idiomatic Rust code that requires extensive manual effort to further refactor. For example, existing tools often fail to map polymorphic uses of void pointers in C to Rust's generic pointers. In this paper, we present a translation tool, GenC2Rust, that translates non-generic C code into generic Rust code. GenC2Rust statically analyzes the use of void pointers in the C program to compute the typing constraints and then retypes the parametric polymorphic void pointers into generic pointers. We conducted an evaluation of GenC2Rust across 42 C programs that vary in size and span multiple domains to demonstrate its scalability as well as correctness. We discovered GenC2Rust has translated 4,572 void pointers to use generics. We also discuss the limiting factors encountered in the translation process.
DOI 原文 ·
@inproceedings{paperbot8729,
title = {GenC2Rust: Towards Generating Generic Rust Code from C},
author = {Xiafa Wu and Brian Demsky},
booktitle = {ICSE},
year = {2025},
doi = {10.1109/icse55347.2025.00127}
}