Docs / design / program-slicing-design · Edit on GitHub

Program Slicing — Engineering Design

Backward and forward program slices over a function’s PDG: the minimal set of statements that affect (or are affected by) a variable at a given source line.

Program Slicing tab — source editor and slice controls (gbuilder)

Figure 1: Program Slicing tab — function picker, line/variable/direction inputs, and CodeMirror source view with highlighted slice lines.


1. Goals

GoalHow
Minimal relevant codePDG traversal from slice criterion
CLI automationrgctl slice FILE --line N --variable V
Dashboard explorationWASM compute_slice on exported PDG bundles
Security cross-check--taint mode shares taint engine paths

Requires discover --with-cfg (and --with-taint for discover-time taint) for PDG archives and dashboard export.


2. Architecture overview

flowchart LR
  subgraph discover["discover --with-cfg"]
    CFG[CFG per function]
    PDG[PDG per function]
    ARC[cfg_pdg.archive.bin]
    CFG --> PDG --> ARC
  end

  subgraph export["Dashboard export"]
    SI[slice_index.json]
    SB[slice/*.json]
    ARC --> SI
    ARC --> SB
  end

  subgraph runtime["Query"]
    CLI[slice CLI — reads source + PDG]
    WASM[worker compute_slice]
    CLI --> PDG
    WASM --> SB
  end

3. Slice criterion

FieldRole
fileSource path (read from disk at CLI; bundled in dashboard)
--line1-based line number
--variableVariable name at criterion
--functionEnclosing method name (disambiguation)
--directionbackward (default) or forward

4. Rust implementation map

ComponentPath
CFG constructioncrates/rgctl-analysis/src/cfg.rs
PDG + slicingcrates/rgctl-analysis/src/pdg.rs, slicing.rs
CLIsrc/cli/slice.rs
Archive storagecrates/rgctl-analysis/src/storage.rs
Dashboard exportcrates/rgctl-dashboard/src/slice_export.rs

5. Dashboard implementation

PiecePath
Tabdashboard/src/SliceView.tsx
Editordashboard/src/sliceEditor.tsx (CodeMirror)
WorkercomputeSlice(functionId, line, variable, direction)
Indexslice_index.jsonslice/{uuid}.json

6. CLI usage

rgctl discover . --cfg
rgctl slice src/Foo.java --line 42 --variable cart --function checkOut
rgctl -f json slice src/Foo.java --line 10 --variable req --direction forward
rgctl slice src/Foo.java --line 8 --variable input --taint

7. Testing

LayerLocation
Analysis unit testscrates/rgctl-analysis/src/slicing.rs
CLI subprocesstests/cli_output/all_commands_sanity.rs
Dashboard harnesstests/dashboard_harness.rs (slice_index.json)

Screenshots: capture-design-screenshots.mjsdocs/images/design/program-slicing/.


8. Related docs