News for hackers. Stuff that matters.
Re:Translating Quake 3 into Rust by K0nserv on Tuesday January 07, 2020 @09:55AM (#21980437)
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/

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
        };
    }
Re:Translating Quake 3 into Rust by steveklabnik on Tuesday January 07, 2020 @10:04AM (#21980530)
Their 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.
Re:Translating Quake 3 into Rust by harpocrates on Tuesday January 07, 2020 @10:51AM (#21981080)
Step 2 has been happening concurrently, and pretty much since the start of the project. See https://github.com/immunant/c2rust/tree/master/c2rust-refact.... It is just a lot tougher to get right, so it gets less publicity.
Re:Translating Quake 3 into Rust by steveklabnik on Tuesday January 07, 2020 @10:57AM (#21981134)
Ah awesome! Thanks for the link.
Re:Translating Quake 3 into Rust by K0nserv on Tuesday January 07, 2020 @10:04AM (#21980538)
Cool, that seems like a very sensible approach. The fact that they are already uncovering memory issues in C is promising too.
Re:Translating Quake 3 into Rust by steveklabnik on Tuesday January 07, 2020 @10:08AM (#21980579)
Yep, I think so too. That example output is more verbose than a human would write, but it’s a sensible start.
Re:Translating Quake 3 into Rust by mikepurvis on Tuesday January 07, 2020 @02:36PM (#21983819)
Looks 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.