Per-location weak-memory store buffers from pinned Miri #
This module ports the local StoreBuffer state and operations in the pinned
upstream/miri-source/src/concurrency/weak_memory.rs (Miri revision
7fa591d7d4dd9af8154becbc8332f8096f8323b1, Git blob
4838144d1d8625379f28ead9864bcfea72a16cc0). It preserves modification-order
entries, their per-store synchronization clocks, SC marks, values, and
first-load metadata, plus Miri's 128-entry limit and all fetch_store
candidate restrictions.
Miri chooses uniformly at random from the legal candidate set. Lean models the support of that choice as a finite list and permits an explicit rank to select any member; it does not model probabilities. Enumerating the list is an over-approximation of individual source executions by construction: every selected result is a member of the exact source filter's set, and every source result lies in that set. No single random seed is used to justify a safety claim.
Interpreter memory updates, RNG distribution, atomic-access validation
callback, diagnostics, and Miri's complete operation dispatch are outside this
local slice. bufferedReadAt accepts the validation transition explicitly and runs
it after selecting an entry but before recording load metadata, matching the
source order. Scalar values are abstracted as a Lean type parameter; none
is the source's uninitialized scalar case. This is not a complete Rust or Miri
weak-memory semantics.
Maximum number of retained modification-order entries in Miri.
Equations
Instances For
Whether a selected weak-memory load returned the newest modification-order entry or an older one.
- Latest : LoadRecency
- Outdated : LoadRecency
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Equations
Explicit failures for invalid local buffer/rank operations. Normal buffers cannot be empty or exceed the source capacity.
- emptyStoreBuffer : WeakMemoryError
- bufferTooLong : WeakMemoryError
- choiceOutOfBounds : WeakMemoryError
- selectedIndexOutOfBounds : WeakMemoryError
Instances For
Equations
Equations
- One or more equations did not get rendered due to their size.
Instances For
First-load metadata stored on each source store element. The list is a
finite-map representation keyed by VectorIdx.toNat; insertion preserves the
first timestamp, as FxHashMap::try_insert does.
- timestamps : List (VectorIdx × VTimestamp)
- scLoaded : Bool
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Equations
Read the recorded first timestamp for one thread, if present.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Record a load by a thread only if that thread has not loaded this element before, and remember whether any load was SC.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Whether an earlier recorded load from this element happens before the current store, matching Miri's SC-store closure condition.
Equations
- element.hasLoadBefore clock = element.loadInfo.timestamps.any fun (pair : Miri.Concurrency.VectorIdx × Miri.Concurrency.VTimestamp) => decide (pair.snd.time ≤ (clock.index pair.fst).time)
Instances For
Apply Miri's ATOMIC LOAD IMPL metadata update and return the stored value.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A nonempty source store buffer. oldest plus newer stores the exact
oldest-to-newest modification order; the proof field enforces the source's
128-entry retention bound.
- oldest : StoreElement Value
- newer : List (StoreElement Value)
Instances For
The retained entries in modification order.
Instances For
The latest modification-order element.
Equations
Instances For
Construct the source's initial non-atomic store, which has no acquireable clock and is not SC. Its thread and timestamp are the source's zero values.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Exact blocking condition used by Miri's fetch_store prefix scan.
Equations
- One or more equations did not get rendered due to their size.
Instances For
One supported outcome of Miri's randomized fetch_store.
- position : Nat
- element : StoreElement Value
- recency : LoadRecency
Instances For
The finite support of Miri fetch_store: candidates are presented in
newest-to-oldest order, preserving distinct modification-order entries.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The initial element and inclusive prefix rule ensure at least one legal candidate for every valid store buffer and clock state.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Record the selected load after external atomic validation has succeeded. The passed clock is the post-validation thread-clock state, as in Miri.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Result of one buffered atomic load, including the selected synchronization clock, chosen value, recency diagnostic bit, and post-validation thread state.
- buffer : StoreBuffer Value
- value : Option Value
- choice : LoadChoice Value
- clocks : ThreadClockSet
Instances For
Execute one legal source read choice. Validation observes that entry's per-element synchronization clock after selection. Load metadata changes only if validation succeeds, in the same order as the source implementation.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Perform Miri's RMW-side read from the latest modification-order element. The RMW does not use randomized stale reads.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Add a store, dropping the oldest element when the current buffer is already at the source limit. SC marking follows the pinned source's two HB/CoWR tests.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Miri's ordinary buffered write: capture the writer's timestamp and the caller-provided release-sequence clock, then append/trim/SC-mark.
Equations
- buffer.bufferedWrite value thread index isSeqCst syncClock = buffer.storeImpl value index thread.clock isSeqCst syncClock
Instances For
Allocation-local range map of atomic objects to their store buffers.
- storeBuffers : DataStructures.RangeObjectMap (StoreBuffer Value)
Instances For
A detached value handle for one perfectly overlapping object. Callers commit it explicitly after their operation; a changed range map invalidates the handle instead of silently updating some other object.
- range : Memory.AllocRange
- position : DataStructures.Position
- buffer : StoreBuffer Value
Instances For
- rangeMap (error : DataStructures.RangeObjectMapError) : StoreBufferAllocError
- handleInvalidated : StoreBufferAllocError
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Pure transition result retains RangeObjectMap's partial mutation on error, matching its insert-before-check behavior.
- allocation : StoreBufferAlloc Value
- outcome : Except StoreBufferAllocError (Option (StoreBufferHandle Value))
Instances For
Equations
Instances For
Equations
- allocation.bufferCount = allocation.storeBuffers.length
Instances For
Equations
- allocation.bufferRanges = allocation.storeBuffers.ranges
Instances For
Remove or retain buffered state after a non-atomic write exactly according
to Miri's ongoing_action_data_race_free flag and overlap classification.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Return a store-buffer handle only for a perfectly overlapping object. Empty and imperfect overlaps return no buffer, as in Miri.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Get an exactly matching buffer or initialize a new one. On imperfect overlap, the old intersecting buffers are removed before insertion, matching Miri's range invalidation order.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Commit a returned buffer handle after the modeled atomic operation.
Equations
- One or more equations did not get rendered due to their size.