In Rust, there is no
volatile modifier. Instead, there are unstable “volatile read” and “volatile write” primitives. And, it seems like those will be stabilized soon. So, since there is no
volatile modifier, does that mean that the Rust compiler must assume that all memory is volatile by default? In particular, in general given
x: &u64, the compiler won’t know if x is a reference to value stored in volatile memory, right? Thus, it will never be able to do speculative reads of
x and in general it must make sure it uses
ACCESS_ONCE  style access to every such value, unless it can prove that
x is not a reference to volatile memory, which is in general very hard. Is that right?
It seems like it can’t be right, because this seems like it would be horrible for performance. But, I can’t figure out how the proposed “volatile read” and “volatile write” functions work otherwise. In particular, “volatile read” and “volatile write” seem to only make sense under the assumption that there are no speculative reads/writes to the memory they are writing to, but there’s no way to indicate to rustc that no speculative reads/writes are allowed.