vyre-conform 0.1.0

Conformance suite for vyre backends — proves byte-identical output to CPU reference
Documentation
//! Meta-mutation operator and catalog types.

/// The 5 core mutation operators for meta-conform harness verification.
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
pub enum MetaOperator {
    /// Change a literal 1 to 0 or increment/decrement a literal.
    OffByOne,
    /// Swap == with !=, < with >, etc.
    SwapComparison,
    /// Replace assert! and similar macros with ().
    DropAssertion,
    /// Change < to <= or > to >=.
    WeakenBound,
    /// Ignore an error result or force a success.
    SwallowError,
}

/// One concrete meta-mutation the harness can apply to vyre-conform sources.
///
/// Every variant carries enough data to both identify the mutation in a
/// report and apply it mechanically to a source file. Adding a variant is
/// matches in downstream contributors.
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
pub enum MetaMutation {
    /// Corrupt a checker to skip one structural boundary witness (e.g., drop
    /// `{0, 1, u32::MAX}` from its sample set).
    CheckerMissBoundary {
        /// Qualified checker path, e.g., `"algebra::checker::commutative"`.
        component: &'static str,
        /// Which boundary this mutation drops — opaque identifier decoded
        /// by [`crate::meta::mutation::apply`].
        boundary: &'static str,
    },
    /// Reduce the checker's witness sample count below the declared
    /// statistical threshold.
    CheckerSkipWitness {
        /// Qualified checker path.
        component: &'static str,
    },
    /// Make an oracle resolver downgrade from `Law` to `Property` on at
    /// least one input class. Represents the "weaker oracle when a stronger
    /// one applies" threat.
    OracleDowngrade {
        /// Qualified resolver path.
        component: &'static str,
    },
    /// Flip one Expr variant in the reference interpreter to return the
    /// wrong answer. Meta-tests must diff every backend against the
    /// interpreter and notice.
    InterpreterOffByOne {
        /// Qualified interpreter path, e.g., `"reference::eval_expr"`.
        component: &'static str,
        /// Name of the Expr variant the mutation corrupts.
        variant: &'static str,
    },
    /// Make the mutation probe report a mutation as killed when the test
    /// actually still passes. The single worst bug — makes every lower
    /// gate dishonest.
    GateFalseKill {
        /// Qualified gate path.
        component: &'static str,
    },
    /// Make the generator's independence certificate accept a tautological
    /// test (one that computes expected from the op under test).
    CertificateBypass {
        /// Qualified generator path.
        component: &'static str,
    },
    /// Make composition proof-token derivation claim laws or theorem chains
    /// that are not justified by the constituent specs.
    CompositionProofDrift {
        /// Qualified proof-token path.
        component: &'static str,
    },
    /// A generic syntactic mutation applied to a harness component.
    Syntactic {
        /// Qualified component path.
        component: &'static str,
        /// The mutation operator applied.
        operator: MetaOperator,
        /// 1-based line number.
        line: usize,
        /// 1-based column number.
        column: usize,
    },
}

/// A family of meta-mutations. Components declare sensitivity to classes,
/// not individual mutations, so adding a new mutation to an existing class
/// is backwards-compatible.
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
pub enum MetaMutationClass {
    /// Corrupt a law checker (skip boundary, reduce sample count, return
    /// false verdict).
    CheckerCorruption,
    /// Corrupt the oracle resolver (downgrade, misroute).
    OracleCorruption,
    /// Corrupt the reference interpreter (per-variant output drift,
    /// per-variant panic).
    InterpreterCorruption,
    /// Corrupt the mutation gate (false kill, false survival).
    GateCorruption,
    /// Corrupt the generator's independence certificate (bypass, false
    /// tautology detection).
    CertificateCorruption,
    /// Corrupt composition proof-token derivation (false preservation,
    /// missing broken laws, unstable theorem chain).
    CompositionProofCorruption,
    /// Syntactic corruption of harness logic (off-by-one, swap-comparison, etc).
    HarnessCorruption,
}

/// Return the [`MetaMutationClass`] of a concrete [`MetaMutation`].
#[must_use]
pub const fn class_of(mutation: MetaMutation) -> MetaMutationClass {
    match mutation {
        MetaMutation::CheckerMissBoundary { .. } | MetaMutation::CheckerSkipWitness { .. } => {
            MetaMutationClass::CheckerCorruption
        }
        MetaMutation::OracleDowngrade { .. } => MetaMutationClass::OracleCorruption,
        MetaMutation::InterpreterOffByOne { .. } => MetaMutationClass::InterpreterCorruption,
        MetaMutation::GateFalseKill { .. } => MetaMutationClass::GateCorruption,
        MetaMutation::CertificateBypass { .. } => MetaMutationClass::CertificateCorruption,
        MetaMutation::CompositionProofDrift { .. } => MetaMutationClass::CompositionProofCorruption,
        MetaMutation::Syntactic { .. } => MetaMutationClass::HarnessCorruption,
    }
}

/// The compile-time catalog of every meta-mutation the harness knows how
/// to apply. Grows over time; the post-mortem rule is: every bug found in
/// a vyre-conform component adds one new meta-mutation so the gate catches
/// its next instance.
pub const META_MUTATION_CATALOG: &[MetaMutation] = &[
    MetaMutation::CheckerMissBoundary {
        component: "algebra::checker::commutative",
        boundary: "u32_max_pair",
    },
    MetaMutation::CheckerMissBoundary {
        component: "algebra::checker::associative",
        boundary: "u32_max_triple",
    },
    MetaMutation::CheckerSkipWitness {
        component: "algebra::checker::commutative",
    },
    MetaMutation::OracleDowngrade {
        component: "oracles::resolve",
    },
    MetaMutation::InterpreterOffByOne {
        component: "reference::eval_expr",
        variant: "BinOp::Add",
    },
    MetaMutation::InterpreterOffByOne {
        component: "reference::eval_expr",
        variant: "BinOp::Shl",
    },
    MetaMutation::GateFalseKill {
        component: "harnesses::mutation::mutation_probe",
    },
    MetaMutation::CertificateBypass {
        component: "generator::emit",
    },
    MetaMutation::CompositionProofDrift {
        component: "algebra::proof_token::ProofToken::from_specs",
    },
];