7 ms·
Do you have specification of a memory model?
by mesaframe 6y ago
Do you have specification of a memory model?
- kibwen 6y agoI believe it's safe to assume that Rust's memory model is (a subset of) C++11's memory model, since that's what LLVM implements. At this point I don't see how any specification could deviate significantly from that without breaking tons of code.
- Jweb_Guru 6y agoThe Rust memory model is deviating from it a little in order to enable some norestrict-based optimizations that aren't really done for C, even though (as you know) LLVM can't really take advantage of them yet.
- staticassertion 6y agoI imagine that in C if the compiler can prove that two pointers don't alias than it can elide a load?
- pjmlp 6y agoIt is very much compiler specific, and also depends if modifiers like volatile are present or not.
- Jweb_Guru 6y agoSure, or with C++ TBAA it can do that too, but those rules work differently from the kinds of guarantees that Rust's type system provides. The C equivalent is (sort of) restrict, but it's used very rarely--so no one has really worked out what its semantics would be like if it were used at the same scale it is in Rust, and there are a lot of bugs.
- steveklabnik 6y agoNot yet. That falls under the "underspecified, but there is active work ongoing" bit. There's a lot there.
- GlitchMr 6y agoIt's work in progress, however you may want to take a look at https://rust-lang.github.io/unsafe-code-guidelines/ https://rust-lang.github.io/unsafe-code-guidelines/. As far thread safety goes (threads, locks, atomics), memory model matches C++ specification.