3 ms·
Instead of waiting for faster compiler in Rust, how about from the other direction, adding some kind of borrow checker to Zig? That sounds more within reach and
by lioeters 3mo ago
Instead of waiting for faster compiler in Rust, how about from the other direction, adding some kind of borrow checker to Zig? That sounds more within reach and practically achievable, possibly even in userland.
- onlyrealcuzzo 3mo agoThat's sort of what I'm doing... I'm writing a language with Affine Ownership that transpiles to Zig and has a built-in FSM-based Green Fiber runtime. Affine Ownership gives you memory safety + fearless concurrency + eliminates the need for Go's GC. It's obviously going to slow down compilation - since you need to do Rust's borrow checking, etc. But I can do this incrementally as well...
- rienbdj 3mo agoCan selectively turn off the borrow check for dev builds?
- dnautics 3mo ago> how about from the other direction, adding some kind of borrow checker to Zig? That sounds more within reach and practically achievable, possibly even in userland. It's doable, and as static analysis. see sibling comment.
- Ar-Curunir 3mo agoNo, it would fundamentally change how Zig works.
- dnautics 3mo agono, it would not. If you do not believe me, you should try out the repo.
- Ar-Curunir 3mo agothe architecture doesn't make sense. MIRI doesn't perform static analysis on MIR. It is, as the name says, an interpreter. The borrow checker is entirely different from miri. Rust's borrow checker requires lifetime annotations. Zig code doesn't contain any such annotations. How does your design handle this?
- dnautics 3mo ago1. it is possible to do code annotations in zig even though i havent implemented it in this iteration of clr (the first poc demonstrated this). i want to see how far i can get without them. 2. let's take double free (easiest to explain). you dont have to tag ownership, you can be agnostic about who should free, and merely report if two nondisjoint code paths attempt to free the same memory.
- Ar-Curunir 3mo agoRe 1: that doesn't help with Zig code that doesn't use your annotations. In contrast, Rust forces all code to use annotations. Re 2: that still looks to me to be a runtime check.
- veber-alex 3mo agoIt's impossible to add a borrow checker to any existing language. The reason Rust has a working borrow checker is because every part of the language from structs, enum, traits, generics and all the way to the syntax itself has been designed to support lifetimes and borrow checking. It's is not something you can just tack on to an existing language without fundamentally changing it.
- solatic 3mo agoI wouldn't say it's impossible, rather un-ergonomic. TypeScript can add type information to ordinary JavaScript code via JSDoc comments; the result can both be executed as ordinary JavaScript as-is and type-checked with TypeScript. But it's a huge pain to try to write (and maintain) everything that way, it was supported as a hack to help migrate legacy codebases. You could probably take a similar "the lifetimes are embedded in comments" approach with other languages, and the result would be similarly un-ergonomic.
- afdbcreid 3mo agoThat is possible (clang has experimental lifetime annotations support), but that is not enough to guarantee memory safety. As a simple example, Zig has no private fields. That makes encapsulating any unsafety impossible.
- veber-alex 3mo agoExactly. Every part of the language must support memory safety from first principles.
- dnautics 3mo agoempirically untrue. several projects exist that bolt on extra safety to unsafe languages or unsafe parts of language. SeL4 for C, MIRI for rust unsafe. i guess ada/spark for ada too, is the OG, spark being added to ada 4 years after its first release