weirflow 0.1.0

GPU-first dataflow analysis primitives for Vyre and Santh compiler pipelines.
Documentation
# R6-D Final Invariant Scan Report: `weir`

**Scan date:** 2026-05-24  
**Target:** `/media/mukund-thiru/SanthData/Santh/libs/dataflow/weir`  
**Source files scanned:** 281 `.rs` files under `src/`  
**Verdict:** **NEEDS_WORK**

---

## 1. Duplication Scan

A similarity scan was run on all `src/**/*.rs` files, extracting contiguous non-empty code blocks ≥50 lines and comparing them with `difflib.SequenceMatcher` (threshold ≥85%).

**Result:** 39 near-duplicate pairs found.

### Notable Clusters

| Similarity | File A | File B | Notes |
|------------|--------|--------|-------|
| **100%** | `src/ifds_gpu_core_tests.rs:683-749` | `src/ifds_gpu_core_tests/solve_borrowed_many_with_scratch_prepares_once_and_reuses_solve_outputs.rs:14-80` | Monolithic test file duplicates split-out test. |
| **100%** | `src/ifds_gpu_core_tests.rs:601-661` | `src/ifds_gpu_core_tests/solve_borrowed_with_scratch_reuses_prepare_and_solve_outputs.rs:91-151` | Same issue, monolithic file still exists after refactor. |
| **100%** | `src/ifds_gpu_core_tests.rs:523-599` | `src/ifds_gpu_core_tests/solve_borrowed_with_scratch_reuses_prepare_and_solve_outputs.rs:13-89` | Same issue. |
| **99.3%** | `src/slice/resident.rs:318-381` | `src/live/resident.rs:320-383` | Template-like resident solver impls across analyses. |
| **99.0%** | `src/reaching/resident.rs:324-387` | `src/live/resident.rs:320-383` | Same pattern. |
| **98.8%** | `src/reaching/resident.rs:324-387` | `src/slice/resident.rs:318-381` | Same pattern. |
| **97.8%** | `src/reaching/resident.rs:324-387` | `src/points_to/resident.rs:323-386` | Same pattern. |
| **97.3%** | `src/reaching/closure.rs:318-387` | `src/slice/closure.rs:280-349` | Nearly identical closure logic. |
| **98.5%** | `src/slice/resident.rs:126-185` | `src/live/resident.rs:128-187` | Resident batch-setup duplication. |
| **98.5%** | `src/slice/resident.rs:30-91` | `src/live/resident.rs:32-93` | Resident allocation duplication. |

**Recommendation:** The monolithic `src/ifds_gpu_core_tests.rs` (1,074 lines) should be deleted, its contents were already extracted into `src/ifds_gpu_core_tests/*.rs`. The `src/ifds_resident_solve_tests.rs` (881 lines) vs `src/ifds_resident_solve_tests/mod.rs` overlap should also be resolved. The cross-analysis resident/closure duplication (`slice`, `live`, `reaching`, `points_to`) is architectural boilerplate; macro-abstract or note for future cleanup.

---

## 2. Raw IR Scan

**Test:** `cargo test --test legoblock_composition`

**Result:** **FAIL**

```
test raw_ir_construction_is_allowlisted ... FAILED

Raw Vyre IR construction (`Expr::`, `Node::`, `Region::`) must go through
`vyre-primitives`. New violations found:
fixed_point_closure.rs:212:         let Some(vyre::ir::Node::Region { generator, .. }) = entry.first() else {
```

**Same failure in:** `cargo test --test oracle_boundary`  
Test: `production_source_raw_ir_construction_is_contained` flags `src/fixed_point_closure.rs` as a new production file containing raw IR (`Node::`).

**Root cause:** `src/fixed_point_closure.rs:212` pattern-matches on `vyre::ir::Node::Region` inside `is_bitset_equal_program()`. The test allowlists are **REMOVE-ONLY** (explicit policy). This file is not in `RAW_IR_PROGRAM_BUILDER_FILES` and the line is not in `RAW_IR_ALLOWLIST`.

**Impact:** blocking release status. Must refactor `fixed_point_closure.rs` to inspect the program through `vyre-primitives` APIs instead of matching raw IR nodes directly.

---

## 3. Untested Panic Path Scan

Scan scope: `src/**/*.rs` excluding `tests/`, `test_harness/`, `bin/`, `*_tests.rs`, `tests.rs`, and all `#[cfg(test)]` / `mod tests { ... }` blocks.

**Result:**

| Construct | Count | Location summary |
|-----------|-------|------------------|
| `panic!` | **0** | |
| `.unwrap()` | **0** | |
| `.expect(...)` | **35** | 12 files |

### Files with untested `.expect()` in production paths

| File | Count | Notes |
|------|-------|-------|
| `src/cross_language.rs` | 12 | `cpu_ref` oracle malformed-input paths and `usize` conversions. No `#[should_panic]` coverage. |
| `src/reaching_def_summary.rs` | 5 | Normalization / count-fitting expects. No `#[should_panic]` coverage. |
| `src/ssa.rs` | 3 | Legacy infallible-caller allocation expects. No `#[should_panic]` coverage. |
| `src/dispatch_decode/pack.rs` | 3 | Legacy infallible-caller allocation expects. **Partial coverage:** `should_panic_garden.rs` covers `capacity overflow` and `zero word staging`, but line 12 and 59 (`u32 byte pack allocation`) are untested. |
| `src/def_use.rs` | 2 | Unknown SSA definition version. No `#[should_panic]` coverage. |
| `src/graph_layout.rs` | 1 | Normalization scratch allocation. No `#[should_panic]` coverage. |
| `src/ifds_cpu_oracle.rs` | 1 | Empty CSR `row_ptr`. No `#[should_panic]` coverage. |
| `src/ifds/cpu_oracle.rs` | 2 | Malformed seed / CSR. **Covered** by inline `#[should_panic]` tests in same file. |
| `src/callgraph/cpu_oracle.rs` | 3 | Malformed bitsets. **Covered** by inline `#[should_panic]` tests in same file. |
| `src/summary/cpu_oracle.rs` | 3 | Malformed bitsets. **Covered** by inline `#[should_panic]` tests in same file. |

