Copy the page URI to the clipboard
Ling, Michael; Yu, Yijun; Wu, Haitao; Wang, Yuan; Cordy, James and Hassan, Ahmed
(2022).
DOI: https://doi.org/10.1145/3510454.3528640
Abstract
Rust is a type-safe language for system programming with a compiler checking memory and concurrency safety. For a smooth transition from an existing C project, a source-to-source transpiler can auto-transform C programs into Rust using program transformation. However, existing C-to-Rust transformation tools (e.g. the open-source C2Rust transpiler project) have the drawback of preserving the unsafe semantics of C, while rewriting them in Rust's syntax. By relaxing the semantics-preserving constraints of transformations, in this paper, we present CRustS, a fully-automated source-to-source transformation approach, that increases the ratio of the transformed code passing the safety checks of the Rust compiler. Our method uses 220 new Txl source-to-source transformation rules, of which 198 are strictly semantics-preserving and 22 are semantics-approximating, thus reducing the scope of unsafe expressions and exposing more opportunities for safe Rust refactoring. Our method has been evaluated on both open-source and commercial projects, which demonstrates significantly higher safe code ratios after the transformations, with function-level safe code ratios comparable to the average level of idiomatic Rust projects.