|
30 | 30 | //! used to make sure a value in a thread's view is not overwritten by a write that occured earlier than the one in the existing view. |
31 | 31 | //! In our implementation, this is detected using read information attached to store elements, as there is no data strucutre representing reads. |
32 | 32 | //! |
33 | | -//! Safe/sound Rust allows for more operations on atomic locations than the C++20 atomic API was intended to allow, such as non-atomically accessing |
| 33 | +//! The C++ memory model is built around the notion of an 'atomic object', so it would be natural |
| 34 | +//! to attach store buffers to atomic objects. However, Rust follows LLVM in that it only has |
| 35 | +//! 'atomic accesses'. Therefore Miri cannot know when and where atomic 'objects' are being |
| 36 | +//! created or destroyed, to manage its store buffers. Instead, we hence lazily create an |
| 37 | +//! atomic object on the first atomic access to a given region, and we destroy that object |
| 38 | +//! on the next non-atomic or imperfectly overlapping atomic access to that region. |
| 39 | +//! These lazy (de)allocations happen in memory_accessed() on non-atomic accesses, and |
| 40 | +//! get_or_create_store_buffer() on atomic accesses. This mostly works well, but it does |
| 41 | +//! lead to some issues (https://github.com/rust-lang/miri/issues/2164). |
| 42 | +//! |
| 43 | +//! One consequence of this difference is that safe/sound Rust allows for more operations on atomic locations |
| 44 | +//! than the C++20 atomic API was intended to allow, such as non-atomically accessing |
34 | 45 | //! a previously atomically accessed location, or accessing previously atomically accessed locations with a differently sized operation |
35 | 46 | //! (such as accessing the top 16 bits of an AtomicU32). These senarios are generally undiscussed in formalisations of C++ memory model. |
36 | 47 | //! In Rust, these operations can only be done through a `&mut AtomicFoo` reference or one derived from it, therefore these operations |
@@ -156,8 +167,8 @@ impl StoreBufferAlloc { |
156 | 167 | } |
157 | 168 | } |
158 | 169 |
|
159 | | - /// Gets a store buffer associated with an atomic object in this allocation |
160 | | - /// Or creates one with the specified initial value |
| 170 | + /// Gets a store buffer associated with an atomic object in this allocation, |
| 171 | + /// or creates one with the specified initial value if no atomic object exists yet. |
161 | 172 | fn get_or_create_store_buffer<'tcx>( |
162 | 173 | &self, |
163 | 174 | range: AllocRange, |
|
0 commit comments