Skip to main content

weir/
slice.rs

1//! DF-6  -  backward slicer.
2//!
3//! Given a sink node `s`, emit the minimal sub-graph that may
4//! affect it. Reduces to **reverse** reachability on the merged
5//! dependence graph: walk backward from the sink, union-in
6//! every predecessor along data dependences (DF-2 reaching, DF-3
7//! points-to, DF-5 callgraph) and control dependences
8//! (`security::dominator_tree`).
9//!
10//! # Implementation
11//!
12//! Reverse-BFS is
13//! [`csr_backward_traverse`] applied to the caller-supplied
14//! `ProgramGraph`. The caller merges `reach`, `callgraph`, and
15//! `dom` into a single CSR before dispatch (dense-OR of three CSRs
16//!  -  a one-kernel fusion via `fuse_programs`). The
17//!     `edge_kind_mask` channel already supports up to 32 independent
18//!     edge kinds, so we admit **every** kind with `u32::MAX`  -  the
19//!     slicer is intentionally maximal, and false-positives are
20//!     filtered by the downstream rule.
21//!
22//! # Soundness
23//!
24//! [`MayOver`](super::Soundness::MayOver). Rules requiring zero-FP
25//! pair this slicer with a sanitizer filter on each edge in the
26//! returned slice.
27
28#[cfg(any(test, feature = "cpu-parity"))]
29mod oracle;
30mod plan;
31mod program;
32#[cfg(test)]
33mod tests;
34
35pub(crate) const OP_ID: &str = "weir::slice";
36
37crate::define_analysis_family! {
38    family: SliceFamily,
39    kind: crate::fixed_point_graph::FixedPointAnalysisKind::Slice,
40    name: "slice_closure",
41    program_builder: backward_slice,
42    graph_prep: plan::prepare_slice_graph,
43    graph_prep_scratch: plan::prepare_slice_graph_with_scratch,
44    input_buffer: "fin",
45    output_buffer: "fout",
46    closure_prefix: slice_closure,
47    resident_prefix: slice_closure_resident,
48    word_capacity: "slice_closure",
49    frontier_output: "slice frontier",
50    resident_capacity: "slice_closure resident",
51    resident_output: "slice frontier",
52    visibility: pub,
53}
54
55#[cfg(any(test, feature = "cpu-parity"))]
56#[allow(deprecated)]
57pub(crate) use oracle::slice_closure_cpu;
58pub use plan::{
59    prepare_slice_graph, prepare_slice_graph_into, prepare_slice_graph_with_scratch,
60    prepare_slice_plan, prepare_slice_plan_into,
61};
62#[allow(deprecated)]
63pub use program::{backward_slice, backward_slice_with_shape, BackwardSlice};
64
65#[cfg(test)]
66use vyre::ir::Program;
67#[cfg(test)]
68use vyre_primitives::graph::program_graph::ProgramGraphShape;