News for hackers. Stuff that matters.
Re:Rust and C++ Interoperability in Chrome by oscargrouch on Wednesday August 19, 2020 @03:10PM (#24214780)
As someone that deals with a chromium-based codebase everyday, i dont think this is a good idea at all.

Unnecessary overcomplication on the codebase, making it more difficult to understand. (Rust and C++ are complex beasts)

The only thing i could think of, is to replace the tools that are mostly in Python.. But this will be a lot of work.

I guess maybe Google wants to employ good Rust enginneers and need to have some "playground" for them.

Swift on the other way, will have native C++ interop, and soon will give the ability to manage the memory ownership the same way C++ and Rust does (not just defaulting to ref-count)..

Once Swift have those properties we will have one more good contender in the same arena as C++, Rust and Zig.

Re:Rust and C++ Interoperability in Chrome by nilkn on Wednesday August 19, 2020 @03:15PM (#24214869)
I doubt the point is to offer people a playground but rather to find a way to write new code in a language that is memory safe by default. Browsers are notoriously plagued by bugs related to memory safety so there’s quite a lot of motivation for at least considering this path.
Re:Rust and C++ Interoperability in Chrome by oscargrouch on Wednesday August 19, 2020 @03:33PM (#24215133)
That is the problem with default narratives, they dont adapt well to every case.

Chromium codebase is a massive codebase. It works, its efficient and fast, its sophisticated and complex, its well tested, had all sort of bugs that was taken out of them. Its really well written C++ code with modern ownership semantics. So a lot of mistakes that are used as boogeyman to convince people to use Rust are barely problems you really face.

And no matter what wonders Rust promisses, a lot of bugs would get back there in case of rewriting things.

Rust can make a very good point when the thing to be rewritten is in C (if is not a billion dollar codebase like Linux). But with big codebases, well written and modern C++ it doesnt make sense at all.

I get it why someone would start a new project in Rust though.. but the things dont add up when we talk about big codebases already coded with good C++ practices.

Re:Rust and C++ Interoperability in Chrome by kllrnohj on Wednesday August 19, 2020 @03:45PM (#24215309)
> So a lot of mistakes that are used as boogeyman to convince people to use Rust are barely problems you really face.

https://bugs.chromium.org/p/project-zero/issues/list?q=produ...

This year alone saw 2 issues from Project Zero in Chrome that would have been prevented by Rust - both OOB accesses, one with a helping of data racing.

Chromium is an incredibly security-sensitive piece of software, and that really is an excellent fit for Rust. It's not a boogeyman argument and the Chromium team themselves are the ones pursuing it, it's not being forced on them.

Re:Rust and C++ Interoperability in Chrome by oscargrouch on Wednesday August 19, 2020 @04:08PM (#24215626)
I have no doubt that Rust could save some sort of bugs. If you read all the comment i´ve made, you will see that we are talking about a massive codebase already coded in C++.

Giving the time it is alive, all the engineering hours, investiments, tools, etc.. most of the bugs that Rust could have prevented right on the beggining are already covered (Chrome also uses fuzzers and static analysis tools to automate C++ code)

> This year alone saw 2 issues from Project Zero in Chrome that would have been prevented by Rust

Thanks for making my point even clearer. If you really knew the size of the codebase, having only 2 issues on Project Zero is kind of a compliment to Chrome.

By the way, it was yesterday, that i´ve saw a research with fuzzers applied in C, C++ and Rust codebases.

In that research, Rust had the same overall count of bugs and even some 'zero day' sort of ones not any different from C++ and C codebases (maybe just better than the C one).

Its a pitty i can find where it is (I´ve saw it on Twitter, but its pretty recent).

> Chromium is an incredibly security-sensitive piece of software, and that really is an excellent fit for Rust. It's not a boogeyman argument and the Chromium team themselves are the ones pursuing it, it's not being forced on them.

A Chrome started from zero in 2020? probably.. but thats not the reality here. Millions of lines of C++ code, and its not just a matter of language, but the knowledge and people with the know-how to write those pieces..

Thats why im saying is not worth it..

Re:Rust and C++ Interoperability in Chrome by iulian_r on Wednesday August 19, 2020 @04:44PM (#24216157)
> In that research, Rust had the same overall count of bugs and even some 'zero day' sort of ones not any different from C++ and C codebases (maybe just better than the C one).

That's actually not entirely true. One of the problems was the program taking too long to compete due to suboptimal algorithm. The GitHub repo showed that the tests were run using debug version of the Rust binary. It worked fine when people tried to reproduce using the release version.

For the other two problems, not many details were given, but both programs panicked immediately with the given input. That's still better than any kind of undefined behaviour or silent error.

Re:Rust and C++ Interoperability in Chrome by staticassertion on Thursday August 20, 2020 @01:55AM (#24220323)
> most of the bugs that Rust could have prevented right on the beggining are already covered (Chrome also uses fuzzers and static analysis tools to automate C++ code)

This isn't even close to true...

https://chromereleases.googleblog.com/2020/08/stable-channel...

Here's one from just this month.

Here's another from just this month with another fifteen issues: https://chromereleases.googleblog.com/2020/08/stable-channel...

There are hundreds a year like this. I could find many, many, many more.

Re:Rust and C++ Interoperability in Chrome by mrich on Wednesday August 19, 2020 @04:24PM (#24215869)
You also have to consider the huge investment that testing takes. Not only person days spent writing tests, but also infrastructure costs for running fuzzers, huge test suites and so on. And although the code base is already there and tested, it constantly changes, so there is no way to just incrementally test it. At some point you have to make some advances in the way you approach software development, not everything can be handled by brute force.
Re:Rust and C++ Interoperability in Chrome by oscargrouch on Wednesday August 19, 2020 @04:43PM (#24216152)
It would cost much more to rewrite in Rust.

Again thats why im saying that if the project would start now in 2020, all of those would be pretty good points. Right now is too late for that.

As another example, you can get just the V8 VM for instance. For start, with the ammount of solid code out there it would be nuts to talk over a rewrite..

Now imagine if we add to that, that the knowledge on JIT compilers is so difficult to grasp, that you would also need to have those same great engineers in the new language/platform you are planning the rewrite.

Giving the age of Rust, and giving you already have a bad time of finding those in the much older C++, imagine the time it takes to have the same quality people in Rust.

I know a lot of people are bully about Rust, but in reality things are not that simple.

(On the bright side, is not that hard to taught a C++ engineer to code in Rust)

Re:Rust and C++ Interoperability in Chrome by roca on Wednesday August 19, 2020 @06:43PM (#24217703)
If you care about security, it is much easier to write non-exploitable code in Rust than in C++, and you can hire accordingly.

Actually, the people who are really experienced at writing secure code in C++ understand that they can't do it reliably, and an increasing number of them (like me) would much rather write Rust code instead for that reason. So for secure code the hiring advantage is tilting away from C++ towards Rust.

Re:Rust and C++ Interoperability in Chrome by rvz on Wednesday August 19, 2020 @07:36PM (#24218126)
Yet once the Chromium team goes down that Rust to C++ FFI route, they will encounter the same old bugs outlined in this paper. [0] They might as well fork Servo and create their own engine from that, but even that is still a prototype worked on for years with zero C++ at least.

It's too early to see how the Chromium team will begin to work on this given it's only a plan, but maybe the unsafety and security issues are enough motivation to actually use Rust to C++ interop or a rewrite. But once again, this has been tried by some other projects and by just looking at the effort of a rewrite, they later concluded that it is not worth it. [1] [2]

Even better, just improve Servo instead. But I guess they would rather create their own fork, just like they did with WebKit.

[0] https://arxiv.org/pdf/2003.03296.pdf

[1] https://blogs.dust3d.org/2019/03/13/why-i-rewrote-the-mesh-g...

[2] http://way-cooler.org/blog/2019/04/29/rewriting-way-cooler-i...

Re:Rust and C++ Interoperability in Chrome by roca on Wednesday August 19, 2020 @08:01PM (#24218350)
None of this logic follows. Paper [0] categorizes bugs in unsafe Rust code. "There will be some bugs in FFI code" does not imply "no benefit to using Rust if there is C++ FFI". Many projects, including Firefox, have found Rust is really helpful even if you have C++ FFI.
Re:Rust and C++ Interoperability in Chrome by steveklabnik on Wednesday August 19, 2020 @04:43PM (#24216145)
By the way, there's a lot of questions about the methodology of that paper: https://www.reddit.com/r/rust/comments/icaf19/we_tested_the_...
Re:Rust and C++ Interoperability in Chrome by oscargrouch on Wednesday August 19, 2020 @05:04PM (#24216450)
To be fair Steve, i didnt use this as to invalidate the assumptions on Rust. Just that we need to be more carefull to just take things for granted.

Im not even taken this research for granted, and are waiting for further work to really prove the points, or even going against them.

Im just using as a cautionary tale for people going too fast on some assumptions, and not taking care to study sample by sample.

I have no doubt that Rust have a great future ahead of it. But it will take more time and lines of code to turn all of those wishes people have into reality.

Re:Rust and C++ Interoperability in Chrome by steveklabnik on Wednesday August 19, 2020 @05:21PM (#24216697)
Absolutely. I am very interested to see how everything plays out in the future.
Re:Rust and C++ Interoperability in Chrome by roca on Wednesday August 19, 2020 @05:15PM (#24216625)
> So a lot of mistakes that are used as boogeyman to convince people to use Rust are barely problems you really face.

The Chromium team does not believe you. https://www.chromium.org/Home/chromium-security/memory-safet...

Re:Rust and C++ Interoperability in Chrome by joshuamorton on Wednesday August 19, 2020 @04:09PM (#24215636)
> So a lot of mistakes that are used as boogeyman to convince people to use Rust are barely problems you really face.

To elaborate on the other commenter, the majority of bugs found in chromium are bugs that rust would avoid (memory safety issues that rust makes ~impossible).

Re:Rust and C++ Interoperability in Chrome by oscargrouch on Wednesday August 19, 2020 @04:23PM (#24215858)
If it was written from the start in Rust, i have no doubts. But thats not the reality being faced here.

Right now the Chromium codebase have less bugs than if it was written in Rust, because of how many hours and efforts that were spent on the codebase to make it work smoothly.

Also the particular engineers with particular know-hows work with a particular tool. Its not easy to find them especially if you are forcing to use a new language in a giving project. It will take years and even decades to have the same quality people you already have in C and/or C++ in Rust.

So it will take time to have an engineer that can make, lets say, a multi-process compositor in Rust. What about many people with that particular special knowledge that take years to be good at.

So in real life its not just a matter of a language being a better fit. Theres a lot of other vectors to take into account.

https://www.joelonsoftware.com/2000/04/06/things-you-should-...

Re:Rust and C++ Interoperability in Chrome by modeless on Wednesday August 19, 2020 @03:31PM (#24215113)
The security benefits of Rust outweigh those concerns. Almost all C++ code in Chromium is security sensitive. Even if it is sandboxed it can be part of an exploit chain to get to a sandbox escape. Adopting more secure languages should be a long term goal of the project.
Re:Rust and C++ Interoperability in Chrome by roca on Wednesday August 19, 2020 @05:14PM (#24216603)
Rust and Swift are not in the same arena as C++ and Zig. The former offer memory safety and the latter don't --- a critical distinction, since the main reason Rust exists is to provide memory safety in contexts where C++ has traditionally been dominant.
Re:Rust and C++ Interoperability in Chrome by oscargrouch on Wednesday August 19, 2020 @05:36PM (#24216907)
Thats because you have divided the languages by properties and i´ve originally divided them over the class of software that can be written in those languages.

More as "system language" category, where you can code OS´s, JIT compilers, Browsers or any time/memory sensitive kind of software. Thats why they were packed together.

Classically, those sort of things could be only coded in C and C++ as the attempts in doing them in "higher level" languages mostly failed.