News for hackers. Stuff that matters.
Re:Bone Lisp – Lisp Without Garbage Collection by akkartik on Tuesday June 07, 2016 @12:14PM (#11855470)
I'm exploring something similar in my project: https://github.com/akkartik/mu. Where C was designed as a more portable+expressive assembly language, Mu is designed as a more portable+safe assembly language. You have to manually manage memory, but you can't ever end up corrupting your heap or using pointers after free. I provide these guarantees by allocating a refcount with every single allocation. The only way to reclaim memory is to clear a pointer. If you happen to still have other pointers to the allocation you won't actually reclaim it.

Given this setup I can prototype programs without thinking about memory at all. When my program runs out of memory I start measuring allocations and insert the odd pointer clear at strategic places until I don't, then I continue on my merry way. 99.9% of programs we write don't require thinking of "no memory leaks" as a black-and-white cast-iron guarantee.

This setup also provides a really nice teaching experience where students can learn about pointers and write all sorts of programs without ever running into weird bugs due to use-after-free or overflowing bounds. However it adds some overhead akin to a realtime GC: everytime you copy a struct you have to increment refcounts of any pointers nested arbitrarily deep within it (Mu maintains a flattened bitmap for each type to make this not utterly suck). Sum types get even crazier, because you might have a pointer at offset x depending on the state of the tag at offset y, and so on. I'll try to measure the overhead at some point..

Re:Bone Lisp – Lisp Without Garbage Collection by dTal on Wednesday June 08, 2016 @04:13AM (#11860763)
>The only way to reclaim memory is to clear a pointer. If you happen to still have other pointers to the allocation you won't actually reclaim it.

Elegant! It's funny though, on persistent storage we sort of invented this decades ago in the form of hard links. You can have as many hard links as you want to a file, and the file will only be deleted when all links are removed and all file handles are closed.

Re:Bone Lisp – Lisp Without Garbage Collection by akkartik on Wednesday June 08, 2016 @10:22AM (#11862441)
Yes, reference counting is one of those things that keeps coming up everywhere.
Re:Bone Lisp – Lisp Without Garbage Collection by foota on Tuesday June 07, 2016 @03:29PM (#11857086)
This is basically "leaky" reference counting, yeah?
Re:Bone Lisp – Lisp Without Garbage Collection by akkartik on Tuesday June 07, 2016 @03:38PM (#11857153)
Yes, the mechanism is exactly reference counting. However, the goal is totally different. Typically refcounting is used for automatic memory management. Here the goal is safe manual management. (The different goal means that refcounting's well-known inability to collect cycles is irrelevant, among other things.)