vyre-conform 0.1.0

Conformance suite for vyre backends — proves byte-identical output to CPU reference
Documentation
//! Reproducible random inputs.

use std::sync::atomic::{AtomicU64, Ordering};

/// Deterministic seed derivation from one master seed.
#[derive(Debug)]
pub struct SeedStream {
    master: u64,
    counter: AtomicU64,
}

impl SeedStream {
    /// Create a seed stream from the master seed.
    pub const fn new(master: u64) -> Self {
        Self {
            master,
            counter: AtomicU64::new(0),
        }
    }

    /// Return the master seed.
    pub const fn master(&self) -> u64 {
        self.master
    }

    /// Derive a reproducible per-test seed from tuple identity.
    #[inline]
    pub fn derive(&self, op: &str, archetype: &str, oracle: &str) -> u64 {
        let mut hasher = blake3::Hasher::new_derive_key("vyre-conform-test-seed");

        let n = self.counter.fetch_add(1, Ordering::Relaxed);

        hasher.update(&self.master.to_le_bytes());

        hasher.update(&(op.len() as u64).to_le_bytes());
        hasher.update(op.as_bytes());

        hasher.update(&(archetype.len() as u64).to_le_bytes());
        hasher.update(archetype.as_bytes());

        hasher.update(&(oracle.len() as u64).to_le_bytes());
        hasher.update(oracle.as_bytes());

        hasher.update(&n.to_le_bytes());

        let hash = hasher.finalize();
        let bytes = hash.as_bytes();
        u64::from_le_bytes([
            bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7],
        ])
    }
}