Top
Best
New

Posted by adius 12 hours ago

Ladybird adopts Rust(ladybird.org)
976 points | 537 commentspage 2
Fervicus 11 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||
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 10 hours ago|||
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|||
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 3 hours ago|||
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|||
This is what I was trying to highlight in my post.
cromka 10 hours ago|||
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 10 hours ago||
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?

account42 11 hours ago||
> We previously explored Swift, but the C++ interop never quite got there, and platform support outside the Apple ecosystem was limited.

Why was there ever any expectation for Swift having good platform support outside Apple? This should have been (and was to me) already obvious when they originally announced moving to Swift.

adastra22 11 hours ago||
Apple’s own marketing speak has Swift as a cross platform language. Just like, I suppose, C# is a cross platform language.

Apple puts zero resources into making that claim reality, however.

hocuspocus 10 hours ago|||
Apple actually did put some resources behind it, the toolchain is reasonably pleasant to use outside macOS and Xcode, they have people building an ecosystem in the Swift Server Workgroup, and arguably some recent language design decisions don't seem to be purely motivated by desktop/mobile usage.

But in the end I can't help but feel Swift has become an absolute beast of a multi-paradigm language with even worse compile times than Rust or C++ for dubious ergonomics gains.

adastra22 10 hours ago|||
A language is more than a compiler. All of the Swift frameworks you would need to do anything actually useful or interesting in the language are macOS-only. You cannot develop in Swift for Windows/Linux/Android the way that you develop in Swift for macOS/iOS. That matters.
hocuspocus 9 hours ago||
You don't need to convince me that Swift is poorly positioned there, but if you only care about server side (or possibly CLI) apps, the usable ecosystem on Linux isn't too shabby.

Does it make sense compared to C#, Go, Rust or a JVM language? I don't know, but it's there, and Apple put some resources behind the initiative.

adastra22 8 hours ago||
I think it is comparable to C#, at least C# a decade or more ago. Back then it was a great language for developing GUI applications on Windows, Unity games, and that's about it. Now there's a blossoming community of cross-platform frameworks, but only because Microsoft invested in making those first-class. Apple hasn't been putting that effort into Swift.
shantara 6 hours ago|||
Was it Apple, or community driven projects?
hypeatei 8 hours ago|||
> Just like, I suppose, C#

Have you actually used .NET on Linux/macOS? I have (both at home and work) and there isn't anything that made me think it was neglected on those platforms. Everything just works™

adastra22 8 hours ago||
It didn't use to be that way, for a very long time.
vips7L 6 hours ago|||
It's been 10 years of it running on Linux.
Kapendev 5 hours ago||
People here need time to notice XD
Fervicus 6 hours ago|||
When it wasn't that way, they never had any marketing speak that suggested that though?
storus 3 hours ago||
This is really YOLOing as the original author doesn't know Rust well so what happens if they hit some complex production issue LLM aren't aware of? Hiring an expensive consultant to fix that until the next LLM iteration?
drakythe 2 hours ago||
I'm as anti LLM use as they come, but this appears to be migrating libraries from already funcitoning C++ code. In the case of your hypothetical I suspect the course of action will be "shelve this library port until someone with domain expertise and Rust experience can look at it". Its not like he chucked the whole codebase at the GenaI gods and said "Port it to Rust!".
etcetera1 3 hours ago||
> what happens if they hit some complex production issue

they learn Rust

it takes a couple of years

it's not that hard.

fdefitte 3 hours ago||
The "human-directed, not autonomous" framing is the part people keep glossing over. Claude Code here is a compiler-level translation tool, you are still the architect deciding what gets ported and in what order.

The real question is what this does to migrations that never happened because 18 months of rewrite did not pencil out. A 2-week port fundamentally changes that calculus.

vipulbhj 11 hours ago||
Someone should try this with the “Ralph Wiggum loop” approach. I suspect it would fail spectacularly, but it would be fascinating to watch.

Personally, I can’t get meaningful results unless I use the tool in a true pair-programming mode—watching it reason, plan, and execute step by step. The ability to clearly articulate exactly what you want, and how you want it done, is becoming a rare skill.

simonw 11 hours ago||
Given the quality of their existing test suite I'm confident the Ralph Wiggum loop would produce a working implementation... but the code quality wouldn't be anywhere near what they got from two weeks of hands-on expert prompting.
vipulbhj 8 hours ago||
Sure yeah, I can buy that, but that would be like collecting tech debt for generations.
throwaway2037 10 hours ago||

    > Ralph Wiggum loop
