5 ms·
Disclaimer: I'm just a Pascal programmer... so I didn't grok the nitty gritty of the lambda calculus, but I think enough to see where this is going. This evoke
by mikewarot 5y ago
Disclaimer: I'm just a Pascal programmer... so I didn't grok the nitty gritty of the lambda calculus, but I think enough to see where this is going.
This evokes a similar feeling to when I learned that Lisp wasn't John McCarthy's target programming language. I began to wonder how powerful that intended language would have been, if everyone hadn't stopped at the bootstrap language.
There is great power in what is shown, and I suspect even more power in what it enables. I look forward to see where this goes, there clearly could be another similar leap.
Question: Does this mean it's possible to rework Rust to remove the accursed borrow checker? (I tried learning Rust, and stopped at the Borrow Checker, so I gotta ask)
- namibj 5y agoFor the most part, Rust's borrow checker just serves to verify that non-`unsafe` code doesn't modify/deallocate memory that is still accessible through a different pointer (a reference , in Rust terms; actual (raw) pointers free of such implications can't be used for data access without `unsafe`). They further imply that they are non-NULL and their pointee is dereferenceable (no segfault; correctly aligned) and a valid bitpattern for the pointee type. These assumptions are provided to LLVM, allowing a bunch of optimizations already. Mutable references further guarantee `noalias`/`restrict`, as a mutable reference to some memory location implies no other references to that memory exist, an exclusivity enabling aggressive store-to-load forwarding and elimination of redundant stores. The non-NULL nature makes `Option<&T>` pointer-sized, so semantically nullable pointers have no memory cost and just force explicit handling of their NULL state when accessed (there are convenience method-syntax functions and `match` statements who's cases (patterns, in Rust terms) look like type constructors on the left side of a `=>` and have the inner values bound to the identifiers on the expression to the right of the `=>`). If a function itself returns an `Option`, `foo?` can be used to just unpack a `Some(bar)` and `return None;` on the nullable case. This syntax also works with `Result<T, E>` which allows conveying detailed errors (similar to exceptions, but with performance matching C's negative return codes instead of C++'s unwinding). References are written as `&T` for immutable ones and `&mut T` for mutable ones. Raw pointers are written as `const T` for immutable ones and `mut T` for mutable ones. These guarantees of no-mutable-shared-memory not guarded by explicit `Atomic` types (or concurrent datastructures (I count `Mutex` and `RwLock`)) carry semantic guarantees beyond what an auto-`.clone()` and/or GC can provide. I highly suggest you to try Rust again, but this time using non-lexical-lifetimes (NLL(s)), which shift the lifetime enforcement from simple lexical scope to a control-flow-graph based reachability. They lack the unintuitively-restrictive limitations particularly notable with loops, while still simplifying to abstract over combinatorial path explosion. BorrowChk is your friend, I promise. Just ask in e.g. the Community Discord if you're getting rejected for no good reason despite trying to understand/work around it's complaints. You're not really fighting it; it's more like a sparring partner than an enemy. Also, `.clone()` and `#[derive(Debug, Clone, Copy)]` are your friends when fighting BorrowChk.
- southerntofu 5y ago> Question: Does this mean it's possible to rework Rust to remove the accursed borrow checker? Sure, with the "unsafe" keyword. But you probably don't want to do that in most cases as it will open new failure modes the compiler can protect you from. As another commenter pointed out, the borrow checker has become more clever over time (with NLLs) so if you tried Rust years ago i definitely recommend to give it a new try. At first i was a little confused with compiler errors, but they're pretty good (unique error code, and usually suggestions for fix) but over time i realized the compiler was not my enemy but rather a very friendly reviewer preventing me to make obvious mistakes in my code. Nowadays i pseudocode my Rust on paper then write the actual code, then spend some time arguing with the compiler, but the design-code-debug lifecycle has been much reduced (compared with other languages) because there are very good chances the program works perfectly as soon as it compiles, and when it doesn't in 99% of cases that's because my logic was wrong to begin with, not because of a programming error.