Rust simply lacks that mapping, yet.
Rust simply lacks that mapping, yet.
However, Rust and C alike have another whole dimension to their semantics, that of Undefined Behavior, which is not reflected in the assembly, and which needs to be taken into account for unsafe code authors (in Rust) / by all programmers (in C). See for example https://www.ralfj.de/blog/2019/07/14/uninit.html for what goes wrong when you think of C as just a macro assembler.
But this is no different from C! The way C programs interact with memory is defined in very similar terms to MiniRust's memory interface trait, using "objects" with some rules for which pointers are allowed to interact with which objects.
In both C and Rust, if you want to do pointer tagging or bit packing, you need to consider the language's rules carefully- this does not mean you cannot do it in either case, only that you are stepping close to the boundary of what is supported.
(Maybe that's what you meant, it wasn't entirely clear.)
I'm completely fine with difficult semantics in weird corners of the language. I just want to know them tho :D.
Yes. It's called type safety / type soundness: you cannot cause UB in safe code.
I literally did a PhD on that topic: https://research.ralfj.de/phd/thesis-screen.pdf
Just today we had this nice example on the front page where initializing a variable differently completely changed the codegen for large parts of the program: https://jpieper.com/2022/08/05/debugging-bare-metal-stm32-fr...
I don't expect to have a good mental model of an optimising compiler in "gotta go fast"-mode, but a mental model of what the memory layout looks like is pretty darn relevant when designing or working with ABIs and binary data representations.
If you only use raw pointers, Rust has significantly less UB that C does.
But if you use references, then yeah we have those aliasing rules and they can be quite restrictive.
You wrote a PHD on it so you might have a better idea of the issues that past me ran into, than what present me can still recall ;)
I'll throw you folks an issue over the fence, should I run into the same problems again, pinky swear ;)
Whats the current state of the art for unsafe code? The guidelines?(https://rust-lang.github.io/unsafe-code-guidelines/)
I found the Rustonomicon, despite it's mythological status, to be quite thin. ^^'
I'm not sure where you got the idea otherwise, but Rust supports the same memory layouts and ABIs as C on a given platform.
You don't get a specific layout by default because that allows for the implementation to improve over time, but that's not really relevant when working with binary data representations, where you simply specify which one to use.
cough https://riscv.org/wp-content/uploads/2018/05/10.45-clifford-...
There are plenty of undefined things in ISAs, writing to some internal ARM registries also springs to mind, but that's a bit of a red herring. Just because code with undefined behaviour doesn't map to some abstract machine model nicely, doesn't imply that code that doesn't invoke UB can't have a simple mapping to some abstract machine semantics.
The VSP hack on Commodore 64 comes to mind.
No there isn't. "Something von neumann-ish" would have behaviour for all inputs - maybe not desirable behaviour, maybe even different behaviour on different processor revisions, but it would have behaviour. The C abstract machine doesn't.
That applies to pretty much all imperative languages that compile directly to assembly/machine code – including Rust.