News for hackers. Stuff that matters.
Re:For Better Computing, Liberate CPUs from Garbage Collection by arcticbull on Thursday May 09, 2019 @03:13AM (#19866057)
> But all of these are much cheaper than developer labour and reputation damage caused by leaky/crashy software. The economics make sense.

Of course, with traditional languages, that's the trade-off we're being asked to make. That's my point! We need to develop languages that accurately encapsulate lifetimes statically so that we can express that to the compiler. If we do, the compiler can just make instances disappear statically when we're done with them -- not dynamically! Like Rust but without the need for Rc and Arc boxes. Rust gets us 80% of the way there.

The truth is with most of the Rust I write, I don't have to worry about allocation and deallocation of objects, and it happens. It's almost ubiquitous. We need to extend that to 100%.

> Long live garbage collection!

Long live the rocket powered horse!

Re:For Better Computing, Liberate CPUs from Garbage Collection by bollu on Thursday May 09, 2019 @03:45AM (#19866191)
This only works if your language is strict. With a lazy language like Haskell, you can't statically infer (at least naively with respect to scoping rules) when something lives and dies.

Performing this statically is hard, and GHC tries to do it (Demand analysis).

But without a GC, these sorts of languages would be a no-go, as would logic-based languages like Prolog which need to GC their internal data structures.

While we now have the expertise for eliminating the GC from single threaded strict programs (multi threading in Rust is still quite complex, and you do see Rc<Box<..>> more often than not in these settings, which is essentially refcounting/GC), this _does not scale_ to all models of languages.

Re:For Better Computing, Liberate CPUs from Garbage Collection by eru on Thursday May 09, 2019 @06:44AM (#19866956)
GHC infers these kinds of things all the time. It can't do so in general, but neither can you do that in a static language.

GHC even has a strictness analyzer.

Re:For Better Computing, Liberate CPUs from Garbage Collection by tempguy9999 on Thursday May 09, 2019 @03:56AM (#19866240)
> If we do, the compiler can just make instances disappear statically when we're done with them -- not dynamically!

Not possible generally. It would be easy to create a situation where some kind of refcount is a necessary final fallback.

> The truth is with most of the Rust I write, I don't have to worry about allocation and deallocation of objects, and it happens.

If Rust is the answer, why are you pushing for new langs when Rust is sufficient? Something doesn't add up here.

> Long live the rocket powered horse!

Your response to someone giving their years of experience is that? Well, we're all convinced now.

Re:For Better Computing, Liberate CPUs from Garbage Collection by ascar on Thursday May 09, 2019 @04:53AM (#19866507)
> If Rust is the answer, why are you pushing for new langs when Rust is sufficient? Something doesn't add up here.

Maybe because he said, twice, that Rust is not all the way there?

Re:For Better Computing, Liberate CPUs from Garbage Collection by tempguy9999 on Thursday May 09, 2019 @05:08AM (#19866567)
You're quite right, thank you, upvoted.

However if he says "Rust gets us 80% of the way there" as you point out then he is obliged, IMO, to point out explicitly the 20% where it fails or we can't even begin to discuss it.

Re:For Better Computing, Liberate CPUs from Garbage Collection by DevoidSimo on Thursday May 09, 2019 @06:07AM (#19866802)
He mentions Rc and Arc which I assume is what he means by the 20%. I tend to agree, although I'm not sure how you would get rid of them.
Re:For Better Computing, Liberate CPUs from Garbage Collection by eru on Thursday May 09, 2019 @06:42AM (#19866947)
>> If we do, the compiler can just make instances disappear statically when we're done with them -- not dynamically!

> Not possible generally. It would be easy to create a situation where some kind of refcount is a necessary final fallback.

Either refcount or a GC. But those situations might be rare in practice with a good system.

If you think about it, generational garbage collection implements lots of those heuristics. (But it's closer to a JIT optimizer, not a static optimizer.)

Re:For Better Computing, Liberate CPUs from Garbage Collection by cormacrelf on Thursday May 09, 2019 @03:18AM (#19866068)
How do you see multi-threaded anything working without Arc? Some owners (threads) are created and destroyed dynamically. Are you thinking Arcs get added wherever necessary?
Re:For Better Computing, Liberate CPUs from Garbage Collection by jules on Thursday May 09, 2019 @08:58AM (#19867843)
There are solutions for that, but it requires a more powerful type system / logic than Rusts: http://www0.cs.ucl.ac.uk/staff/p.ohearn/papers/permissions_p...
Re:For Better Computing, Liberate CPUs from Garbage Collection by szemet on Thursday May 09, 2019 @03:23AM (#19866091)
Or a multi-threaded app where plenty of dynamically created closures operates on persistent data structures? ;)
Re:For Better Computing, Liberate CPUs from Garbage Collection by arcticbull on Thursday May 09, 2019 @03:29AM (#19866110)
Oh to be clear I don't have an answer for this off-hand, I'm not that smart. However, if we'd given the 30 years of people developing faster for-loops the task of figuring out how to manage memory statically, I'd wager we'd not be having this conversation right now. It is by no means an easy problem, however.
Re:For Better Computing, Liberate CPUs from Garbage Collection by Hercuros on Thursday May 09, 2019 @04:12AM (#19866300)
I think there are essentially two ways of making the compiler statically aware of lifetimes: you can annotate the program with lifetimes, as in Rust, or you can have the compiler infer all of the lifetime information somehow.

Adding annotations requires more programmer effort and reduces the level of abstraction of your programming language. Rust takes this approach, but tries to keep the level of annotation somewhat reasonable, and provides the "unsafe" escape hatch for when you cannot convince the compiler that what you're doing makes sense. (Although I do believe that it would be possible for the Rust compiler to infer most/all lifetimes).

For instance, in a functional programming language, you are typically creating closures all over the place, like one of the other posters mentioned. It seems quite unlikely that there is any kind of reasonable lifetime annotation system that would capture all of the complex lifetime patterns that you would see in such a language.

One can say "Oh, but surely someone smarter than me must be able to come up with something that works for those situations", but I don't think that is a very constructive line of thought, since you could say that about pretty much everything. Rust is an example of a language where lifetimes work reasonably well, but Rust already makes some tradeoffs that reduce its level of abstraction to some degree. It doesn't provide the same level of abstraction that, say, Haskell does.

Program analysis would allow you to keep your level of abstraction and ideally not require only little annotations. However, since any non-trivial program property is undecidable, program analysis is fundamentally incomplete and it is again unlikely that it would be able to deal with all lifetime patterns that you see in practice.

Therefore, it seems to me that there is no free lunch here. Either you sacrifice abstraction by requiring annotations or you don't require any annotations but then you have an incomplete program analysis.

(Also, you seem to think 30 years of good research has been wasted on the "obviously bad idea" of garbage collection, but somehow none of these researchers were good enough to realize this and come up with the silver bullet that makes GC unnecessary? After all, people were already thinking about GC-less languages long before Rust was a thing)

Re:For Better Computing, Liberate CPUs from Garbage Collection by mafribe on Thursday May 09, 2019 @04:33AM (#19866412)

   possible for the Rust compiler 
   to infer most/all lifetimes)
I'd be interested to learn why you think this is possible. As you point out yourself, by Rice's theorem, precise lifetimes are not statically decidable. Rust's lifetimes are essentially based on nesting (think well-balanced brackets) and tracked by enriching the standard Damas-Hindley-Milner approach with a notion of affin-ness which is a weakening of Girard's linearity. Circular data structures immediately violate affine-ness. What mechanism do you propose to get around this conundrum?
Re:For Better Computing, Liberate CPUs from Garbage Collection by lllr_finger on Thursday May 09, 2019 @09:11AM (#19867928)
"All" might not be possible, but every Rust release tends to see improvements in lifetime elision. I just went through a few Rust apps I wrote 6 months ago and was able to get rid of nearly every explicit lifetime annotation thanks to improvements.

So there's definitely room for improvement, but also good progress being made.

Re:For Better Computing, Liberate CPUs from Garbage Collection by Hercuros on Thursday May 09, 2019 @05:27AM (#19866652)
I think that for function definitions in Rust you would in principle be able to leave out lifetime annotations on arguments/return values in more cases than is currently allowed by lifetime elision. I believe they don't allow this since it can become very confusing if the lifetimes are not written out when there are multiple references arguments. I'm not entirely sure about this, though.
Re:For Better Computing, Liberate CPUs from Garbage Collection by sanxiyn on Thursday May 09, 2019 @04:54AM (#19866510)
I know this is possible because Rust already does this. Rust's types in closures can be fully inferred. Try replacing all Rust functions with closures. It goes surprisingly far.
Re:For Better Computing, Liberate CPUs from Garbage Collection by timw4mail on Thursday May 09, 2019 @09:19AM (#19867991)
I'm not sure this would be possible for a standalone library, compared to a self-contained program, either.
Re:For Better Computing, Liberate CPUs from Garbage Collection by jules on Thursday May 09, 2019 @09:02AM (#19867869)
It's a little bit contradictory that you simultaneously believe that the people who worked on GC are much smarter than you, but at the same time they were wrong to choose to work on GC rather than your research program ;-) Not all problems can be solved by throwing smart people at it. There has been research along the lines you suggest. Look at the MLkit region inference research, or escape analysis research, for example. It doesn't work very well in practice. It can correctly infer like 95% of memory allocation/deallocation, but that remaining 5% leaks memory which means you need a GC anyway. It's still valuable research though. Go, for example, made the bet that they can use a low-pause low-throughput GC by reducing the pressure on the GC by doing escape analysis. Maybe that would work even better with the far more powerful region inference of the MLkit.
Re:For Better Computing, Liberate CPUs from Garbage Collection by pedrocr on Thursday May 09, 2019 @10:08AM (#19868402)
> Like Rust but without the need for Rc and Arc boxes. Rust gets us 80% of the way there.

I think you're qualifying Rc/Arc as kludges to get around the type system. They may end up being used like that sometimes but when well used they are actually encoding extra semantics, just like &Type and &mut Type.

A simple example is a cache get() method:

pub fn get(&self, key: &K) -> Option<Arc<V>>

https://docs.rs/multicache/0.5.0/multicache/struct.MultiCach...

This allows you to get and use a cache value across your program and depending on outside input the value can disappear first in the cache by eviction or in the consumer. So Arc<V> is already expressing to the compiler the exact semantics. It just so happens that the actual lifetime is runtime defined from outside input so it must be managed dynamically.

I don't see a general way around that without copying but maybe a lot more can be inferred automatically so you get similar ergonomics to a GC language by introducing Rc/Arc/etc automatically at compile time. I don't think that's a good fit for a system programming language like Rust though where you don't pay extra costs without asking for them explicitly. But maybe there's space for a higher level language that does all that magic and doesn't use a GC. Someone trademark Rustscript.

Re:For Better Computing, Liberate CPUs from Garbage Collection by jules on Thursday May 09, 2019 @03:44AM (#19866189)
It isn't clear that what you're asking for is even theoretically possible, and it's far from obvious that the end result would be comparable to GC in terms of productivity.
Re:For Better Computing, Liberate CPUs from Garbage Collection by mcguire on Thursday May 09, 2019 @01:52PM (#19870472)
In Rust, does the standard way of implementing a graph structure still use a vector of nodes and indices for edges?

I think I saw a Rust implementation of an arena. Is it working?

Re:For Better Computing, Liberate CPUs from Garbage Collection by holy_city on Thursday May 09, 2019 @02:13PM (#19870675)
>In Rust, does the standard way of implementing a graph structure still use a vector of nodes and indices for edges?

You'd probably want to do this whenever you implement a graph in a performant language, it's faster and safer (depending on the problem). Implementing edges as vectors of pointers is an exercise in memory leaks and data races, imo.

You can see an implementation with adjacency lists here:

https://github.com/bluss/petgraph/blob/master/src/graph_impl...

>I think I saw a Rust implementation of an arena. Is it working?

https://docs.rs/typed-arena/1.4.1/typed_arena/