Sujet : C to Rust translation
De : seaohveh (at) *nospam* hoffmanlabs.invalid (Stephen Hoffman)
Groupes : comp.os.vmsDate : 04. Jan 2025, 19:42:35
Autres entêtes
Organisation : HoffmanLabs LLC
Message-ID : <vlbver$j2no$1@dont-email.me>
User-Agent : Unison/2.2
Apropos of nothing, a recently-announced tool for translating C to Rust.
https://arxiv.org/abs/2412.15042"The popularity of the Rust language continues to explode; yet, many critical codebases remain authored in C, and cannot be realistically rewritten by hand. Automatically translating C to Rust is thus an appealing course of action. Several works have gone down this path, handling an ever-increasing subset of C through a variety of Rust features, such as unsafe. While the prospect of automation is appealing, producing code that relies on unsafe negates the memory safety guarantees offered by Rust, and therefore the main advantages of porting existing codebases to memory-safe languages.
We instead explore a different path, and explore what it would take to translate C to safe Rust; that is, to produce code that is trivially memory safe, because it abides by Rust's type system without caveats. Our work sports several original contributions: a type-directed translation from (a subset of) C to safe Rust; a novel static analysis based on "split trees" that allows expressing C's pointer arithmetic using Rust's slices and splitting operations; an analysis that infers exactly which borrows need to be mutable; and a compilation strategy for C's struct types that is compatible with Rust's distinction between non-owned and owned allocations."
Rust and Zig are among the language choices available for those looking to increntally translate and incrementally replace C source code with something else. Swift interoperates with C and C++ code well too, but that's mostly targeting Apple platforms.
https://ziglang.org-- Pure Personal Opinion | HoffmanLabs LLC