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.
- Read : NaReadType
- Retag : NaReadType
Instances For
Equations
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Errors corresponding to Rust conversion failures, checked timestamp overflow, and assertions/panics in the selected value operations.
- timestampOverflow : ClockError
- vectorIndexOverflow : ClockError
- setAtIndexWouldDecrease : ClockError
- mutableIndexOutOfBounds : ClockError
Instances For
Equations
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Equations
Equations
- One or more equations did not get rendered due to their size.
Instances For
Model Idx::new: converting a host index above u32::MAX panics upstream.
Equations
- Miri.Concurrency.VectorIdx.ofNat value = if h : value < 4294967296 then Except.ok { value := ⟨value, h⟩ } else Except.error Miri.Concurrency.ClockError.vectorIndexOverflow
Instances For
The largest time encodable above a one-bit read type in a packed u32.
Equations
- Miri.Concurrency.maxTimestamp = 2147483647
Instances For
Equations
Equations
- One or more equations did not get rendered due to their size.
Instances For
The all-zero timestamp.
Equations
Instances For
The raw packed u32 value as a natural number.
Equations
- timestamp.packedValue = ↑timestamp.packed
Instances For
Decode the timestamp by shifting away the low read-type bit.
Instances For
Decode the low bit as a regular read or retag read.
Equations
- timestamp.readType = if ↑timestamp.packed % 2 = 0 then Miri.Concurrency.NaReadType.Read else Miri.Concurrency.NaReadType.Retag
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
The packed-word constructor, useful for faithful decoding of existing u32 values.
Instances For
Equality corresponding to Rust PartialEq: the packed read/retag bit is ignored.
Instances For
Preserve the read type while replacing time; encoding overflow is an upstream panic.
Equations
- timestamp.setTime time = Miri.Concurrency.VTimestamp.encode time timestamp.readType
Instances For
Preserve time while replacing the packed read/retag bit.
Equations
- timestamp.setReadType Miri.Concurrency.NaReadType.Read = { packed := ⟨2 * timestamp.time, ⋯⟩ }
- timestamp.setReadType Miri.Concurrency.NaReadType.Retag = { packed := ⟨2 * timestamp.time + 1, ⋯⟩ }
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.
Instances For
Equations
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
Equations
Equations
The logical timestamp slice corresponding to the internal vector.
Equations
Instances For
The all-zero vector clock.
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
- Miri.Concurrency.VClock.zero.last? = none
- (Miri.Concurrency.VClock.nonzero a a_1 a_2).last? = some a_1
Instances For
Read a clock entry; absent vector indices denote VTimestamp::ZERO.
Equations
- clock.index index = (Miri.Concurrency.VClock.listIndex?✝ clock.asList index.toNat).getD Miri.Concurrency.VTimestamp.ZERO
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
- left.join right = Miri.Concurrency.VClock.ofList (Miri.Concurrency.VClock.joinLists✝ left.asList right.asList)
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
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
- Miri.Concurrency.VClock.equalLists [] [] = true
- Miri.Concurrency.VClock.equalLists (left :: leftRest) (right :: rightRest) = (left.sameTime right && Miri.Concurrency.VClock.equalLists leftRest rightRest)
- Miri.Concurrency.VClock.equalLists x✝¹ x✝ = false
Instances For
Compare the common vector prefix using Miri's partial-order accumulation rule.
Equations
- Miri.Concurrency.VClock.compareCommon Ordering.eq (left :: leftRest) (right :: rightRest) = Miri.Concurrency.VClock.compareCommon (left.compare right) leftRest rightRest
- Miri.Concurrency.VClock.compareCommon Ordering.lt (left :: leftRest) (right :: rightRest) = none
- Miri.Concurrency.VClock.compareCommon Ordering.lt (left :: leftRest) (right :: rightRest) = Miri.Concurrency.VClock.compareCommon Ordering.lt leftRest rightRest
- Miri.Concurrency.VClock.compareCommon Ordering.gt (left :: leftRest) (right :: rightRest) = none
- Miri.Concurrency.VClock.compareCommon Ordering.gt (left :: leftRest) (right :: rightRest) = Miri.Concurrency.VClock.compareCommon Ordering.gt leftRest rightRest
- Miri.Concurrency.VClock.compareCommon order x✝¹ x✝ = some order
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 strict-greater-than comparison.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Build a read-only clock from timestamps, canonicalizing only trailing time-zero entries.
Equations
- Miri.Concurrency.VClock.fromTimestamps timestamps = Miri.Concurrency.VClock.ofList timestamps
Instances For
Equations
- Miri.Concurrency.instBEqVClock = { beq := fun (left right : Miri.Concurrency.VClock) => Miri.Concurrency.VClock.equalLists left.asList right.asList }