**Untested total (excluding already-covered oracle paths): 24 instances across 7 files.**

---

## 4. Benchmark Gap Scan

**Public modules (`pub mod` in `src/lib.rs`):** 51  
**Benchmark files (`benches/*.rs`):** 11 (excluding `scalar_opt_test_bak.rs` which is not a registered benchmark)

### Modules with dedicated benchmarks

- `bitset_closure_oracle`
- `graph_layout`
- `oracle` (via `dominator_sets`, `ifds_solve`, `reaching_def_summary_sharded`)
- `fixed_point_scratch`
- `ifds_resident_direct_batch`
- `ifds_vyre_resident`
- `reaching_def_summary`
- `ssa`
- `reaching`
- `fixed_point_resident`

### Public modules without dedicated benchmarks (≈38)

`analysis_family`, `callgraph`, `control_dependence`, `cross_language`, `def_use`, `dispatch_decode`, `dominators`, `escape`, `escapes`, `fixed_point_batch`, `fixed_point_execution_plan`, `fixed_point_execution_plan_cache`, `fixed_point_graph`, `fixed_point_resident_batch`, `fixed_point_resident_cache`, `fixed_point_resident_frontier`, `fixed_point_resident_plan`, `ifds`, `ifds_gpu`, `ifds_resident_batch`, `ifds_resident_cache`, `ifds_resident_direct_prepare`, `ifds_resident_direct_prepare_scratch`, `live`, `live_at`, `loop_sum`, `may_alias`, `must_init`, `points_to`, `post_dominates`, `range`, `range_check`, `reachability_witness`, `reaching_def`, `scc_query`, `slice`, `soundness`, `summary`, `traversal_step`, `value_set`

**Note:** Some of these are exercised indirectly through `primitive_micro` / `primitive_scale` or the oracle benchmarks, but they do not have their own named benchmark files.

---

## 5. Final Test Run

| Command | Result | Details |
|---------|--------|---------|
| `cargo test --lib` | ✅ **PASS** | 1,443 passed; 0 failed |
| `cargo test --test oracle_boundary` | ❌ **FAIL** | `production_source_raw_ir_construction_is_contained`. `src/fixed_point_closure.rs` |
| `cargo test --test legoblock_composition` | ❌ **FAIL** | `raw_ir_construction_is_allowlisted`. `src/fixed_point_closure.rs:212` |
| `cargo clippy --lib --no-deps -- -D warnings` | ❌ **FAIL** | 2 errors (see below) |

### Clippy errors

1. **`src/fixed_point_scratch/telemetry.rs:166`**
   ```
   error: this pattern reimplements `Option::unwrap_or`
   ```
   Replace `match left.checked_add(right) { Some(sum) => sum, None => u64::MAX }` with `left.checked_add(right).unwrap_or(u64::MAX)`.

2. **`src/ifds_resident_solve/single_query.rs:139`**
   ```
   error: truncating to zero length
   ```
   Replace `results.truncate(0)` with `results.clear()`.

---

## 6. Summary & Verdict

| Category | Status | Blocking? |
|----------|--------|-----------|
| Duplication | 39 pairs found; monolithic test files need deletion | No (noted for cleanup) |
| Raw IR invariant | **FAIL**: `fixed_point_closure.rs:212` | **Yes** |
| Untested panics | 24 `.expect()` paths without `#[should_panic]` | No (noted for coverage) |
| Benchmark gaps | ~38 public modules without dedicated benchmark | No (noted for future work) |
| `cargo test --lib` | **PASS** | No |
| `cargo test --test oracle_boundary` | **FAIL** | **Yes** |
| `cargo test --test legoblock_composition` | **FAIL** | **Yes** |
| `cargo clippy --lib --no-deps -- -D warnings` | **FAIL** (2 errors) | **Yes** |

### Final Verdict: **NEEDS_WORK**

**Blockers before depth:**
1. Refactor `src/fixed_point_closure.rs:212` to avoid raw `vyre::ir::Node::Region` pattern matching (or move the file into `RAW_IR_PROGRAM_BUILDER_FILES` if it is a legitimate program builder (but the allowlist policy is REMOVE-ONLY)).
2. Fix the 2 clippy errors (`manual_unwrap_or`, `manual_clear`).

**Non-blocking but recommended:**
- Delete stale monolithic test files (`src/ifds_gpu_core_tests.rs`, resolve `src/ifds_resident_solve_tests.rs` duplication).
- Add `#[should_panic]` or error-path unit tests for the 24 uncovered `.expect()` production paths, especially `cross_language.rs`, `reaching_def_summary.rs`, `ssa.rs`, and `def_use.rs`.
- Fill benchmark gaps for high-visibility public modules (e.g., `ifds`, `slice`, `live`, `points_to`, `loop_sum`).