weirflow 0.1.0

GPU-first dataflow analysis primitives for Vyre and Santh compiler pipelines.
Documentation
use super::*;

#[test]
fn direct_ifds_graph_hash_canonicalizes_order_and_separates_edge_families() {
    let intra = vec![(0u32, 0u32, 1u32), (0, 1, 2)];
    let reordered = vec![(0u32, 1u32, 2u32), (0, 0, 1)];
    let inter = vec![(0u32, 1u32, 1u32, 0u32)];
    let gen_edges = vec![(0u32, 0u32, 1u32)];
    let kill = vec![(0u32, 1u32, 0u32)];

    assert_eq!(
        graph_hash(&intra, &[], &[], &[]),
        graph_hash(&reordered, &[], &[], &[]),
        "direct resident IFDS graph identity must be stable for equivalent edge orderings"
    );
    assert_ne!(
        graph_hash(&intra, &[], &[], &[]),
        graph_hash(&[], &inter, &[], &[])
    );
    assert_ne!(
        graph_hash(&[], &[], &gen_edges, &[]),
        graph_hash(&[], &[], &[], &kill)
    );
}

#[test]
fn direct_ifds_graph_hash_mixes_full_usize_lengths() {
    let base = graph_hash(&[], &[], &[], &[]);
    let one = graph_hash(&[(0u32, 0u32, 0u32)], &[], &[], &[]);

    assert_ne!(
        base, one,
        "direct resident cache identity must include exact edge-family lengths"
    );
}

#[test]
fn direct_ifds_graph_hash_distinguishes_duplicate_multisets_without_sorting() {
    let duplicate = graph_hash(&[(0u32, 0u32, 0u32), (0u32, 0u32, 0u32)], &[], &[], &[]);
    let changed = graph_hash(&[(0u32, 0u32, 0u32), (0u32, 0u32, 1u32)], &[], &[], &[]);

    assert_ne!(
        duplicate, changed,
        "direct resident cache identity must distinguish same-length edge multisets"
    );
}

#[test]
fn direct_ifds_graph_key_rejects_dimension_or_length_drift() {
    let graph = vec![(0u32, 0u32, 1u32)];
    let changed = vec![(0u32, 0u32, 1u32), (0, 1, 2)];
    let key = DirectResidentIfdsGraphKey::from_edges(1, 2, 1, &graph, &[], &[], &[]);

    assert!(
        key.validate_edges(2, 2, 1, &graph, &[], &[], &[]).is_err(),
        "graph key must reject changed IFDS dimensions"
    );
    assert!(
        key.validate_edges(1, 2, 1, &changed, &[], &[], &[])
            .is_err(),
        "graph key must reject changed edge-family lengths"
    );
    assert!(
        key.validate_edges(1, 2, 1, &[(0u32, 1u32, 1u32)], &[], &[], &[])
            .is_err(),
        "graph key must reject changed edge contents even when lengths match"
    );
    assert!(
        key.validate_edges(1, 2, 1, &graph, &[], &[], &[]).is_ok(),
        "graph key must accept the graph shape it was built from"
    );
}

#[test]
fn direct_ifds_cache_key_separates_backend_versions() {
    let first = DirectIfdsKey {
        backend_id: "weir_test_direct_ifds_versioned_gpu",
        backend_version: "test-v1",
        num_procs: 1,
        blocks_per_proc: 2,
        facts_per_proc: 1,
        graph_hash: 42,
    };
    let second = DirectIfdsKey {
        backend_version: "test-v2",
        ..first.clone()
    };

    assert_ne!(
        first, second,
        "direct resident IFDS cache identity must include backend implementation version"
    );
}