Repository navigation
style: check the Google Rust style guide's rules with clippy, and follow them - #239
Conversation
…low them Each library's root warns on the guide's rules that clippy can check: missing docs, unwrap, a borrow taken by value, a panic left out of the docs, a missing #[must_use], and glob imports. CI now runs clippy on ddxdb too. The fixes: - #[must_use] on 70 pure functions; - pattern matching in place of a length check and an unwrap; - borrows in place of by-value slices, maps and plans, and a moved emit in place of a copy; - named fields in place of tuples (a union column's arms, a contraction's groups, the program cache's entries); - no read of a poisoned mutex: the program cache and a compiled plan are built again, and ddxdb's release raises; - explicit imports in the SQL layer's tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CvszJhH8pn8H9G69wEPMU2
|
😈🧪 Adversarial tester I tested this PR at 161db46 and found no bugs. Differential fuzz against main (a223f33). I ran the same seeds on ddxdb built from each, on DuckDB and DataFusion:
Both runs' logs and failure lists are byte-for-byte identical. The failures they share are the pre-existing #235–#238. ddxdb tests: 127 passed. Soak, 15 min: one failure in 1,158 cases, seed 239000365. It's a DataFusion Code read: the behavior changes are equivalent:
The poisoned-lock paths in 🤖 Generated with Claude Code |
…xdb 0.4.6 (#233) grad and vjp differentiate through UNION ALL, as jvp already did (#229). A loss joining one-row aggregates of constant data is again a scalar loss (#230). A step that one later step reads once is computed inside it: xarray-sql's GPT step has 64 steps rather than 77, about 1.5% faster on DuckDB (#231). The code follows the Google Rust style guide (#234, #239, #240), with instruction counts within 0.05% of before; a lock a panic poisoned is no longer read. Nothing public breaks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CvszJhH8pn8H9G69wEPMU2
Why
This is the second of three PRs that bring ddx in line with the Google Rust style guide, after #234 (formatting). It covers the guide's rules that clippy can check, plus a few clippy can't. Most of the code already followed them:
unwraps;unsafe.How
Lints. Each library's root (
ddx-core,ddx-ad,ddx-datafusion, ddxdb) warns on these. CI treats warnings as errors:missing_docsexpectoverunwrapclippy::unwrap_used(tests may unwrap:clippy.toml)clippy::needless_pass_by_valueclippy::missing_panics_doc#[must_use]on functionsclippy::must_use_candidate,clippy::return_self_not_must_useclippy::wildcard_importsddxdb leaves out
missing_docs, andneedless_pass_by_valuetoo, since pyo3 passes functions owned values. CI now runs clippy on ddxdb, which it never did.Fixes.
#[must_use]on 70 pure functions and builder methods.ddx_datafusion::ad::sqlreturns an error instead of panicking.stitchborrows its pieces, the dual'semittedborrows its tangents, andbroadcastborrows its columns;prune::finishmoves its emit instead of cloning it;SeedisCopy.Def::Union's arms areArm { branch, column };Group { side, column };Kept { key, program }.Rules not applied
emit::select(...)). ddx-ad's plan builders (emit,expr) read as a small language:call(add, vec![field(0), lit_f64(1.0)]). Prefixing hundreds of calls would add noise, and the guide's reason is Google's large-scale-change tooling.Option<&T>instead of&Option<T>(clippy::ref_option). The three hits take a prost child field (&Option<Box<Rel>>) as prost declares it. TakingOption<&Rel>would only lengthen 18 call sites.#[non_exhaustive]on every public enum and struct. The guide exempts types whose users the authors will fix, and ddx has no outside users. ddx-ad's errors, programs, tables and results already have it.Rcin the region tree, where regions share what is beneath them, andcatch_unwindinad_sql_text.rs's fuzzer, which reports a panic with its seed. Both are deliberate.async.Performance
Measured against main (a223f33) on xarray-sql's GPT step (
examples/prepared_step.rs, prepared, DataFusion) andad_perf'snnfamily, release builds run alternately.ad_perfnn process, user-space instructions (3 each)Instruction counts are the measure here. Another job was compiling on the machine (load 4–10), so wall time varied ±30% between runs of the same binary. The CPU time of six runs of main alone spread by 87%. The format-only build (#234) measured +3.6% in wall time against main in the same conditions, with identical instruction counts.
Next
Moving code out of non-leaf modules (
to_sql/mod.rs,sql/mod.rs).🤖 Generated with Claude Code
https://claude.ai/code/session_01CvszJhH8pn8H9G69wEPMU2
Summary by CodeRabbit
Bug Fixes
Chores