Can you explain more? (I know the reference that he is the idiot son of Chief Wiggum from The Simpsons.)
simonw 10 hours ago||
https://ghuntley.com/loop/ and https://github.com/anthropics/claude-code/blob/main/plugins/...
woadwarrior01 8 hours ago||
Looks like it's been renamed to ralph-loop for legal reasons. :D

https://github.com/anthropics/claude-plugins-official/pull/1...

pjmlp 11 hours ago||
All the best to them, however this feels like yah shaving instead of focusing into delivering a browser than can become an alternative to Safari/Chrome duopoly.
cromka 11 hours ago||
Part of browser experience is safety and migrating their JS library to Rust is probably one of the best ways to gain advantage over any other existing engine out there in this aspect. Strategically this may and likely will attract 3rd party users of the JS library itself, thus helping its adoption and further improving it.

They're not porting the browser itself to Rust, for the record.

pjmlp 10 hours ago||
Yet, they are open to further rewrites.
cromka 8 hours ago||
Your rant was about their loss of focus, not about them being open to other changes. Moving goalposts!
norman784 10 hours ago|||
Javascript is a self contained sub system, if the public API stays the same, then they can rewrite as much as they want, also I suppose this engine now will attract new contributors that will want to contribute to Ladybird just because they enjoy working with Rust.

Don't forget that the Rust ecosystem around browsers is growing, Firefox already uses it for their CSS engine[0], AFAIK Chrome JPEG XL implementation is written in Rust.

So I don't see how this could be seen as a negative move, I don't think sharing libraries in C++ is as easy as in Rust.

[0] https://github.com/servo/stylo

VoxPelli 6 hours ago||
Not only is Firefox using it for their CSS engine but Mozilla created Rust to build Servo and sadly only the CSS engine and maybe some other parts is what they kept around when they offloaded Rust.

“the Rust ecosystem around browsers is growing” – in the beginning pretty much 100% of the ecosystem around Rust was browser oriented

Thankfully Servo is picking up speed again and is a great project to help support with some donations etc: https://servo.org/

wolvesechoes 9 hours ago|||
Maybe it is my cynicism, but I always suspect such projects to be endless rabbit chasing. It is not about catching it.
cogman10 11 hours ago|||
Agreed. They said they ruled out rust in 2024, I believe the article they published was near the end of 2024 because I remember reading it fairly recently.

Seems like a lot of language switches in a short time frame. That'd make me super nervous working on such a project. There will be rough parts for every language and deciding seemingly on whims that 1 isn't good enough will burn a lot of time and resources.

zem 6 hours ago||
think of it as axe sharpening rather than yak shaving
mosura 12 hours ago||
Interestingly editorialized title omits “with help from AI”.
alpinisme 12 hours ago||
That’s probably just the classic HackerNews title shortening algorithm at work.
sjosh 5 hours ago|||
I went to check if this was documented in the list of undocumented HN features on GitHub but it’s not.

There is an open PR (by simonw btw): https://github.com/minimaxir/hacker-news-undocumented/pull/4...

throwaway2037 10 hours ago|||

    > classic HackerNews title shortening algorithm
Woah, this is a wild claim. @dang: Is this a thing? I don't believe it. I, myself, have submitted many articles and never once did I see some auto-magical "title shortening algorithm" at work!
simlevesque 10 hours ago|||
It's been confirmed by @dang many times before. I'm not sure if that's what cut the title here but I've seen it many times in the last 10 years.
logicprog 10 hours ago|||
I've seen it happen a couple times, iirc, it removes things after commas, and removes certain words as well
ivanjermakov 7 hours ago||
Adds [video] to YouTube links, too.
supriyo-biswas 12 hours ago|||
A LLM-assisted codebase migration is perhaps one of the better use cases for them, and interestingly the author advocates for a hands-on approach.

Adding the "with help from AI" almost always devolves the discussion from that to "developers must adopt AI or else!" on the one hand and "society is being destroyed by slop!" on the other, so as long as that's not happening I'm not complaining about the editorialized title.

FpUser 12 hours ago||
I think we've come to the point when it should be the opposite for any new code, something in line of: "done without AI". Bein an old fart working in software development I have many friends working as very senior developers. Every single one of them including yours truly uses AI.

