News for hackers. Stuff that matters.
Re:Announcing Rust 1.20 by kibwen on Thursday August 31, 2017 @01:47PM (#15142204)
Interestingly, because Firefox chooses to use stable Rust exclusively, this is the version of Rust that will be used to deliver Quantum when Firefox 57 releases on November 14 (by which time Rust 1.21 will be out (releasing October 12), but Firefox 57 will be in beta by September 20).
Re:Announcing Rust 1.20 by tempay on Thursday August 31, 2017 @02:35PM (#15142649)
To save others from searching, Quantum[1] is the new engine for Firefox replacing(/building upon) gecko.

[1] https://wiki.mozilla.org/Quantum

Re:Announcing Rust 1.20 by dblohm7 on Thursday August 31, 2017 @03:49PM (#15143302)
Quantum is the project, not the engine. The resulting product is still Gecko.
Re:Announcing Rust 1.20 by Vinnl on Friday September 01, 2017 @08:38AM (#15147843)
And the goal of the project is to significantly improve the performance of Firefox.
Re:Announcing Rust 1.20 by bad_user on Friday September 01, 2017 @12:34AM (#15146141)
So they are already switching to the new Quantum-powered Gecko in Firefox 57?
Re:Announcing Rust 1.20 by cpeterso on Friday September 01, 2017 @02:13AM (#15146518)
There is no single switch. Quantum is an ongoing initiative to import more code from Servo into Firefox/Gecko and to improve Firefox responsiveness.
Re:Announcing Rust 1.20 by giancarlostoro on Friday September 01, 2017 @09:17AM (#15148089)
They do plan on replacing component by component so not sure how that will be in the case of Gecko, unless Gecko is already designed with pluggable parts then it would make sense, otherwise they might have to replace a lot of moving parts (not sure how large Gecko is / how much it needs to function) but it'll still be done in chunks if it's too large I'm guessing.
Re:Announcing Rust 1.20 by bad_user on Friday September 01, 2017 @03:22AM (#15146756)
Awesome.
Re:Announcing Rust 1.20 by smegel on Thursday August 31, 2017 @06:50PM (#15144649)
Are there any blogs about how Rust is integrated into Firefox (a mostly C++ program) - i.e. how the Rust runtime is invoked, garbage collection etc?
Re:Announcing Rust 1.20 by mbrubeck on Thursday August 31, 2017 @10:30PM (#15145690)
Hi, I'm a Servo developer who worked on some of the Rust code that's in Firefox. Calls between C++ and Rust code in Firefox all go through "extern C" functions. Some of the code involves reference-counted smart pointers. We use RAII wrapper types in both Rust and C++ to ensure that refcounts are incremented and decremented correctly on either side of the FFI boundary.

P.S. This old blog post is not about Rust-in-Firefox, but it does cover a related topic: How the Servo browser engine (written in Rust) interacts with the Spidermonkey JavaScript engine (written in C++ and embedded in both Gecko and Servo), including garbage-collected JavaScript objects:

https://research.mozilla.org/2014/08/26/javascript-servos-on...

Re:Announcing Rust 1.20 by senatorobama on Friday September 01, 2017 @04:05AM (#15146908)
Are there any engineering openings at Mozilla?
Re:Announcing Rust 1.20 by Insanity on Friday September 01, 2017 @05:59AM (#15147238)
You can check out this page: https://careers.mozilla.org/
Re:Announcing Rust 1.20 by smegel on Friday September 01, 2017 @12:10AM (#15146057)
Cool thanks.
Re:Announcing Rust 1.20 by steveklabnik on Thursday August 31, 2017 @06:52PM (#15144662)
Rust doesn't have any more runtime than C, and also doesn't have a GC. Servo has bindings into SpiderMonkey's GC so that the JavaScript stuff works properly, but that's only that part.

That said, I don't think there are any direct blog posts about it; Firefox's other code just sees Rust as C code, as far as I know. (I don't work on Firefox though so I could be wrong about some details.)

Re:Announcing Rust 1.20 by oscargrouch on Thursday August 31, 2017 @07:08PM (#15144772)
> That said, I don't think there are any direct blog posts about it; Firefox's other code just sees Rust as C code, as far as I know.

So it means the compiled binary ends up in a simple compatible C ABI? thats pretty nice, if thats the case.

But giving the project is using LLVM, even C++ ABI would be achievable without too much effort (i guess).

Re:Announcing Rust 1.20 by burntsushi on Thursday August 31, 2017 @07:18PM (#15144828)
To clarify, Rust has its own ABI, just like C++ has its own ABI. And just like C++, you can expose a C ABI if you want by defining special functions. In C++, it's an `extern "C" { ... }` block, and in Rust, it's a `extern "C" fn foo() ...` function declaration. You can see an example here: https://github.com/rust-lang/regex/tree/master/regex-capi

Adding C++ ABI support is a significant effort.

Re:Announcing Rust 1.20 by oscargrouch on Friday September 01, 2017 @05:23AM (#15147138)
> To clarify, Rust has its own ABI, just like C++ has its own ABI. And just like C++, you can expose a C ABI if you want by defining special functions. In C++, it's an `extern "C" { ... }` block, and in Rust, it's a `extern "C" fn foo() ...` function declaration.

Ohh, Now i got it. But its pretty good thing to have anyway. C ABI is the lingua franca anyway to communicate to any language, even C++.

> Adding C++ ABI support is a significant effort.

Ok. So if has its own ABI, im sure it would be a pretty hard undertaking to be compatible with C++.

I was guessing if maybe Rust had managed to squeeze and reuse the C++ ABI.. but sure, giving Rust is not that much alike C++ this would probably be a bad decision for small gains.

Thanks for clarifying.

Re:Announcing Rust 1.20 by vvanders on Thursday August 31, 2017 @11:24PM (#15145885)
Yup, with bindgen and rusty-cheddar you can build interfaces both ways that just talk over a C ABI. It's really, really nice.

In fact Rust in general is awesome for going to a wide range of platforms. I've got a project right now that runs on MSVC-x64/x86, Linux-x64, OSX-x64, Android-armv7, Android-x86, Linux-armv7 and Emscripten. Single codebase and interacting with various languages(C#, C++, Java) via the C ABI. Rust even cross-compiles my C source via GCC crate so I can use C libraries and build for any of those targets from my host(win32) machine.

Also, having just spent a few hours fucking around with linker flags in Qt I can't stress enough how awesome Cargo, Crates.io, Rustup and the sane defaults Rust has. It really is an incredible ecosystem.

Re:Announcing Rust 1.20 by Manishearth on Thursday August 31, 2017 @07:53PM (#15145029)
bindgen actually has the option to generate wrappers for C++ methods and other stuff for Rust to call. We don't use this, but we do use its ability to generate templates and stuff.

The other way around -- getting Rust to use the C++ abi -- needs compiler changes and also has questionable benefits.

Re:Announcing Rust 1.20 by oscargrouch on Friday September 01, 2017 @05:24AM (#15147143)
> getting Rust to use the C++ abi -- needs compiler changes and also has questionable benefits.

Yes.. Im sure is not worthy it overall.

Re:Announcing Rust 1.20 by smegel on Thursday August 31, 2017 @07:03PM (#15144725)
I swear I had read Rust had optional GC at one point. And similarly Rust wanting to own main(). Maybe not then.
Re:Announcing Rust 1.20 by burntsushi on Thursday August 31, 2017 @07:07PM (#15144758)
I don't know the precise history, but at one point, it did have a "gc" type, which I believe was demarcated by the `@` sigil. So, for example, `@T` was a garbage collected pointer to `T`. IIRC, the actual garbage collector was simplistic, and was mostly just reference counting under the hood. At some point (in 2014, I think), the GC type went away. Since then, there has never been any serious talk of adding an optional GC to Rust proper, although many folks have worked/written about writing their own.
Re:Announcing Rust 1.20 by steveklabnik on Thursday August 31, 2017 @07:26PM (#15144879)
This is pretty accurate; however, a very long time ago there was a tracing GC!
Re:Announcing Rust 1.20 by iopq on Thursday August 31, 2017 @08:15PM (#15145149)
Are you sure? I thought @ was reference counted in 0.6 and then removed after. Was it before that?
Re:Announcing Rust 1.20 by steveklabnik on Thursday August 31, 2017 @08:29PM (#15145219)
I don't have any citation beyond "Graydon told me one time". It was like, very very long ago, possibly before @T even existed.
Re:Announcing Rust 1.20 by Rusky on Thursday August 31, 2017 @10:09PM (#15145612)
IIRC it was a mark and sweep GC in the OCaml implementation.
Re:Announcing Rust 1.20 by steveklabnik on Thursday August 31, 2017 @11:11PM (#15145830)
That sounds about right.
Re:Announcing Rust 1.20 by jacobush on Friday September 01, 2017 @03:27AM (#15146775)
Wow, I can't believe I have been reading up lately on official Rust documentation and still I was under the impression that Rust had optional GC. Thanks for sorting me out...
Re:Announcing Rust 1.20 by kbenson on Friday September 01, 2017 @08:21PM (#15153380)
Well, I think is sort of does when you use the Rc types, right? It's just much more explicit than a type modifier, it's a type wrapper that requires requires some level of additional code ornamentation in some instances when using later as well. It's just not really any different than using a library in C++ that offers the same, except that in Rust's case the library is part of the stdlib.
Re:Announcing Rust 1.20 by steveklabnik on Thursday August 31, 2017 @07:35PM (#15144929)
Rust had almost everything at some point :)

Rust binaries do define a "main", and setting that up is the runtime's job, like C. But you can also make a library that needs no main at all.

Re:Announcing Rust 1.20 by shepmaster on Thursday August 31, 2017 @09:20PM (#15145426)
It's not a blog, but Rust Belt Rust 2017 [1] (a conference I help organize) will have a talk "The Story of Stylo: Replacing Firefox's CSS engine with Rust" [2]. The conference is in Columbus, Ohio, and is reasonably priced.

[1]: http://rust-belt-rust.com/ [2]: http://rust-belt-rust.com/sessions.html

Re:Announcing Rust 1.20 by firebones on Thursday August 31, 2017 @10:58PM (#15145783)
Are there any stats yet on improvements in memory safety within Firefox attributable to Rust. In theory, it could be as much as 50% fewer based on the original premise of Rust removing whole classes of programmer errors, but are there stats from Rust being in the wild? The CSS replacement reminded me that there should be something to compare.
Re:Announcing Rust 1.20 by burntsushi on Thursday August 31, 2017 @11:48PM (#15145982)
> are there stats from Rust being in the wild?

I don't know, but if I recall correctly, nobody has ever reported a memory safety bug to ripgrep, or even the underlying regex engine. I don't really know how many people use ripgrep, but it's not zero.

Re:Announcing Rust 1.20 by lordnaikon on Friday September 01, 2017 @02:03AM (#15146484)
I can assure the lower bound is at least one. Thanks for boosting my productivity!
Re:Announcing Rust 1.20 by brazzledazzle on Friday September 01, 2017 @08:57AM (#15147957)
I use it everyday, several times per day. Thank you for you such a useful utility.
Re:Announcing Rust 1.20 by ameliaquining on Friday September 01, 2017 @12:08PM (#15149712)
Well, everyone who's using VS Code is using ripgrep, and a year ago Microsoft said it had half a million active users, and the number has presumably grown since then.
Re:Announcing Rust 1.20 by amelius on Friday September 01, 2017 @04:48AM (#15147036)
Doesn't ANY rewrite (regardless of whether there is a change in language) reduce bug-count, simply because all the requirements are more clear in advance and the engineers have had more time to think about a suitable architecture?
Re:Announcing Rust 1.20 by lomnakkus on Friday September 01, 2017 @05:25AM (#15147145)
Nope. Churn (= number of lines changed) is actually pretty well correlated with bug count.

I don't have a precise reference off-hand, but I believe I read it in "Making Software: What Really Works, and Why We Believe It".

Obviously you'll probably get closer to what the software is intended to do, but it probably won't reduce bug count in the short term. In the long term, you might end up with fewer lines of code overall (which is also correlated with overall bug count).

Re:Announcing Rust 1.20 by amelius on Friday September 01, 2017 @05:44AM (#15147203)
> Churn (= number of lines changed) is actually pretty well correlated with bug count.

Is a rewrite considered as bunch of line changes or not? I would say not.

Also, can I assume that by "correlated with" you mean "positively correlated with"?

If so, isn't a rewrite reducing bug count because you'll end up with far fewer "changed" lines?

Re:Announcing Rust 1.20 by lomnakkus on Friday September 01, 2017 @07:09AM (#15147460)
I would assume a rewrite counts as a bunch of line changes -- absent evidence to the contrary. Obviously, if you're changing the language that changes the equation, some bugs which can happen in C++ simply cannot happen in Rust, for example.

(And yes, I meant "positively correlated with".)