Summary
Add Miri as a GitHub Actions CI job to detect undefined behavior (UB) in the unsafe code paths at test-time.
Motivation
PureCV strives for a zero-unsafe policy, but a few unsafe blocks currently exist for performance-critical SIMD paths:
src/core/arithm.rs — pointer casts in binary_op! / binary_op_scalar! macros (transmuting dst chunks)
src/imgproc/derivatives.rs — from_raw_parts / from_raw_parts_mut reinterpretation for f32 SIMD paths
src/core/tests.rs — raw pointer dereference in data_ptr / data_ptr_mut tests
Requirements
During development, a plan must be created identifying which code/tests to include and exclude from Miri runs:
Code to Include (run under Miri)
- All unit tests in src/core/tests.rs (especially data_ptr and data_ptr_mut tests)
- Arithmetic operations using unsafe transmutes (src/core/arithm.rs)
- Derivative SIMD fast-path (src/imgproc/derivatives.rs)
- src/core/structural.rs split/merge operations
- All safe code paths (sequential/non-SIMD) — should pass trivially
Code to Exclude (skip under Miri)
- Benchmarks (benches/) — too slow under Miri interpretation
- WASM build (crates/wasm/) — Miri does not support wasm32 targets
- pulp-based SIMD (#[cfg(feature = "simd")]) — Miri doesn't support most SIMD intrinsics; annotate with #[cfg_attr(miri, ignore)]
- Rayon parallel tests (#[cfg(feature = "parallel")]) — Miri's thread support is limited; run without parallel feature or selectively ignore
- External I/O or FFI — none expected, but exclude if added
Implementation Plan
-
Add a new job miri to .github/workflows/ci.yml
-
Use dtolnay/rust-toolchain@nightly with components: miri
-
Run: cargo +nightly miri test --workspace (without parallel or simd features initially)
-
Annotate incompatible tests with #[cfg_attr(miri, ignore)]
-
Consider a second Miri run with --features simd once pulp gains Miri compatibility
-
Document excluded tests and rationale in the workflow file
-
Add a Badge in the readme file with all infos.
Proposed Workflow Addition
name: Miri UB Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Install Rust nightly + Miri
uses: dtolnay/rust-toolchain@nightly
with:
components: miri
- name: Rust Cache
uses: Swatinem/rust-cache@v2
- name: Run Miri
run: cargo +nightly miri test --workspace
env:
MIRIFLAGS: "-Zmiri-strict-provenance"
Acceptance Criteria
Summary
Add Miri as a GitHub Actions CI job to detect undefined behavior (UB) in the unsafe code paths at test-time.
Motivation
PureCV strives for a zero-unsafe policy, but a few unsafe blocks currently exist for performance-critical SIMD paths:
src/core/arithm.rs— pointer casts inbinary_op!/binary_op_scalar!macros (transmuting dst chunks)src/imgproc/derivatives.rs—from_raw_parts/from_raw_parts_mutreinterpretation for f32 SIMD pathssrc/core/tests.rs— raw pointer dereference indata_ptr/data_ptr_muttestsRequirements
During development, a plan must be created identifying which code/tests to include and exclude from Miri runs:
Code to Include (run under Miri)
Code to Exclude (skip under Miri)
Implementation Plan
Add a new job miri to
.github/workflows/ci.ymlUse dtolnay/rust-toolchain@nightly with components: miri
Run: cargo +nightly miri test --workspace (without parallel or simd features initially)
Annotate incompatible tests with #[cfg_attr(miri, ignore)]
Consider a second Miri run with --features simd once pulp gains Miri compatibility
Document excluded tests and rationale in the workflow file
Add a Badge in the readme file with all infos.
Proposed Workflow Addition
Acceptance Criteria