News for hackers. Stuff that matters.
Re:Using Rust in Mercurial by gcb0 on Monday December 04, 2017 @12:34PM (#15845642)
really wonder why not Go.

original code was python with lots of C. the same can be done with Go, while keeping much of the same philosophy of python.

This change will probably alienate most of the contributors since rust and python or C are worlds apart.

Re:Using Rust in Mercurial by seba_dos1 on Monday December 04, 2017 @12:52PM (#15845860)
I would wonder why Go if Rust is available.

Rust isn't hard. The only somewhat hard thing in Rust is writing with borrow checker, and honestly, if you want to seriously write in C, you really need to go through that experience and understand it enough to feel somewhat comfortable with it.

And even if that would really be a thing, giving up compiler checks in order to allow more low quality code to be contributed doesn't really seem like a good trade off to me.

Re:Using Rust in Mercurial by Rusky on Monday December 04, 2017 @12:58PM (#15845914)
Rust is certainly harder than Go. There's no need to dance around the issue, that doesn't help anyone.

Further, Mercurial is already 100% on the train of "giving up compiler checks," though "low quality code" is hardly a fair characterization of why.

Re:Using Rust in Mercurial by vvanders on Monday December 04, 2017 @01:03PM (#15845966)
In isolation Go is probably easier to write than Rust. However in terms of embedding/interop Rust is certainly much easier.

Last I looked there wasn't a way to pin a pointer in Go and they explicitly forbid passing around opaque handles so you're already constrained in how you can interop.

Secondly you now have a whole nother runtime to hoist up instead of a simple C FFI. It hit this just recently with Python+Rust. Needed to optimize an inner loop. I could just drop down to a single Rust fn, write it and be on my way. No need to spin up a whole runtime just for that inner function.

The parent also hit it on the head. If you're going to be writing C you already need to understand lifetimes deeply, Rust just codifies that in a way that lets you catch it at compile time.

Re:Using Rust in Mercurial by Rusky on Monday December 04, 2017 @01:34PM (#15846255)
Certainly, those are exactly the reasons I would use to argue for Rust. I just don't like seeing people minimize its learning curve just to make a point.
Re:Using Rust in Mercurial by wott on Monday December 04, 2017 @09:06PM (#15849233)
> If you're going to be writing C you already need to understand lifetimes deeply,

Deeply? Unlike complicated languages like for example GC-languages, C only has 2 lifetimes: block scope for stack variables, forever (until explicitly free'd) for heap malloc'ed memory.

You don't have to twist your head to know in which of N possible ways the data you get from a function was allocated, you don't have to twist your head to know if you need to free it manually, or semi-manually, or hope that it gets freed automatically at some point.

You don't have to care about stack variables, you just have to be organised about heap variables, and that's it. No complicated concept, not many different paradigms. You malloc() something to get some memory when you need it, you free() it when you don't need it any more.

Also you don't have to twist your head to know if you can access some function argument, if it was passed by copy or by reference or by a third mean, does it involve heavy data copying or not, what does it mean concerning access, etc. Everything is passed by value (copy) and you can only pass simple objects (plus structures), for anything else you pass the value of the address of the object, end of story.

Re:Using Rust in Mercurial by Rusky on Monday December 04, 2017 @09:49PM (#15849390)
> C only has 2 lifetimes: block scope for stack variables, forever (until explicitly free'd) for heap malloc'ed memory.

To the contrary, C has just as many lifetimes as Rust. They're just not explicit. "free() it when you don't need it any more" is a complex problem and C doesn't really help you solve it at all.

> Everything is passed by value (copy) and you can only pass simple objects (plus structures), for anything else you pass the value of the address of the object, end of story.

That's how Rust works as well.

Re:Using Rust in Mercurial by gcb0 on Wednesday December 06, 2017 @10:06AM (#15861524)
I don't think go is interpreted in the way python is
Re:Using Rust in Mercurial by coldtea on Monday December 04, 2017 @01:15PM (#15846074)
>Rust is certainly harder than Go. There's no need to dance around the issue, that doesn't help anyone.

It's also faster, much more expressive, and much for flexible (e.g. for loading as a C-compatible lib) so there's that.

Re:Using Rust in Mercurial by spooneybarger on Monday December 04, 2017 @12:59PM (#15845926)
I have no idea as to the particulars here. I'm involved with a project that is working with Go code from another language.

Go doesn't allow you to share pointers to Go objects with other languages/runtimes. So whatever else the pros and cons of each, working with Go from another language can be painful.

Re:Using Rust in Mercurial by weberc2 on Monday December 04, 2017 @01:15PM (#15846073)
Correct me if I'm wrong, but I think Go lets you share pointers with other languages/runtimes. I think Go doesn't allow you to pass ownership of the pointer to another language, and you need to make sure the pointer is no longer used by the other language by the time Go cleans it up, but I think you can (for example) pass a Go pointer into C. And assuming I'm right about that point, I think this approach is also roughly what was outlined in the Oxidation Plan (Python won't own resources allocated from Rust and vice versa).
Re:Using Rust in Mercurial by danieldk on Monday December 04, 2017 @01:25PM (#15846175)
I think Go doesn't allow you to pass ownership of the pointer to another language, and you need to make sure the pointer is no longer used by the other language by the time Go cleans it up, but I think you can (for example) pass a Go pointer into C.

Yes, you can, but there are more constraints. E.g. you are also not permitted to pass a pointer to Go memory that contains Go pointers. There is a detailed description here:

https://golang.org/cmd/cgo/#hdr-Passing_pointers

Also, it used to be the case that cgo calls were relatively expensive (definitely not something you want to do in a hot loop). I am not sure if this is still true, but it was when I was using Go daily for projects.

Re:Using Rust in Mercurial by weberc2 on Monday December 04, 2017 @01:09PM (#15846023)
Rust is quite a lot harder than Go. While lots of practice makes it easier, it's still not trivial to reason about lifetimes/borrowing/moving, unlike a GC language (which isn't to say that GCs are strictly superior to other memory management schemes, mind you). There are lots of good reasons to choose Rust over Go (you have extreme performance or correctness requirements, for example), but "Rust is comparably easy to Go" is untrue (or as untrue as any user-friendliness assertions can be).

EDIT: I don't mean to convey that GCs are still trivial in a mixed-runtime context; only that Rust is generally harder than Go.

Re:Using Rust in Mercurial by vvanders on Monday December 04, 2017 @01:20PM (#15846125)
Except if you're embedding a runtime you invert the simplicity of a GC.

As soon as GC'd pointers start passing across an FFI boundary you either need to:

1. Pin them and track yourself, which then loses a lot of your advantage of having a GC since you've got non-deterministic seg-faults based on when GC runs and pulls objects out from underneath you. C# lets you do this, but it's really painful to get right.

2. Prevent any GC objects being passed(which is what Go does). This means that there's a lot of things you can't do(esp with respect to callbacks and future events) that require a ton of gymnastics to do something that's trivial in C.

Re:Using Rust in Mercurial by weberc2 on Monday December 04, 2017 @01:27PM (#15846189)
I absolutely agree with this. I didn't mean to convey otherwise.
Re:Using Rust in Mercurial by jhugg on Monday December 04, 2017 @12:39PM (#15845709)
One reason might be that it seems easier to mix languages with Rust vs. Go. The C interop is pretty sane and Go has a few more gotchas in that department.

The rest of the Rust v Go debate may be similar to the 1000 times people have had it before.

Re:Using Rust in Mercurial by kevin_thibedeau on Monday December 04, 2017 @12:46PM (#15845788)
Nim is an even closer match to Python and interop is trivial.
Re:Using Rust in Mercurial by oconnor663 on Monday December 04, 2017 @12:38PM (#15845694)
My understanding is that Go would be a fine candidate if you wanted to rewrite the entire codebase in it, but not for writing compiled extensions that Python can dynamically link, and they want one language to do both of those things?
Re:Using Rust in Mercurial by rubber_duck on Monday December 04, 2017 @12:43PM (#15845749)
One thing that comes to mind is having to bridge two GC/runtimes in the same binary, where Rust is a drop in replacement for C in that regard (systems programming language)
Re:Using Rust in Mercurial by rbehrends on Monday December 04, 2017 @01:29PM (#15846217)
As the plan seems to be to embed Python in Rust, rather than just writing extension modules in Rust, this shouldn't be as much of a concern.

The tricky part with two runtimes is (1) the system initialization and (2) the GC (if any) being able to control the initial stack frame. If you're just writing extension modules, either problem can be a challenge.

But the first problem goes away if you embed Python, as Python initialization is trivial for the host language when embedding. So does the second problem, as the host language is now in control of the initial stack frame.

The fact that a language is garbage-collected should not matter much; Python uses reference counting as its primary memory management mechanism, with a generational trial deletion approach for cycle colletion (which does not require root scanning). This approach can generally coexist well with a tracing garbage collector (though some challenges remain, but those can be designed around).

That said, Go specifically may have problems (I'm speculating here) due its green threads not being happy if Python does any blocking operations, and it's probably not safe to operate on Python objects concurrently in multiple threads. But that wouldn't necessarily be a problem for other languages.

Re:Using Rust in Mercurial by durin42 on Monday December 04, 2017 @03:24PM (#15847117)
Go isn't really a huge win for hg, and it doesn't support being used as a shared library, so we couldn't easily use it as a replacement for C for native extensions. main() has to be in Go, and even then you've got two GCs in the mix which is not great.
Re:Using Rust in Mercurial by neandrake on Monday December 04, 2017 @07:59PM (#15848969)
Using rust for a shared library implementation seems like it would mean a big improvement for mercurial's tooling in the long run. Right now the options are command line invocation or using the python library (effectively puts a requirement on implementation). Though I'm not sure the integrations I'm aware of[0] would benefit from a shared library.

[0] https://secure.phabricator.com/T9548

Re:Using Rust in Mercurial by chme on Monday December 04, 2017 @03:55PM (#15847405)
There are places where C and other places where programming C++ makes more sense; the same is true with Rust and Go.

When it comes to low-level, high performance, no overhead stuff and less unexpected behaviour C and Rust fit better.

Where high implementation speed and fast changing, experimental and highly modular architecture systems are more important C++ and Go are better.

For Mercurial and Git Rust or C makes more sense. Especially if you put experimental and fast changing stuff into a scripting language. IMO.

Re:Using Rust in Mercurial by rkangel on Monday December 04, 2017 @12:37PM (#15845679)
I'm curious, why is Go+Python easier than Rust+Python?
Re:Using Rust in Mercurial by Uther on Monday December 04, 2017 @04:27PM (#15847662)
It is not.

Go alone is easier than Rust. But since Rust has no GC, it is easier to embed, especially with a language with a Garbage collector like Python.

Re:Using Rust in Mercurial by erpellan on Monday December 04, 2017 @07:16PM (#15848785)
Given a situation where (pre-rust) the usual choice would be to use C or C++, it's totally appropriate to choose Rust. That's one of Rust's express design goals.

Go is intended to make it very easy for junior devs to build concurrent network applications. That's its design goal.

It's not a zero-sum game. Choosing rust doesn't weaken go or vice versa.

Re:Using Rust in Mercurial by panic on Monday December 04, 2017 @01:19PM (#15846117)
Forget Rust and Go, why not ATS? You get C compatibility with dependent types!
Re:Using Rust in Mercurial by petre on Monday December 04, 2017 @05:41PM (#15848230)
I wonder why not Dlang. It has better C/C++ interop than Rust, C parts coukd be used/wrapped before they're rewritten.
Re:Using Rust in Mercurial by Varriount on Tuesday December 05, 2017 @09:54AM (#15852015)
Or Swift, or Nim.

Really, There are so many other languages that are both performant and more readable than Rust (I consider Rust readability to be on par with C++).

Re:Using Rust in Mercurial by usrusr on Monday December 04, 2017 @01:57PM (#15846430)
Outsider guess: they want to move away not only from Python syntax and runtime, but also from Python philosophy.
Re:Using Rust in Mercurial by jstewartmobile on Monday December 04, 2017 @01:09PM (#15846019)
Last I read, any C calls have to be spun off into their own OS thread since the runtime is unable to inject soft context-switches into foreign code.

With heavy FFI usage, that could become costly...