vyre-conform 0.1.0

Conformance suite for vyre backends — proves byte-identical output to CPU reference
Documentation
use crate::spec::op_registry;
use crate::OpSpec;

use super::archetype_check::check_archetypes;
use super::category_check::check_category;
use super::docs_check::check_docs_path;
use super::error::CoverageError;
use super::law_check::{check_declared_laws, check_laws};
use super::oracle_check::check_oracle;
use super::row_check::check_rows;
use super::signature_check::check_signature;
use super::version_check::check_since_version;

/// Iterate the full runtime registry and return every coverage error.
///
/// An empty return value means every op in the registry has its
/// required fields populated. Non-empty means the build gate fails.
#[inline]
pub fn verify_coverage() -> Result<(), Vec<CoverageError>> {
    let specs = op_registry::all_specs();
    verify_specs(&specs)
}

/// Iterate a specific slice of op specs and return every coverage
/// error. Used by tests that want to check a subset without touching
/// the global registry.
#[inline]
pub fn verify_specs(specs: &[OpSpec]) -> Result<(), Vec<CoverageError>> {
    let mut errors = Vec::new();
    let mut seen_ids = std::collections::HashSet::new();

    for spec in specs {
        if !seen_ids.insert(spec.id.to_string()) {
            errors.push(CoverageError::DuplicateOpId {
                op_id: spec.id.to_string(),
            });
            continue;
        }

        check_category(spec, &mut errors);
        check_signature(spec, &mut errors);
        check_laws(spec, &mut errors);
        check_declared_laws(spec, &mut errors);
        check_oracle(spec, &mut errors);
        check_rows(spec, &mut errors);
        check_docs_path(spec, &mut errors);
        check_since_version(spec, &mut errors);
        check_archetypes(spec, &mut errors);
    }

    if errors.is_empty() {
        Ok(())
    } else {
        Err(errors)
    }
}