3 ms·
I must be missing something because I don't see how this is an advance over anything. You have a FREE function, so use-after-free at runtime is still possible.
by ogogmad 4y ago
I must be missing something because I don't see how this is an advance over anything. You have a FREE function, so use-after-free at runtime is still possible. Why not just have malloc and free together then, and program in C but without any lexical scoping so that "Look ma no garbage"?
[edit]
I see why C without scoping would still produce garbage:
int* foo = malloc(sizeof(int));
foo = null;
Linear Lisp forces you to clean up memory. It doesn't allow complex data structures to be assigned to variables without moving the existing contents of those variables elsewhere where they can be disposed of later.
- kryptiskt 4y agoI don't know about Linear Lisp, but if you do linear types as in Wadler's "Linear Types Can Change the World"[0] then the absence of the call to free would be a compilation error. [0] https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.31.5002&rep=rep1&type=pdf https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.31...
- ithkuil 4y agoWhy not inserting a call to free automatically instead of forcing you to do it manually?
- southerntofu 4y agoIsn't that exactly why Rust needs lifetime annotation and Drop trait implementations? How could you achieve the same result without that, or without a garbage collector alternatively?
- shirleyquirk 4y agoYou'd use automatic reference counting, as Swift and Nim do.
- southerntofu 4y agoGood point! I had previously assumed this was considered a form of "garbage collector" although not tracing.
- j-james 4y agoWell, sort of - it adds overhead, though in the form of an extra byte/object and an extra CPU cycle when objects are allocated/deallocated to check/update the reference counts, rather than the lag spikes tracing GCs are known for.
- whateveracct 4y ago1. When you call free matters - it does something after all! 2. You can build abstractions that call free for you. The common withX callback-style function can be better typed with linear types and call free for you, for instance.
- ithkuil 4y ago2 would be a kind of explicit destructors/drop ?
- pjmlp 4y agoSomething like this fictional language, with-some-resource { res -> // use res as you like } The with-some-resource function takes care of the resource management, while the type system takes care res doesn't escape the lambda.
- ithkuil 4y agoWhat if you want to move the ownership of the resource and let the new owner eventually to dispose it?
- whateveracct 4y agoThen withX isn't the right abstraction. The original situation (malloc gives you a linear variable) handles what you want. A function that takes the variable but does not return it effectively "takes ownership of it" and the type system will force a free. There's a "Linear Constraints" paper draft out there that emulates ownership and borrowing with linear types, and uses the titular new language feature to greatly improve ergonomics.
- pjmlp 4y agoBecause it is based on linear types, not affine types. With affine types, like Rust, you can use a type zero or one times, with linear types you must use it exactly once. So not calling free() as per all possible dataflow analysis, would be a compilation error. By the way, this is the approach adopted by Haskell with Linear Haskell extensions.