[quote=“Amanieu, post:10, topic:3188”]
Yes it is, because you are using a &u64, which guarantees that it points to a valid instance of u64. Now, this isn’t actually specified in the documentation, but Rust (at least the way it is currently implemented) will also assume that it points to normal memory where reading the value multiple times will not result in any side-effects and will always return the same value.[/quote]
So, would it be fair to say that a Rust reference is equivalent to a non-NULL pointer-to-non-volatile object?
So, would it be fair to say that a Rust pointer is equivalent to a C pointer to volatile object?
In particular, if this is all true, it means that no function could ever safely use reference types and then later cast them to pointers for the purpose of calling volatile_load or volatile_store, as the compiler may insert speculative loads ahead of the cast from reference to pointer. This has the pretty amazing consequence, AFAICT, that one cannot create a safe (doesn’t require the use of unsafe) API that ever uses volatile memory.
If so, that actually sounds pretty OK to me for the time being. However, it would be nice to also have a safe (i.e. doesn’t require the use of unsafe) API for volatile memory in Rust, because pointers are too unsafe. AFAICT, that would require an extension to the type system, or at least the creation of volatile types analogous to Rust’s atomic types.
Also, IMO it is very important that it is clearly documented in the Rust reference that references are non-volatile and pointers are volatile, if this is all true.