John Nunley (notgull) writes about Rust, async/await internals, unsafe code, and compiler bootstrapping, including the Dozer Rust compiler in C.
HN commenters link it for Dozer, a bare-bones Rust compiler in C meant to simplify bootstrapping, and debate its claims about unsafe Rust.
> If you at all break the rather subtle rules, then essentially anything can and will happen.
If by subtle rules you mean your invariants, that is missing fundamental assumptions.
It's akin to making a building without foundation and load bearing structures.
> So for example, there was recently a thread where someone had code that checked if a value was in range to safely coerce it directly to an enum then did so. But because of eager evaluation of an argument the unsafe cast happened first
You mean this: https://notgull.net/cautionary-unsafe-tale/
However note the UB goes away if you never use any unsafe code. Or if you expand your unsafe to encompas some safe code.
Issue it had was safe code was invalidating the invariants unsafe code was relying on. Iirc alignment.
> Another way to see the benefit of this approach is that if you have a memory violation, then you only have to look in the unsafe blocks.
Not really. Safety is non-local. It is possible to break unsafe code by feeding inputs from safe Rust that don't uphold the invariants that make the unsafe code safe. So it's not enough to look in the unsafe blocks--you have to consider the all the contexts that invoke the unsafe code.
See https://doc.rust-lang.org/nomicon/working-with-unsafe.html, and https://notgull.net/cautionary-unsafe-tale/ for a practical example.
There was a project [0] to write a bare bones rust compiler (no borrow checking) in C that aims to be able to build rustc in order to simplify bootstrapping, but it seems to have stalled.
[0] https://notgull.net/announcing-dozer/
See also https://notgull.net/announcing-dozer/ -- removes C++ and LLVM from the stack needed to bootstrap Rust.
Dozer might be the most likely path to that.
https://notgull.net/announcing-dozer
Correct link: https://notgull.net/device-afd/