5 ms·
I looked for the transpiled source, but I couldn't find it. I suspect it's not particularly idomatic Rust since it has to maintain all details of the C code how
by K0nserv 7y ago
I looked for the transpiled source, but I couldn't find it. I suspect it's not particularly idomatic Rust since it has to maintain all details of the C code however I think it's a very promising project anyway.
The fact that they found a memory safety bug is excellent. Maybe translating old C projects to Rust via this method can be used to find memory issues as well as to aid rewriting in Rust projects.
EDIT: You can try the transpilation yourself on https://c2rust.com/ https://c2rust.com/
Here's an example of the output:
#![allow(dead_code, mutable_transmutes, non_camel_case_types, non_snake_case,
non_upper_case_globals, unused_assignments, unused_mut)]
#![register_tool(c2rust)]
#![feature(register_tool)]
#[no_mangle]
pub unsafe extern "C" fn insertion_sort(n: libc::c_int, p: *mut libc::c_int) {
let mut i: libc::c_int = 1 as libc::c_int;
while i < n {
let tmp: libc::c_int = *p.offset(i as isize);
let mut j: libc::c_int = i;
while j > 0 as libc::c_int &&
*p.offset((j - 1 as libc::c_int) as isize) > tmp {
*p.offset(j as isize) =
*p.offset((j - 1 as libc::c_int) as isize);
j -= 1
}
*p.offset(j as isize) = tmp;
i += 1
};
}
- steveklabnik 7y agoTheir plan is twofold, in my understanding: first to translate the code fairly literaly, and then second, to provide unsafe -> safe refactoring tools. As far as I know they’re still on step 1.
- K0nserv 7y agoCool, that seems like a very sensible approach. The fact that they are already uncovering memory issues in C is promising too.
- steveklabnik 7y agoYep, I think so too. That example output is more verbose than a human would write, but it’s a sensible start.
- harpocrates 7y agoStep 2 has been happening concurrently, and pretty much since the start of the project. See https://github.com/immunant/c2rust/tree/master/c2rust-refactor https://github.com/immunant/c2rust/tree/master/c2rust-refact.... It is just a lot tougher to get right, so it gets less publicity.
- steveklabnik 7y agoAh awesome! Thanks for the link.
- mikepurvis 7y agoLooks like it's meant to enable projects similar to how the Go compiler/toolchain was initially translated (with the like-named c2go) and then gradually rewritten over time into idiomatic golang. It's easy to see that this could be a much more tenable project then a grand rewrite that has two codebases iterating forward in parallel for a time.