I use AI more and more. Goes like create me classes A,B,C with such and such descriptive names, take this state machine / flowchart description to understand the flow and use this particular sets of helpers declared in modules XYZ

I then test the code and then go over and look at any un-optimal and other patterns I prefer not to have and asking to change those.

After couple of iterations code usually shines. I also cross check final results against various LLMs just in case

nicoburns 11 hours ago||
Very happy to see this. Ladybird's engineering generally seems excellent, but the decision to use Swift always seemed pretty "out there". Rust makes a whole lot more sense.
VoxPelli 6 hours ago|
Servo makes a whole lot more sense: https://servo.org/
LeFantome 5 hours ago||
Can you send a Gmail in Servo? No?

Ladybird is much further ahead in terms of actually rendering web pages that people use.

The biggest advantage to Servo was that it is written in Rust. This move begins to nullify that advantage as well.

Why exactly does Servo make more sense?

I hope they both succeed. But Ladybird is more likely to become a usable browser first.

cmrdporcupine 4 hours ago||
This move was only to port a part of their JS runtime pieces to Rust, that's it.
thiht 11 hours ago||
Cool, that seems like a rational choice. I hope this will help Ladybird and Servo benefit from each other in the long run, and will make both of them more likely to succeed
Perz1val 2 hours ago|
I hope it does not -> because we don't more browser crossbreeding
viktorcode 12 hours ago|
> We previously explored Swift, but the C++ interop never quite got there

But Rust doesn't have C++ interop at all?

nicoburns 12 hours ago||
You can do it via the C ABI, and use opaque pointers to represent higher-level Rust/C++ concepts if you want to.

Firefox is a mixed C++ / Rust codebase with a relatively close coupling between Rust and C++ components in places (layout/dom/script are in C++ while style is in Rust, and a mix of WebRender (Rust) and Skia (C++) are used for rendering with C++ glue code)

wavemode 10 hours ago||
> You can do it via the C ABI, and use opaque pointers to represent higher-level Rust/C++ concepts

Yeah but, you can do the same in Swift

nicoburns 10 hours ago||
My understanding from a brief read of the Swift issue is that they kept running into bugs in the Swift compiler which, in practice, prevented them from doing the things that they ought to be do in theory. This went on for long enough, that they got fed up and abandoned Swift.

The Rust compiler is incredibly solid (across all target platforms), and while it's C/C++ interop is relatively simplistic, what does exist is extensively battle tested in production codebases.

tonyedgecombe 12 hours ago|||
>But Rust doesn't have C++ interop at all?

It also doesn't have the disadvantages of Swift. Once the promise of Swift/C++ interop is gone there isn't enough left to recommend it.

skavi 12 hours ago||
I’m curious what issues people were running into with Swift’s built in C++ interop? I haven’t had the chance to use it myself, but it seemed reasonable to me at a surface level.
stratos123 11 hours ago||
There's a list of unsolved problems in this Ladybird issue, now closed because they dropped Swift: https://github.com/LadybirdBrowser/ladybird/issues/933

for example: "Swift fails to import clang modules with #include <math.h> with libstdc++-15 installed. Workaround: None (!!)"

woadwarrior01 11 hours ago|||
Yeah, that part doesn't make much sense to me. IMO, Swift has reasonably good C++ interop[1] and Swift's C interop has also significantly improved[2] since Swift 6.2.

[1]: https://www.swift.org/documentation/cxx-interop/

[2]: https://www.swift.org/blog/improving-usability-of-c-librarie...

azornathogron 11 hours ago|||
It may have in the future. Crubit is one effort in this direction: https://crubit.rs/
matthewkosarek 11 hours ago|||
There is also cxx.rs, which is quite nice, albeit you have to struggle sending `std` types back and forth a bit
nicoburns 11 hours ago||
> albeit you have to struggle sending `std` types back and forth a bit

Firefox solves this partly by not using `std` types.

For example, https://github.com/mozilla/thin-vec exists in large part because it's compatible with Firefox's existing C++ Vec/Array implementation (with the bonus that it's only 8 bytes on the stack compared to 24 for the std Vec).

nickorlow 11 hours ago||
Luckily, ladybird also does not use `std` types
the_mitsuhiko 10 hours ago|||
Rust has cxx which I would argue is "good enough" for most use cases. At least all C++ use cases I have. Not perfect, but pretty damn reasonable.
k33n 12 hours ago||
It's technically Rust -> C -> C++ as it stands right now
More comments...