Hacker News new | ask | show | jobs
by randomstringxyz 262 days ago
Conceptually, think about it. Coroutines require copying not only the variables but the function itself, outside of the lifetime of the parent function. (Or at least pointers thereto.) I would like to hear about a language with static coroutines but I am not aware of any. Even Rust doesn't do it, they just make you pass the lifetime around.
1 comments

The parent is talking about closures, not coroutines. Rust does have closures that don't require a GC or passing lifetimes around (there's not even any syntax for putting a lifetime on a closure).
Rust closures can have lifetimes, and the lifetime of a closure is restricted to the lifetime of the shortest lived reference that it captures. But that just means the compiler protects you from having dangling pointers in your closure. And I don't think you can get much better than that without a runtime garbage collector.
A Rust closure "has" a lifetime in the sense that the anonymous underlying struct that Rust creates to hold the closed-over values has a lifetime, but that's not a requirement to have closures without a GC. Like C++, Odin doesn't care about being memory-safe, so you can just say "be careful doing anything that involves pointers" (which is how the language already works), or if you wanted to be a little safer you could just forbid closing over anything that contained a pointer.