M
Modular•2mo ago
Nagaraj Hegde

Mojo documentation says "The Mojo compiler uses lifetime values to track the validity of references.

Specifically, a lifetime value answers two questions:What logical storage location "owns" this value?Can the value be mutated using this reference? If so, why call it as lifetime? Rather call it as 'refscope' or 'reftype' or something like that. the term 'lifetime' i think confusing when used to describe a reference. Or is there any reason which I'm missing. May be my understanding is limited, I'm pretty new to this. Thanks.
4 Replies
Melody Daniel
Melody Daniel•2mo ago
the name has been changed to "origin" and will probably change again before Mojo reaches stability
Nagaraj Hegde
Nagaraj HegdeOP•2mo ago
Thanks for the info. Good to hear that more sensible stuffs are coming 🙂 They seem to be good in everything else in language development except naming, just as in the name of the language itself 😉
Darkmatter
Darkmatter•2mo ago
Lifetime is related to how long a value "lives". Accessing a "dead" value is also known as a use after free, which is bad. The concept of a lifetime is only loosely related to a reference, since GC languages also have lifetime tracking, they just don't make it visible or do it to nearly the same degree. You can have references without lifetimes, like C++, but they are usually heavily restricted and can still cause crashes. Mutability is another dimension. When you combine all of them with a borrow checker, then you can have memory safety. They are being changed to Origins because in Mojo having a reference actually keeps the value alive when it would otherwise be cleaned up.
Nagaraj Hegde
Nagaraj HegdeOP•2mo ago
Thank you for the detailed explanation!
Want results from more Discord servers?
Add your server