Drop in replacements for popular projects written in Rust?

I just came across ScyllaDB, and thought they had a clever idea, rewrite a popular library in a better language.. what if we started doing this in Rust so more people would switch over to Rust? And we give them a really easy choice: use the old version or the new version that has both high performance and high security? What projects would see benefits from being rewritten this way?

There's a pretty huge unstated assumption in your question that there exists a pool of people with the time and expertise to do this sort of thing. And generally speaking, the people who meet those criteria are already working on the things they consider important.

4 Likes

I have often heard it said that one should not consider rewriting code in a new language just because ooo, new language.

Especially if it is a large and complicated thing. That takes a lot f time. It will introduce all kind of new bugs that will need to be fixed. A huge amount of work that does not necessarily gain you anything and diverts effort from creating new things.

Not only that, the old libraries are not going to go away any time soon. There will be C code and C coders around for decades more, perhaps forever. So now we have two versions of the same thing to maintain and move forward in different languages.

There has to be a very compelling reason to rewrite such things.

Luckily a lot of what we need is written in C so it's very advantageous that a new language inter-operates with C easily so that it can make use of what exists.

Which I gather is exactly what Rust does.

Better to get along and coexist with what already exists already in some kind of "symbiosis" than to try and kill off and replace everything. Upsetting a lot of people along the way.

2 Likes

C2Rust (a C to Rust transpiler) is specifically designed for this kind of thing - they've gone to great lengths to ensure that the output Rust code is functionally identical to the original C (the idea being that you could incrementally refactor it into more safe/idiomatic Rust).

They actually managed to build and run a pure Rust version of Quake 3 last month, with some minimal by-hand fixes :slight_smile:

9 Likes

I think the OP is asking if there are any projects that would benefit in a large way from being rewritten in Rust. His example ScyllaDB is a rewrite of Cassandra. Going from Java to C++ and most likely some architectural changes gave huge improvements in performance. From ScyllaDB website, it seems like a lot of people are getting lower latency while also needing less servers (saving them tons of money). These are clear benefits.

The OP isn't saying to rewrite ScyllaDB in Rust. He is curious if anyone knows of a project that would massively benefit from being rewritten in Rust. Most likely not a C library but some less performant language.

1 Like

Wow, amazing.

One day they will have the Linux kernel transpiled to Rust.

No doubt finding a ton of bugs along the way.

Which would be nice.

Correct asafigan, find projects that could benefit from Rust. Most of Tensorflow's important stuff is run in C++, but that's an example, convert some of the python in famous Machine learning libraries to Rust.

Are there large Python or Ruby or Java projects that could benefit from being rewritten in Rust? Hadoop for example definitely needs all the speed it can get and is write in Java.

@ skyschermer I hear you on the finding the time of developer's issue. Ideally start with smaller sized projects. Or maybe just write upgrade modules for other projects to optimize and secure specific pieces of their code. I just know there are a bunch of people around here who will be working on future projects in Rust and would like this to be somewhere in the back of their mind. I'm one of them too fyi.

Plus, keep in mind that nothing stops you from selling what you build as ScyllaBD is doing for those who care about the extra oomph over the free open source version.

Nice!! How does C2Rust deal with unsafe code?

And I respect they have to start small, but hope they add C++ support at some point.

I don't think C2Rust 'deals' with unsafe code at all - for example, if I input this janky bit of C code:

void test(int value, int* pointer, int offset) {
    *(pointer + offset) = value;
}

C2Rust happily outputs Rust code that does the same thing, safety be damned:

#![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 test(mut value: libc::c_int,
                              mut pointer: *mut libc::c_int,
                              mut offset: libc::c_int) {
    *pointer.offset(offset as isize) = value;
}

Which is ugly, but it's API-compatible with the original library, and it behaves the same.

The idea is that you'd use the output of C2Rust as a starting point, and then manually convert it to 'proper' Rust code over time. It won't fix code that's already full of UB :stuck_out_tongue:

7 Likes

That's not the worst way of doing it.. Rust compiler will throw an error and not you know you need to get into the code and fix that code due to safety issues.. which means it allows you to find places in C that have memory safety issues and fix them :slight_smile:

You may also want to be aware of this project:

Has some advantages over Rust in theory.. tried playing with C2Rust last night to convert some C code to Rust.. was a pain to install and possibly doesn't work on Windows. This one is written in Rust itself and supports C++ as well as C. Still a couple issues like only being able to convert one file at a time.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.