Add more bench-cargo-miri programs
These example programs are derived from long-running (>15 minutes) tests in the test suites of highly-downloaded crates (if I have my way, that runtime will not be correct for long). They should serve as realistic but also somewhat pathological workloads for the interpreter.
The unicode program stresses the code which looks for adjacent and equal stacks to merge them.
The backtraces program has an uncommonly large working set of borrow tags per borrow stack.
This also updates the .gitignore to ignore files commonly emitted in the course of using these benchmark programs.
---
The benchmark programs are so-named to avoid confusingly duplicating the names of the crates they are benchmarking. Is that a good idea? I started doing this so that I could use `cargo add` but now I'm not entirely sold on the names.
These example programs are derived from long-running (>15 minutes) tests
in the test suites of highly-downloaded crates. They should serve as
realistic but also somewhat pathological workloads for the interpreter.
The unicode program stresses the code which looks for adjacent and equal
stacks to merge them.
The backtrace program has an uncommonly large working set of borrow tags
per borrow stack.
This also updates the .gitignore to ignore files commonly emitted in the
course of using these benchmark programs.
make clippy mandatory for bors, and silence another clippy lint
We don't currently trigger this but I saw it in a PR and I'd rather evaluate this on a case-by-case basis during review, thank you clippy.
Make scheduler preemptive
This is actually fairly easy. :D I just roll the dice on each terminator to decide whether we want to yield the active thread. I think with this we are also justified to no longer show "experimental" warnings when a thread is spawned. :)
Closes https://github.com/rust-lang/miri/issues/1388
Weak memory emulation using store buffers
This implements the second half of the [Lidbury & Donaldson paper](https://www.doc.ic.ac.uk/~afd/homepages/papers/pdfs/2017/POPL.pdf): weak memory emulation using store buffers. A store buffer is created over a memory range on atomic access. Stores will push store elements into the buffer and loads will search through the buffer in reverse modification order, determine which store elements are valid for the current load, and pick one randomly.
This implementation will never generate weak memory behaviours forbidden by the C++11 model, but it is incapable of producing all possible weak behaviours allowed by the model. There are certain weak behaviours observable on real hardware but not while using this.
Note that this implementation does not take into account of C++20's memory model revision to SC accesses and fences introduced by [P0668](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0668r5.html). This implementation is not fully correct under the revised C++20 model and may generate behaviours C++20 disallows.
Rust follows the C++20 memory model (except for the Consume ordering and some operations not performable through C++'s std::atomic<T> API). It is therefore possible for this implementation to generate behaviours never observable when the same program is compiled and run natively. Unfortunately, no literature exists at the time of writing which proposes an implementable and C++20-compatible relaxed memory model that supports all atomic operation existing in Rust. The closest one is [A Promising Semantics for Relaxed-Memory Concurrency](https://www.cs.tau.ac.il/~orilahav/papers/popl17.pdf) by Jeehoon Kang et al. However, this model lacks SC accesses and is therefore unusable by Miri (SC accesses are everywhere in library code).
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 a previously atomically accessed location, or accessing previously atomically accessed locations with a differently sized operation (such as accessing the top 16 bits of an `AtomicU32`). These scenarios are generally left undefined in formalisations of C++ memory model, even though they [became possible](https://lists.isocpp.org/std-discussion/2022/05/1662.php) in C++20 with `std::atomic_ref<T>`. In Rust, these operations can only be done through a `&mut AtomicFoo` reference or one derived from it, therefore these operations can only happen after all previous accesses on the same locations. This implementation is adapted to accommodate these.
----------
TODOs:
- [x] Add tests cases that actually demonstrate weak memory behaviour (even if they are scheduler dependent)
- [x] Change `{mutex, rwlock, cond, srwlock}_get_or_create_id` functions under `src/shims` to use atomic RMWs instead of separate read -> check if need to create a new one -> write steps
- [x] Make sure Crossbeam tests still pass (https://github.com/crossbeam-rs/crossbeam/pull/831)
- [x] Move as much weak-memory related code as possible into `weak_memory.rs`
- [x] Remove "weak memory effects are not emulated" warnings
- [x] Accommodate certain mixed size and mixed atomicity accesses Rust allows on top of the C++ model