vyre-foundation 0.4.1

Foundation layer: IR, type system, memory model, wire format. Zero application semantics. Part of the vyre GPU compiler.
Documentation
//! Spec-driven optimizer rewrites derived from operation algebraic laws.

use crate::ir::Program;
use crate::optimizer::{fingerprint_program, vyre_pass, PassAnalysis, PassResult};

#[derive(Debug, Default)]
#[vyre_pass(name = "spec_driven", requires = [], invalidates = [])]
/// Protocol for running spec-driven optimizer passes.
pub struct SpecDriven;

impl SpecDriven {
    /// Skip this pass: foundation does not link a dialect registry and
    /// therefore cannot run spec-driven algebraic rewrites. The driver
    /// layer reruns the pass with a registry-backed resolver.
    #[must_use]
    #[inline]
    pub fn analyze(_program: &Program) -> PassAnalysis {
        PassAnalysis::SKIP
    }

    /// No-op at foundation tier; driver layer applies algebraic rewrites.
    #[must_use]
    pub fn transform(program: Program) -> PassResult {
        // VYRE_IR_HOTSPOTS CRIT: the previous `from_programs(original, program)`
        // paid a whole-Program clone and an O(N) PartialEq just to report
        // changed=false. The pass is declared a no-op; bypass both.
        PassResult::unchanged(program)
    }

    /// Passthrough fingerprint so cache invalidation matches identity.
    #[must_use]
    #[inline]
    pub fn fingerprint(program: &Program) -> u64 {
        fingerprint_program(program)
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::ir::{BufferDecl, DataType, Expr, Node};

    fn trivial() -> Program {
        Program::wrapped(
            vec![BufferDecl::output("out", 0, DataType::U32).with_count(1)],
            [1, 1, 1],
            vec![Node::store("out", Expr::u32(0), Expr::u32(42))],
        )
    }

    #[test]
    fn analyze_always_skips() {
        assert_eq!(SpecDriven::analyze(&trivial()), PassAnalysis::SKIP);
    }

    #[test]
    fn transform_is_identity() {
        let p = trivial();
        let result = SpecDriven::transform(p);
        assert!(!result.changed);
    }

    #[test]
    fn fingerprint_is_deterministic() {
        let p = trivial();
        assert_eq!(SpecDriven::fingerprint(&p), SpecDriven::fingerprint(&p));
    }
}