News for hackers. Stuff that matters.
Re:The Rust compiler has gotten faster again by dividedbyzero on Thursday November 11, 2021 @10:27PM (#29196040)
I really like Rust, it hits a lot of sweet spots for me – strongly typed, neat type system, the mild functional-ness thats useful while keeping people from going too crazy with functional patterns, usually low on boilerplate, static binaries, clever little things like ? ... but sometimes I wish there was a garbage-collected version of it, the constraints of the borrow checker make things like tree structures at least an order of magnitude harder to get right, and I'd love to have the ergonomics of the language and the ergonomics of a gc-ed runtime. Not going to happen I guess, but I feel like there's an opportunity for a Rust-ish language that is somewhat less finnicky, at the cost of making some abstractions more expensive, for microservices with complex business logic and such.
Re:The Rust compiler has gotten faster again by pcwalton on Thursday November 11, 2021 @10:57PM (#29196174)
I actually support the idea of adopting Rust's ideas in a memory-safe, garbage collected language. I like garbage collection—it's not always the right tool, but it's a great tool in the proper domains. Modern GC builds upon decades of research to achieve memory safety at runtime with good performance and very low cognitive overhead on the part of the programmer.

What I don't agree with is the idea of taking Rust's ideas and putting them into manually-memory-managed, unsafe languages. We should be moving away from such languages as an industry.

Re:The Rust compiler has gotten faster again by skohan on Thursday November 11, 2021 @11:41PM (#29196372)
> I actually support the idea of adopting Rust's ideas in a memory-safe, garbage collected language

You're describing Swift

Re:The Rust compiler has gotten faster again by saghm on Friday November 12, 2021 @12:28AM (#29196555)
Swift also has some stuff coming from the history of Objective-C interop (inheritance is the big one I'm thinking of, although I'm sure there are others that are slipping my mind). I'm not sure how mainstream this opinion is, but personally I _prefer_ not having classes and inheritance, and while I could always choose not to use them in my own code, I imagine it's common enough in libraries that I'd end up dealing with it a bit anyways. Combined with the fact that Linux support still seems like it's a bit secondary makes me feel like there still is a potential niche out there for "Rust with garbage collecting" that Swift might not be filling entirely.
Re:The Rust compiler has gotten faster again by skohan on Friday November 12, 2021 @01:56AM (#29196943)
Yeah I agree, I think one of the biggest mistakes in Swift was coupling reference types to classes. Choosing whether something is a reference type of value type should have been orthogonal to the class system, if they included classes at all.

But in practice I think modern swift uses inheritance very sparingly, and leans much harder on the protocol/extensions system, which is very well design imo

Re:The Rust compiler has gotten faster again by mirekrusin on Friday November 12, 2021 @01:51AM (#29196921)
What are you both talking about? Swift doesn't have garbage collector the same way Rust doesn't have it.
Re:The Rust compiler has gotten faster again by skohan on Friday November 12, 2021 @02:01AM (#29196969)
Swift doesn't have tracing GC, but to be pedantic automatic reference counting is a form of GC.

But that only goes for reference types. For value types you're correct that both languages use mostly static memory management.

I guess in that sense you'd have to consider Rust as a gc'd language as well: the only difference really is that you have more fine-grained control over which mode of reference counting is being used for a given object.

Re:The Rust compiler has gotten faster again by wahern on Friday November 12, 2021 @02:47AM (#29197174)
See also "A Unified Theory of Garbage Collection", https://researcher.watson.ibm.com/researcher/files/us-bacon/...

> We present a formulation of the two algorithms that shows that they are in fact duals of each other. .... Using this framework, we show that all high-performance collectors (for example, deferred reference counting and generational collection) are in fact hybrids of tracing and reference counting.

...

> For every operation performed by the tracing collector, there is a corresponding "anti-operation" performed by the reference counting collector.

...

> We have shown that tracing and reference counting garbage collection, which were previously thought to be very different, in fact share the exact same structure and can be viewed as duals of each other.

Re:The Rust compiler has gotten faster again by pjmlp on Friday November 12, 2021 @02:33AM (#29197118)
Chapter 5 of the GC Handbook, one of the major CS references in GC algorithms.
Re:The Rust compiler has gotten faster again by mirekrusin on Friday November 12, 2021 @05:45AM (#29197988)
GC is standalone runtime that does tracing and deallocates memory at some arbitrary time. Are you really claiming that using C++'s smart pointers is using GC? I think you're conflating semi/automatic memory management with GC.
Re:The Rust compiler has gotten faster again by pjmlp on Friday November 12, 2021 @06:17AM (#29198148)
You're conflating tracing GC algorithm with GC as CS concept.

Regarding C++ smart pointers, if you manually call them like in std::shared_ptr<>(), no.

If the runtime calls it for you like on C++/CX or compiler blessed types like _com_ptr_t, then surely.

Re:The Rust compiler has gotten faster again by mirekrusin on Saturday November 13, 2021 @01:14AM (#29207848)
ARC in Swift doesn't have runtime part, retain/release code is injected at the compile time. It doesn't have ie. cycle detector running periodically or anything like that. If you define this setup as GC then by this definition Rust's borrow-checker is also a GC because it works the same way - by injecting static code during compilation (but has different rules).
Re:The Rust compiler has gotten faster again by bouke on Friday November 12, 2021 @02:05AM (#29196983)
Swift does not employ garbage collection, but reference counting.
Re:The Rust compiler has gotten faster again by pjmlp on Friday November 12, 2021 @02:33AM (#29197121)
Chapter 5 of the GC Handbook, one of the major CS references in GC algorithms.

Reference counting is a GC algorithm, regardless how people sell it to the man on the street.

Additionally there is a whole set of politics how ARC had to be sold after the technical failure to make Objective-C GC implementation work without core dumps, due to the underlying C semantics.

Plus making retain/release calls automatic wasn't anything new as idea, VB and Delphi did it first with COM AddRef/Release.

Re:The Rust compiler has gotten faster again by skohan on Friday November 12, 2021 @02:15AM (#29197025)
Swift doesn't have tracing gc but ref counting is a form of gc
Re:The Rust compiler has gotten faster again by pjmlp on Friday November 12, 2021 @02:31AM (#29197113)
Also Haskell, D, Chapel, among others.
Re:The Rust compiler has gotten faster again by cultofmetatron on Thursday November 11, 2021 @11:41PM (#29196370)
> I actually support the idea of adopting Rust's ideas in a memory-safe, garbage collected language.

sooo... ocaml?

Re:The Rust compiler has gotten faster again by johnisgood on Friday November 12, 2021 @02:08AM (#29196997)
Or many other programming languages, but yes, OCaml is a pretty good one, and it is perfectly suitable for systems programming.
Re:The Rust compiler has gotten faster again by pjmlp on Friday November 12, 2021 @02:33PM (#29203575)
I can attest that so far the lifetime static analysers for C++ haven't progressed that much.

However until certain C++ overloads don't give more love to memory-safe, garbage collected language or languages like Rust, that is better than nothing.

For example, I don't expect Windows team to ever lose their love for C++, NVidia moving from their C++ love for CUDA, or Metal shaders in something else.

Ah, and then many of those languages are keeping C++ around by building on top of GCC or LLVM.

So any improvement towards to make C and C++ safer is better than just using them as they are.

Re:The Rust compiler has gotten faster again by estebank on Thursday November 11, 2021 @10:38PM (#29196096)
For what is worth, you can opt-into reference counting and internal mutability with container types (Arc/Rc, Cell/RefCell, RwLock/Mutex), and get the same performance characteristics as a GC language (but without a JIT) for the cost of more complex types in your signatures.

Edit:

> the constraints of the borrow checker make things like tree structures at least an order of magnitude harder to get right

The constraints of the borrow checker make those things more unlikely to compile without extra ceremony. The likelihood of getting them right is orthogonal from making the compiler "happy", even in Rust but specially in other languages. The way I've heard it described is that Rust is a language where you get the hangover first. It upfronts dealing with the error conditions of your problem space in a way that (you can argue) hinders the exploration phase, but that makes of a very quiet maintenance phase.

Re:The Rust compiler has gotten faster again by sizediterable on Thursday November 11, 2021 @10:44PM (#29196121)
People like to bring up reference cycles a lot as if it's always a deal-breaker, but for short-lived processes it kind of seems like a non-issue. Anecdotally, we've seen Instagram get overall gains by disabling GC in Python (which will still do reference counted cleanup).
Re:The Rust compiler has gotten faster again by gnulinux on Friday November 12, 2021 @04:48AM (#29197724)
Exactly, I like implementing compilers and I personally never bother with anything other than reference counting nowadays. Ref count gives a very easy to reason semantics. So I count as a feature in my language even if it's slower than GC. Moreover, some of the "memory leak" discussions nowadays miss the biggest issue behind memory leak, which is resource allocation. Some people measure memory leak as the # bytes that process didn't deallocate at the time of exit.
Re:The Rust compiler has gotten faster again by Const-me on Friday November 12, 2021 @12:48AM (#29196636)
> and get the same performance characteristics as a GC language

Pretty sure modern state of the art GCs, like the ones found in Java or .NET runtimes, are way more efficient than reference counting.

Reference counters have that unfortunate RAM access pattern where the counter is frequently updated from multiple threads concurrently. On modern processors, this means concurrent access to a cache line by different CPU cores. These cache coherency protocols are pretty slow. On many CPUs, reading a cache line recently modified by another core costs 300-500 clock cycles, even more expensive than a cache miss and roundtrip to system RAM.

Re:The Rust compiler has gotten faster again by sizediterable on Friday November 12, 2021 @11:57AM (#29201550)
Python is experimenting with a novel approach where objects have two reference counts, one exclusively for the owning thread and another for all other threads, improving performance when most of the increments/decrements are done by the owning thread.

https://lwn.net/Articles/872869/

Re:The Rust compiler has gotten faster again by pjmlp on Friday November 12, 2021 @05:05PM (#29205079)
They are, specially when ARC marketing from Apple gets validated.

https://github.com/ixy-languages/ixy-languages

Re:The Rust compiler has gotten faster again by sizediterable on Thursday November 11, 2021 @10:40PM (#29196101)
Re:The Rust compiler has gotten faster again by winrid on Thursday November 11, 2021 @10:47PM (#29196142)
Sounds like you're looking for Nim!
Re:The Rust compiler has gotten faster again by musicmatze on Friday November 12, 2021 @03:30AM (#29197333)
The constraints of the borrow checker do not make tree structures harder to get right! They just force you to get it right!
Re:The Rust compiler has gotten faster again by davidkunz on Friday November 12, 2021 @03:47AM (#29197395)
I don't think Rust is low on boilerplate.

As an example, here is a video of David Pedersen creating a simple Tower service: https://www.youtube.com/watch?v=16sU1q8OeeI&t=945s

I found it intimidating how much you have to write to create a simple middleware.

Re:The Rust compiler has gotten faster again by timw4mail on Friday November 12, 2021 @09:13AM (#29199403)
There's some amount of boilerplate that is unavoidable, but, if you have the patience, `macro_rules!` type macros can help cut down on syntactical boilerplate in many cases.

Compared to C, and sometimes C++, there's generally less boilerplate in Rust. Compared to more traditional web languages, though, Rust will seem to have more boilerplate due to it's lower-level design.

Re:The Rust compiler has gotten faster again by skohan on Thursday November 11, 2021 @11:42PM (#29196379)
You're describing Swift
Re:The Rust compiler has gotten faster again by duped on Friday November 12, 2021 @12:39AM (#29196602)
It's a shame Swift isn't as usable outside Apple platforms
Re:The Rust compiler has gotten faster again by skohan on Friday November 12, 2021 @01:55AM (#29196936)
Totally agree - it's a nice language and I would love to be able to use it everywhere
Re:The Rust compiler has gotten faster again by pjmlp on Friday November 12, 2021 @02:30AM (#29197102)
They already exist, OCaml, Haskell, F#, Scala, Swift.
Re:The Rust compiler has gotten faster again by sharno on Friday November 12, 2021 @11:56AM (#29201531)
Totally agree, really wish for a language that has all rust features + GC. OCaml and F# come close enough but they are not as popular.
Re:The Rust compiler has gotten faster again by m0zg on Friday November 12, 2021 @01:41AM (#29196869)
>> Not going to happen

I sure hope not. Borrow checker has little to do with memory allocation/deallocation. It's there so that you can't have unprotected mutable shared state.