Documentation

Miri.Concurrency.WeakMemory

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.

    Instances For
      Equations
      • One or more equations did not get rendered due to their size.
      Instances For

        Explicit failures for invalid local buffer/rank operations. Normal buffers cannot be empty or exceed the source capacity.

        Instances For
          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.

            Instances For
              Equations
              • One or more equations did not get rendered due to their size.
              Instances For

                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
                  def Miri.Concurrency.LoadInfo.record (info : LoadInfo) (index : VectorIdx) (clock : VClock) (isSeqCst : Bool) :

                  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

                    One store in a location's modification order. Value abstracts Rust's Scalar; none is an uninitialized stored value.

                    Instances For
                      def Miri.Concurrency.StoreElement.hasLoadBefore {Value : Type} (element : StoreElement Value) (clock : VClock) :

                      Whether an earlier recorded load from this element happens before the current store, matching Miri's SC-store closure condition.

                      Equations
                      Instances For
                        def Miri.Concurrency.StoreElement.loadImpl {Value : Type} (element : StoreElement Value) (index : VectorIdx) (clocks : ThreadClockSet) (isSeqCst : Bool) :
                        StoreElement Value × Option Value

                        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.

                          Instances For

                            The retained entries in modification order.

                            Equations
                            Instances For
                              def Miri.Concurrency.StoreBuffer.last {Value : Type} (buffer : StoreBuffer Value) :

                              The latest modification-order element.

                              Equations
                              Instances For
                                def Miri.Concurrency.StoreBuffer.new {Value : Type} (initial : Option Value) :

                                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
                                  def Miri.Concurrency.StoreBuffer.blocksEarlier {Value : Type} (element : StoreElement Value) (isSeqCst : Bool) (clocks : ThreadClockSet) :

                                  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.

                                    Instances For
                                      def Miri.Concurrency.StoreBuffer.fetchChoices {Value : Type} (buffer : StoreBuffer Value) (isSeqCst : Bool) (clocks : ThreadClockSet) :

                                      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
                                        theorem Miri.Concurrency.StoreBuffer.fetchChoices_nonempty {Value : Type} (buffer : StoreBuffer Value) (isSeqCst : Bool) (clocks : ThreadClockSet) :
                                        buffer.fetchChoices isSeqCst clocks ≠ []

                                        The initial element and inclusive prefix rule ensure at least one legal candidate for every valid store buffer and clock state.

                                        def Miri.Concurrency.StoreBuffer.fetchAt {Value : Type} (buffer : StoreBuffer Value) (isSeqCst : Bool) (clocks : ThreadClockSet) (rank : Nat) :
                                        Equations
                                        • One or more equations did not get rendered due to their size.
                                        Instances For
                                          def Miri.Concurrency.StoreBuffer.recordSelectedLoad {Value : Type} (buffer : StoreBuffer Value) (choice : LoadChoice Value) (index : VectorIdx) (clocksAfterValidation : ThreadClockSet) (isSeqCst : Bool) :

                                          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.

                                            Instances For
                                              def Miri.Concurrency.StoreBuffer.bufferedReadAt {Value Error : Type} (buffer : StoreBuffer Value) (isSeqCst : Bool) (clocksBeforeValidation : ThreadClockSet) (loadIndex : VectorIdx) (rank : Nat) (validate : VClock → Except Error ThreadClockSet) :

                                              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
                                                def Miri.Concurrency.StoreBuffer.readFromLastStore {Value : Type} (buffer : StoreBuffer Value) (index : VectorIdx) (clocks : ThreadClockSet) (isSeqCst : Bool) :

                                                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
                                                  def Miri.Concurrency.StoreBuffer.storeImpl {Value : Type} (buffer : StoreBuffer Value) (value : Value) (index : VectorIdx) (threadClock : VClock) (isSeqCst : Bool) (syncClock : VClock) :

                                                  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
                                                    def Miri.Concurrency.StoreBuffer.bufferedWrite {Value : Type} (buffer : StoreBuffer Value) (value : Value) (thread : ThreadClockSet) (index : VectorIdx) (isSeqCst : Bool) (syncClock : VClock) :

                                                    Miri's ordinary buffered write: capture the writer's timestamp and the caller-provided release-sequence clock, then append/trim/SC-mark.

                                                    Equations
                                                    Instances For

                                                      Allocation-local range map of atomic objects to their store buffers.

                                                      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.

                                                        Instances For
                                                          Equations
                                                          • One or more equations did not get rendered due to their size.
                                                          Instances For

                                                            Pure transition result retains RangeObjectMap's partial mutation on error, matching its insert-before-check behavior.

                                                            Instances For
                                                              Equations
                                                              Instances For
                                                                Equations
                                                                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.
                                                                        Instances For