Remix.run Logo
Fervicus 10 hours ago

> We know the result isn’t idiomatic Rust, and there’s a lot that can be simplified once we’re comfortable retiring the C++ pipeline. That cleanup will come in time.

I wonder what kind of tech debt this brings and if the trade off will be worth whatever problems they were having with C++.

snowhale 10 hours ago | parent | next [-]

the tech debt risk in this case is mostly in the cleanup phase, not the port itself. non-idiomatic Rust that came from C++ tends to have a lot of raw pointer patterns and manual lifetime management that works fine but hides implicit ownership assumptions. when you go to make it idiomatic, the borrow checker forces those assumptions to be explicit, and sometimes you discover the original structure doesn't compose well with Rust's aliasing rules. servo went through this. the upside is you catch real latent bugs in the process.

surajrmal 9 hours ago | parent | next [-]

It depends. I migrated a 20k loc c++ project to rust via AI recently and I would say it did so pretty well. There is no unsafe or raw pointer usage. It did add Rc<RefCell in a bunch of places to make things happy, but that ultimately caught some real bugs in the original code. Refactoring it to avoid shared memory (and the need for Rc<RefCell<>> wasn't very difficult, but keeping the code structure identical at first allowed us to continue to work on the c++ code while the rust port was ongoing and keep the rust port aligned without needing to implement the features twice.

I would say modern c++ written by someone already familiar with rust will probably be structured in a way that's extremely easy to port because you end up modeling the borrow checker in your brain.

tonyedgecombe 9 hours ago | parent | prev [-]

Yes, I just translated a Rust library from non-idiomatic and unsafe Rust to idiomatic and safe Rust and it was as much work as if I had rewritten it from scratch.

snowhale 2 hours ago | parent | next [-]

yeah, matches what I'd expect. when you're porting idiomatic -> idiomatic within a language, the cleanup is mechanical. crossing from C++ to Rust means the borrow checker surfaces assumptions that were latent in the original code, so you end up redesigning rather than translating. that's not a complaint about Rust -- it's actually doing its job.

Fervicus 9 hours ago | parent | prev [-]

This is what I was trying to highlight in my post.

cromka 10 hours ago | parent | prev | next [-]

I don't think they were having problems with C++, they moved to Rust for memory safety. Mind that they migrated LibJS, their JavaScript library.

heliumtera 9 hours ago | parent | prev [-]

Andreas Kling mentioned many times they would prefer a safer language, specifically for their js runtime garbage collector. But since the team were already comfortable with cpp that was the choice, but they were open and active seeking alternatives.

The problem was strictly how cpp is perceived as an unsafe language, and this problem rust does solve! Not being sarcastic, this truly looks like a mature take. Like, we don't know if moving to rust would improve quality or prevent vulnerabilities, here's our best effort to find out and ignore if the claim has merits for now. If the claim maintains, well, you're better prepared, if it doesn't, but the code holds similar qualities...what is the downside?