Skip to main content

weir/slice/
program.rs

1use super::OP_ID;
2use vyre::ir::Program;
3use vyre_primitives::graph::csr_backward_traverse::csr_backward_traverse;
4use vyre_primitives::graph::program_graph::ProgramGraphShape;
5
6/// Build one reverse-BFS step. Caller invokes this Program in a
7/// host loop until the slice bitset stops growing (same fixpoint
8/// driver pattern as DF-2 reaching, DF-3 points-to).
9///
10/// Buffer contract: `frontier_in` is the current slice bitset (seed
11/// is one bit set  -  the sink node). `frontier_out` is the expanded
12/// bitset after one reverse-edge traversal. The caller-supplied
13/// `ProgramGraph` buffers are bound at the canonical `pg_*` names
14/// (callgraph ∪ reach ∪ dom merged via three-way `fuse_programs`).
15///
16/// PHASE6_DATAFLOW HIGH: previous 5-arg entry hardcoded
17/// `ProgramGraphShape::new(1, 1)` and ignored the `reach`,
18/// `callgraph`, `dom` buffer arguments  -  i.e. it produced a
19/// 1-node-grid kernel for any real CFG, silently losing every
20/// dependency edge. The 5-arg shim is now `#[deprecated]` and
21/// delegates with a pessimistic shape that surfaces the bug.
22/// Callers MUST use the explicit-shape entry below.
23#[must_use]
24pub fn backward_slice(shape: ProgramGraphShape, frontier_in: &str, frontier_out: &str) -> Program {
25    vyre_harness::region::tag_program(
26        OP_ID,
27        csr_backward_traverse(shape, frontier_in, frontier_out, u32::MAX),
28    )
29}
30
31/// Deprecated alias for back-compat with callers that imported the
32/// pre-fix `backward_slice_with_shape` name.
33#[deprecated(
34    since = "0.4.1",
35    note = "use `backward_slice(shape, frontier_in, frontier_out)` directly  -  the suffix is redundant since the 5-arg entry was removed"
36)]
37#[must_use]
38pub fn backward_slice_with_shape(
39    shape: ProgramGraphShape,
40    frontier_in: &str,
41    frontier_out: &str,
42) -> Program {
43    backward_slice(shape, frontier_in, frontier_out)
44}
45
46/// Marker type for the backward-slice dataflow primitive.
47#[derive(Clone, Copy, Debug, PartialEq, Eq)]
48pub struct BackwardSlice;
49
50impl crate::soundness::SoundnessTagged for BackwardSlice {
51    fn soundness(&self) -> crate::soundness::Soundness {
52        crate::soundness::Soundness::MayOver
53    }
54}
55
56inventory::submit! {
57    vyre_harness::OpEntry::new(
58        OP_ID,
59        || backward_slice(ProgramGraphShape::new(4, 3), "frontier_in", "frontier_out"),
60        Some(|| {
61            let u32s = crate::dispatch_decode::pack_u32;
62            vec![vec![
63                u32s(&[0, 0, 0, 0]),
64                u32s(&[0, 1, 2, 3, 3]),
65                u32s(&[1, 3, 1]),
66                u32s(&[1, 1, 1]),
67                u32s(&[0, 0, 0, 0]),
68                u32s(&[0b0010]),
69                u32s(&[0]),
70            ]]
71        }),
72        Some(|| {
73            let u32s = crate::dispatch_decode::pack_u32;
74            vec![vec![u32s(&[0b0101])]]
75        }),
76    )
77}