Documentation

Miri.Concurrency.VectorClock

Miri's vector-clock value operations #

This module ports the timestamp and vector-clock operations from the pinned upstream/miri-source/src/concurrency/vector_clock.rs (Miri revision 7fa591d7d4dd9af8154becbc8332f8096f8323b1, blob 723dfd29651525198b7590553f1ef5e72b952eba). The stored representation keeps the complete packed 32-bit timestamp word, including the low read/retag bit. Clock comparisons and timestamp equality intentionally inspect time only, as the Rust PartialEq/Ord implementations do.

The source's Span field is omitted. In this file it affects debug output and diagnostic attribution only: increment copies a non-dummy span, join and set_at_index choose a non-dummy span, and none of those span choices affects timestamp time, read type, ordering, clock equality, or update success. The surrounding data-race detector uses spans when rendering diagnostics, which is outside this value-operation port. SmallVec's inline capacity is likewise a storage optimization; this module preserves the logical vector length and trailing-zero invariant, not allocation strategy.

This does not model thread scheduling, synchronization, data-race reports, atomic operations, memory, or full Miri concurrency semantics.

The non-atomic read category packed into a vector timestamp.

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

      Errors corresponding to Rust conversion failures, checked timestamp overflow, and assertions/panics in the selected value operations.

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

          A clock index is exactly a Rust u32 value.

          • value : Fin 4294967296
          Instances For
            Equations
            Instances For
              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                def Miri.Concurrency.VectorIdx.ofU32 (value : Nat) (h : value < 4294967296) :

                Construct the index associated with a Rust u32.

                Equations
                Instances For

                  Model Idx::new: converting a host index above u32::MAX panics upstream.

                  Equations
                  Instances For

                    Convert the index to its mathematical value.

                    Equations
                    Instances For
                      @[simp]
                      theorem Miri.Concurrency.VectorIdx.toNat_ofU32 (value : Nat) (h : value < 4294967296) :
                      (ofU32 value h).toNat = value

                      The largest time encodable above a one-bit read type in a packed u32.

                      Equations
                      Instances For

                        A timestamp stores the exact unsigned 32-bit word 2 * time + readBit.

                        The Fin bound models the raw u32 range without truncating or dropping its retag bit. Rust equality and ordering compare time, not this whole word.

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

                            The raw packed u32 value as a natural number.

                            Equations
                            Instances For

                              Decode the timestamp by shifting away the low read-type bit.

                              Equations
                              Instances For

                                Decode the low bit as a regular read or retag read.

                                Equations
                                Instances For

                                  Encode time and read type, preserving the source's checked-multiply overflow.

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

                                    Encode a timestamp, returning overflow instead of wrapping its packed word.

                                    Equations
                                    Instances For
                                      def Miri.Concurrency.VTimestamp.ofPacked (packed : Nat) (h : packed < 4294967296) :

                                      The packed-word constructor, useful for faithful decoding of existing u32 values.

                                      Equations
                                      Instances For

                                        Equality corresponding to Rust PartialEq: the packed read/retag bit is ignored.

                                        Equations
                                        Instances For

                                          Ordering corresponding to Rust Ord: only the decoded timestamp is compared.

                                          Equations
                                          Instances For

                                            Preserve the read type while replacing time; encoding overflow is an upstream panic.

                                            Equations
                                            Instances For

                                              Preserve time while replacing the packed read/retag bit.

                                              Equations
                                              Instances For

                                                Rust r.max(l): the receiver is the other clock's timestamp, and Rust's Ord::max returns its second argument on ties, so the left/self timestamp wins.

                                                Equations
                                                Instances For
                                                  @[simp]
                                                  theorem Miri.Concurrency.VTimestamp.maxForJoin_left_on_time_tie (left right : VTimestamp) (sameTime : left.time = right.time) :
                                                  left.maxForJoin right = left
                                                  @[simp]
                                                  theorem Miri.Concurrency.VTimestamp.time_setReadType (timestamp : VTimestamp) (readType : NaReadType) :
                                                  (timestamp.setReadType readType).time = timestamp.time
                                                  @[simp]
                                                  theorem Miri.Concurrency.VTimestamp.sameTime_refl (timestamp : VTimestamp) :
                                                  timestamp.sameTime timestamp = true

                                                  A vector clock is either empty or ends in a timestamp whose time is nonzero.

                                                  Its prefix may contain zero timestamps, including timestamp-zero retag reads. This representation enforces Miri's unique trailing-zero-free clock shape.

                                                  • zero : VClock

                                                    The all-zero vector is represented only by the empty clock.

                                                  • nonzero (earlier : List VTimestamp) (last : VTimestamp) (last_time_nonzero : last.time ≠ 0) : VClock

                                                    A canonical clock with arbitrary prefix and a nonzero final time.

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

                                                      The logical timestamp slice corresponding to the internal vector.

                                                      Equations
                                                      Instances For

                                                        The logical number of stored entries.

                                                        Equations
                                                        Instances For

                                                          Build a clock from a logical timestamp list, removing trailing time-zero values.

                                                          Equations
                                                          Instances For

                                                            The last stored timestamp, when the clock is nonempty.

                                                            Equations
                                                            Instances For
                                                              theorem Miri.Concurrency.VClock.last_time_nonzero (clock : VClock) :
                                                              match clock.last? with | none => True | some timestamp => timestamp.time ≠ 0

                                                              The canonical last-entry invariant follows from the representation.

                                                              Read a clock entry; absent vector indices denote VTimestamp::ZERO.

                                                              Equations
                                                              Instances For

                                                                Construct a clock containing only the supplied timestamp at one index. As upstream, any timestamp whose time is zero produces the empty vector, even a retag read.

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

                                                                  Increment the timestamp at a known vector index. Packed-time overflow is returned explicitly instead of wrapping.

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

                                                                    Pointwise join, with the source's left/self raw timestamp chosen on equal times.

                                                                    Equations
                                                                    Instances For

                                                                      Replace one coordinate by the corresponding timestamp of other. This models the source assertion that the coordinate may only increase; the assertion failure is represented explicitly as setAtIndexWouldDecrease.

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

                                                                        Clear all clock entries.

                                                                        Equations
                                                                        Instances For

                                                                          Read the packed read type at an existing coordinate and preserve its time.

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

                                                                            Clone a clock, including every raw read-type bit.

                                                                            Equations
                                                                            Instances For

                                                                              Clone-from has the same logical behavior as replacing the value.

                                                                              Equations
                                                                              Instances For

                                                                                Clock equality corresponding to Rust's derived VClock equality and timestamp PartialEq: length and every decoded time must agree; read/retag bits are ignored.

                                                                                Equations
                                                                                Instances For
                                                                                  @[irreducible]

                                                                                  Compare the common vector prefix using Miri's partial-order accumulation rule.

                                                                                  Equations
                                                                                  Instances For

                                                                                    Partial componentwise vector-clock comparison.

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

                                                                                      Rust's optimized strict-less-than comparison.

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

                                                                                        Rust's optimized less-than-or-equal comparison.

                                                                                        Equations
                                                                                        Instances For

                                                                                          Rust's optimized strict-greater-than comparison.

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

                                                                                            Rust's optimized greater-than-or-equal comparison.

                                                                                            Equations
                                                                                            Instances For

                                                                                              Build a read-only clock from timestamps, canonicalizing only trailing time-zero entries.

                                                                                              Equations
                                                                                              Instances For
                                                                                                theorem Miri.Concurrency.VClock.increment_keeps_canonical (clock : VClock) (index : VectorIdx) (next : VClock) (_h : clock.incrementIndex index = Except.ok next) :
                                                                                                match next.last? with | none => True | some timestamp => timestamp.time ≠ 0
                                                                                                theorem Miri.Concurrency.VClock.join_keeps_canonical (left right : VClock) :
                                                                                                match (left.join right).last? with | none => True | some timestamp => timestamp.time ≠ 0