Skip to content

fix(ci): lint the whole workspace, and clear what that exposes (gh#743) - #757

Open
vsbuffalo wants to merge 2 commits into
mainfrom
fix/clippy-workspace-lint
Open

fix(ci): lint the whole workspace, and clear what that exposes (gh#743)#757
vsbuffalo wants to merge 2 commits into
mainfrom
fix/clippy-workspace-lint

Conversation

@vsbuffalo

Copy link
Copy Markdown
Owner

Fixes #743.

The gate linted one package

cd rust && cargo clippy --all-targets -- -D warnings lints only the current package. rust/Cargo.toml declares the workspace root as a package (camdl-tests), so sim, cli and io compiled as dependencies and were never linted — the check could not go red for anything in the real crates. Adding --workspace makes it real; this PR clears everything that then surfaces.

Workspace clippy is now 0 lints under -D warnings.

The neg_cmp_op_on_partial_ord eighteen — none was a bug

Every one was deliberate NaN handling, several with a comment saying so (obs_loglik cites gh#645). They are rewritten so the NaN arm lives in the code rather than a comment:

-if !(sigma > 0.0) { ... }
+if sigma.is_nan() || sigma <= 0.0 { ... }

Exactly equivalent by truth table. Ten were in sim; eight more surfaced in cli, which clippy had never reached.

NaN coverage added: the boundary_times monotonicity guards, optimize_det bounds, neg_binomial_dispersion, a NaN forcing knot, and a NaN Cond predicate in the flat-VM byte-identity A/B. That last one is verified to have teeth — reverting the guard fails it with eval_resolved=2.0 != eval_flat=1.0.

Two arms are left untested and I would rather say so than pad: odes h fallback and the multi_stream_obs denominator. Both need a fixture out of proportion to a provably equivalent rewrite.

Two real defects fell out

  1. spatial_density.rs — the -inf diagnostic tested (rate <= 0.0 && flow > 0) || (flow > 0), which collapses to flow > 0. The pathology the author wanted to see (flow out of a transition with no propensity) was printed but never distinguished. Same rows, now marked.
  2. Three orphaned doc commentsapply_params_file lost its docs to a function inserted between them (reattached); sampling.rss module overview used ///, so it documented a use statement (now //!); and a doc block for the removed --starts-from flag outlived it (deleted).

Design calls to sanity-check

Allowed workspace-wide, each with its reason in rust/Cargo.toml:

lint why
needless_range_loop the one that matters. All remaining sites are pgas/pmmh/nuts/ode/resampling, where the index mirrors the derivation and often walks several arrays at once. De-indexing buys no correctness and makes a silent transposition easier to introduce — CLAUDE.md flags these exact files as high-risk "regardless of how mechanical the change looks".
too_many_arguments, type_complexity numerical kernels where the parameter list is the domain
upper_case_acronyms PGAS/PMMH are the method names
large_enum_variant boxing argv-built dispatch enums

approx_constant is allowed at four call sites where it is a false positive: 3.14 is not π, and substituting the constant would change what the test asserts. One is a scipy oracle value that happens to equal -ln(2).

No correctness lint is silenced anywhere.

Commits

items_after_test_module produced an ~800-line reordering in trajectories.rs and pmmh.rs. It is in its own commit, verified as a pure move by comparing whitespace-normalized sorted line sets against main (diff empty), so it does not bury the substantive changes.

Verification

Full make test — every phase, ending with the install-script suite — exit 0, 0 failures.

@vsbuffalo
vsbuffalo force-pushed the fix/clippy-workspace-lint branch 2 times, most recently from 866d82b to c2b5962 Compare August 27, 2026 22:28
`clippy::items_after_test_module` fires where a `#[cfg(test)] mod tests`
sits between the items above it and the items below, which is easy to
read past when scanning a file for a definition.

This commit is a PURE REORDERING and nothing else. Verified by comparing
the whitespace-normalized set of lines before and after — identical in
both files:

    git show origin/main:<f> | sed 's/[[:space:]]\+/ /g' | sort
    <same over the working copy>          # diff is empty

Kept separate from the rest of the lint cleanup precisely because the
line count (~800) is otherwise the largest thing in the diff and would
bury the substantive changes.
`cd rust && cargo clippy --all-targets -- -D warnings` linted ONE
package. rust/Cargo.toml declares the workspace root as a package
(`camdl-tests`), so with no `-p` and no `--workspace` cargo lints only
that; sim, cli and io compile as dependencies and were never linted. The
check could not go red for anything in the real crates — an assurance
that wasn't there. Add `--workspace`, and clear everything it exposes.

The ten `neg_cmp_op_on_partial_ord` are the valuable ones, and none was
a bug: every `!(x > 0.0)` was deliberate NaN handling, some carrying a
comment saying so (obs_loglik cites gh#645). Rewritten so the NaN arm is
in the code rather than a comment — `x.is_nan() || x <= 0.0` — which is
exactly equivalent, and pinned by assertions. Eight more of the same
shape surfaced in cli, which clippy had never reached.

NaN coverage added: boundary_times monotonicity guards, optimize_det
bounds, neg_binomial_dispersion, a NaN forcing knot, and a NaN `Cond`
predicate in the flat-VM byte-identity A/B. The last was confirmed to
have teeth: reverting the guard makes it fail with eval_resolved=2.0 vs
eval_flat=1.0. Two arms are left untested — ode's `h` fallback and the
multi_stream_obs denominator — because reaching them needs a fixture out
of proportion to a provably equivalent rewrite.

Two real defects fell out:

  - spatial_density's -inf diagnostic tested
    `(rate <= 0.0 && flow > 0) || (flow > 0)`, which collapses to
    `flow > 0`. The pathological case the author wanted to see — flow
    out of a transition with no propensity — was printed but never
    distinguished. Same rows, now marked.
  - three orphaned doc comments. `apply_params_file` lost its docs to a
    function inserted between them (reattached); sampling.rs's module
    overview was written with `///` so it documented a `use` statement
    (now `//!`); and a doc block for the removed `--starts-from` flag
    outlived it (deleted).

Four lints are allowed workspace-wide, with reasons in Cargo.toml:
`too_many_arguments` and `type_complexity` (numerical kernels where the
parameter list is the domain), `needless_range_loop` (the index IS the
notation, and de-indexing invites a silent transposition in exactly the
files CLAUDE.md calls high-risk), `upper_case_acronyms` (PGAS/PMMH are
the method names) and `large_enum_variant` (boxing argv-built enums).
`approx_constant` is allowed at four call sites where the literal is an
arbitrary test value or a scipy oracle — 3.14 is not pi, and
substituting the constant would change what is asserted.

No correctness lint is silenced anywhere.
@vsbuffalo
vsbuffalo force-pushed the fix/clippy-workspace-lint branch from c2b5962 to 6d3683c Compare August 29, 2026 03:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CI's clippy command lints only the workspace-root package, so sim/cli/io have never been linted

1 participant