Vale's generational references memory management and Higher RAII vs Julia and other languages

Vale is a very interesting language, and what can Julia learn from it?

Julia could (should?) add a. Higher RAII (i.e. linear structs), i.e. new syntax and semantics (I think hope in a non-breaking way), and b. its generational references.

[Nim’s ORC memory management (as of 2.0 its default) is also intriguing, but less radical it seems, then maybe easier?).]

https://verdagon.dev/blog/higher-raii-uses-linear-types

If you look up linear types online, you’ll find a lot of unhelpful definitions, like a linear type is a type that can’t be aliased, can’t be cloned, and must be “used” exactly once. 0

That’s somewhat unhelpful because, as Vale shows us, you can have a linear struct without any of the above restrictions.

  • You can read/modify it as much as you like.
  • You can copy it.
  • You can make aliases to it.

So for now, let’s use a less correct but more helpful definition: A linear struct must eventually be explicitly destroyed.

https://verdagon.dev/blog/generational-references

Generational references are a memory management technique, an alternative to reference counting, tracing garbage collection, or borrow checking. 0

https://verdagon.dev/blog/hybrid-generational-memory

Vale’s hybrid-generational memory is a new memory model that aims to combine all the best parts of existing memory strategies: easy as garbage collection, deterministic as reference counting, and as fast as borrow checking.

https://verdagon.dev/blog/linear-types-borrowing

If you’ve used a language like Rust before, this might feel familiar: own-lending is semantically equivalent to borrowing a &mut Random and passing it around.
[…]
It slowly sank in over the next few days.

Using own-lending, we can completely eliminate every single generation check in a program, to get memory safety without borrow checking, reference counting, or tracing garbage collection.
[…]
To get a sense of this “linear style”, I like to compare it to Rust’s borrow checking, because they’re surprisingly similar.

They both have some benefits:

  • Memory safety with no direct extra costs. 11
  • Safety from data races; data races happen when two threads use references to access the same object, but we only ever allow one reference.

C23 adds, and seemingly Julia should too Libc.free_sized and Libc.free_aligned_sized (and aligned_alloc from C11):
https://en.cppreference.com/w/c/memory

more options like gmalloc and zmalloc:

2 Likes