I was thinking of designing a programming language with opt-in (or opt-out) GC, and how that could be achieved. The point is to hit a 80/20 target, where 80% of your code-base does not have to be fast, but 20% must be. Languages like Rust are mostly geared towards projects where 99% of your code must be fast, and in Go, OCaml, Java etc there’s no way to opt-out of blocked GC, and performance is not explicit nor predictable.
The opt-out of GC must be memory safe. I believe this can be achieved with non-escaping variables, without a burden of lifetime annotations like in Rust.
I wanted to apply escape analysis to enforce stack allocated variables to NOT escape their scope. They can be shared, mutated and aliased anyway besides that. This is less restrictive compared to uniqueness types (or rather, has other trade-offs, one could say).
For opt-in GC, I was thinking maybe explicit regions? Or implicit regions? Or even ref count? One can imagine a system which supports both, actually, but not sure if it’s needed.
Regions also need to be non-escaping, but you can pass around its variables in a way you can’t with pure stack allocations.
Note: Nim does not fill the gap, because it doesn’t support multiple memory allocation strategies within the same compilation unit.
The language is supposed to compile to C. Done in OCaml, of course, with Menhir.
Thankful for any feedback. ^^
Edit:
Possible syntax:
local p = Point {1, 2}; // Stack alloc
let q = Point {2, 3} in r; // Region
let s = Point {4, 5}; // Ref count