vyre-conform 0.1.0

Conformance suite for vyre backends — proves byte-identical output to CPU reference
Documentation
/// One entry per missing or malformed field encountered while
/// iterating the registry. Reports the op id and the specific gap so
/// the failure message tells the contributor exactly what to fix.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum CoverageError {
    /// The op declares the empty Category A marker (`composition_of`
    /// empty). Every op must be classified as Category A (with a
    /// real composition list) or Category C (with hardware and backend
    /// availability declarations).
    UnclassifiedCategory {
        /// Op id.
        op_id: String,
    },
    /// The op's `signature.inputs` is empty. Every op consumes at
    /// least one value.
    EmptySignature {
        /// Op id.
        op_id: String,
    },
    /// The op declares no laws. Empty-law ops are legal only for ops
    /// that genuinely have no algebraic structure; this branch
    /// reports them so the reviewer can decide.
    EmptyLawSet {
        /// Op id.
        op_id: String,
    },
    /// The op's `docs_path` is empty. Every op must point at its
    /// documentation page.
    MissingDocsPath {
        /// Op id.
        op_id: String,
    },
    /// The op's `since_version` is ahead of `CURRENT_VERSION`. A
    /// contributor cannot declare an op as shipping in a future
    /// version that doesn't exist yet.
    FutureSinceVersion {
        /// Op id.
        op_id: String,
        /// Declared version as a human-readable string.
        declared: String,
    },
    /// The op is Category C but did not declare a hardware intrinsic identifier.
    MissingCategoryCHardware {
        /// Op id.
        op_id: String,
    },
    /// The op declared the same id twice — the registry has a
    /// duplicate entry.
    DuplicateOpId {
        /// The duplicated op id.
        op_id: String,
    },
    /// `laws` and `declared_laws` disagree.
    LawListDrift {
        /// Op id.
        op_id: String,
    },
    /// A witnessed proof uses zero witnesses.
    ZeroWitnesses {
        /// Op id.
        op_id: String,
        /// Law name.
        law: String,
    },
    /// The selected oracle has no backing data.
    InvalidOracle {
        /// Op id.
        op_id: String,
        /// Diagnostic.
        message: String,
    },
    /// A spec-table row is malformed.
    InvalidSpecRow {
        /// Op id.
        op_id: String,
        /// Row index.
        row: usize,
        /// Diagnostic.
        message: String,
    },
    /// A source/provenance declaration is malformed.
    InvalidSource {
        /// Op id.
        op_id: String,
        /// Diagnostic.
        message: String,
    },
    /// `docs_path` does not point at operation docs.
    InvalidDocsPath {
        /// Op id.
        op_id: String,
    },
    /// The file at docs_path does not exist.
    MissingDocsFile {
        /// Op id.
        op_id: String,
        /// Path that was checked.
        path: String,
    },
    /// The op declares no archetypes. Every op must participate in at least one
    /// test-input archetype.
    EmptyArchetypeSet {
        /// Op id.
        op_id: String,
    },
    /// The op declares an archetype id that is not in the global ARCHETYPES registry.
    UnknownArchetype {
        /// Op id.
        op_id: String,
        /// Unrecognized archetype id.
        archetype: String,
    },
}

impl core::fmt::Display for CoverageError {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::UnclassifiedCategory { op_id } => write!(
                f,
                "{op_id}: Category::unclassified() marker is not allowed. \
                 Fix: declare Category::A {{ composition_of: vec![...] }} \
                 or Category::C {{ hardware, backend_availability }}."
            ),
            Self::EmptySignature { op_id } => write!(
                f,
                "{op_id}: signature.inputs is empty. Fix: every op consumes at \
                 least one value."
            ),
            Self::EmptyLawSet { op_id } => write!(
                f,
                "{op_id}: declares no algebraic laws. Fix: run inference on the \
                 reference_fn — if no laws hold, document the reason in the \
                 op's module doc comment."
            ),
            Self::MissingDocsPath { op_id } => write!(
                f,
                "{op_id}: docs_path is empty. Fix: point it at the op's \
                 documentation page, e.g. \"docs/ops/primitive/add.md\"."
            ),
            Self::FutureSinceVersion { op_id, declared } => write!(
                f,
                "{op_id}: since_version {declared} is ahead of CURRENT_VERSION. \
                 Fix: set since_version to CURRENT_VERSION, or ship a version \
                 bump first."
            ),
            Self::MissingCategoryCHardware { op_id } => write!(
                f,
                "{op_id}: Category::C declared without a hardware intrinsic identifier. \
                 Fix: add hardware: \"...\" and backend_availability."
            ),
            Self::DuplicateOpId { op_id } => write!(
                f,
                "{op_id}: duplicate op id in the registry. Fix: every op id \
                 must be unique."
            ),
            Self::LawListDrift { op_id } => write!(
                f,
                "{op_id}: laws and declared_laws disagree. Fix: make the two law lists exactly match."
            ),
            Self::ZeroWitnesses { op_id, law } => write!(
                f,
                "{op_id}: law {law} uses zero WitnessedU32 witnesses. Fix: set count > 0."
            ),
            Self::InvalidOracle { op_id, message } => {
                write!(f, "{op_id}: invalid oracle override: {message}")
            }
            Self::InvalidSpecRow {
                op_id,
                row,
                message,
            } => write!(f, "{op_id}: invalid spec row {row}: {message}"),
            Self::InvalidSource { op_id, message } => {
                write!(f, "{op_id}: invalid source provenance: {message}")
            }
            Self::InvalidDocsPath { op_id } => write!(
                f,
                "{op_id}: docs_path must point under docs/ops/. Fix: use a repository-relative operation docs path."
            ),
            Self::MissingDocsFile { op_id, path } => write!(
                f,
                "{op_id}: docs_path file missing at '{path}'. Fix: create the documentation file or correct the path."
            ),
            Self::EmptyArchetypeSet { op_id } => write!(
                f,
                "{op_id}: archetypes list is empty. Fix: declare at least one archetype id from the locked vocabulary."
            ),
            Self::UnknownArchetype { op_id, archetype } => write!(
                f,
                "{op_id}: unknown archetype '{archetype}'. Fix: use an id from the global ARCHETYPES registry."
            ),
        }
    }
}

impl core::error::Error for CoverageError {}