3 ms·
Could a Rust like borrow checker automatically and transparently insert the refcount logic only when it's needed, slowing down only access to variables with mul
by cornholio 3y ago
Could a Rust like borrow checker automatically and transparently insert the refcount logic only when it's needed, slowing down only access to variables with multiple owners, which would be a minority?
And perhaps declare some special variables as "resource" to inform the compiler to really enforce the single write owner rule, for "special" external things like file descriptors etc.
IMHO, memory as a tightly managed resource is adequate for system programming, but a
hindrance in most other general programming tasks. But the approach has its point for actual resources any program needs to manage, allowing powerful compile time checks.
So make it optional, with the default being automatic memory management.
- FeepingCreature 3y agoI'm coming from a D perspective, where you really don't want to enforce anything single-owner-like, because it makes algorithms awkward. Neat does some commonsense optimizations to avoid pointless refcount changes, for instance it internally assumes that all function parameters are managed by the caller and doesn't take an additional reference for them. But at the end of the day, it mostly just refcounts and calls it good enough. You can define types in Neat that are noncopyable, but it really limits what you can do with them. For instance, nested function references are noncopyable by default to avoid forcing closure allocations.
- beagle3 3y agoYou’ve basically described Nim’s memory management.
- shoozza 3y agoI think lobster does this. "Compile time reference counting / lifetime analysis / borrow checker."[1] "Reference Counting with cycle detection at exit, 95% of reference count ops removed at compile time thanks to lifetime analysis."[1] [1] https://strlen.com/lobster/ https://strlen.com/lobster/