vyre-conform 0.1.0

Conformance suite for vyre backends — proves byte-identical output to CPU reference
Documentation
//! Structural witness minimization.

use crate::generate::archetypes::TestInput;

/// Shrink a generated structural witness without erasing it.
///
/// Structural archetypes are currently represented as typed `TestInput`
/// vectors. This pass removes trailing values and then minimizes remaining
/// words while preserving the caller-provided failure predicate.
#[inline]
pub fn shrink_structural_input(
    input: &TestInput,
    is_failure: impl Fn(&TestInput) -> bool,
) -> TestInput {
    let mut current = TestInput {
        label: input.label,
        values: input.values.clone(),
    };
    if !is_failure(&current) {
        return current;
    }

    while current.values.len() > 1 {
        let mut trial = TestInput {
            label: current.label,
            values: current.values.clone(),
        };
        trial.values.pop();
        if is_failure(&trial) {
            current = trial;
        } else {
            break;
        }
    }

    for index in 0..current.values.len() {
        for candidate in [0, 1, current.values[index] / 2] {
            let mut trial = TestInput {
                label: current.label,
                values: current.values.clone(),
            };
            trial.values[index] = candidate;
            if is_failure(&trial) {
                current = trial;
            }
        }
    }
    current
}