Repository navigation
Description
Background
Repo already has these static-analysis gates:
cargo clippy --all-features -- -D warningscargo deny check(tightened in chore(deny): tighten multiple-versions, wildcards, sources; deny openssl #1126)cargo vet#![forbid(unsafe_code)]+ grep-level invariant check (scripts/check-unsafe-invariant.sh)
This issue proposes three additions, each closing a distinct class of bug that the existing gates don't catch.
Add 1: cargo-public-api baseline diff
Generate crates/<name>/public-api.txt for the workspace crates with stable public APIs, check the files in, and add a CI step that regenerates and git diff --exit-code's them.
Catches:
- Accidental pub-item removal / rename
- Accidental pub-trait method-signature changes
- Accidental pub-struct field addition without
#[non_exhaustive]
Difference from issue #1233: cargo-public-api produces a human-readable text diff that shows up in PR review; cargo-semver-checks produces a semantic verdict. The two complement each other — public-api for visibility in the PR, semver-checks for the gate.
Add 2: dylint for project-specific lints
dylint runs custom lints written as Rust crates. Lints to start with:
no_unwrap_in_lib
Forbid .unwrap() and .expect() in crates/rustledger-*/src/ (excluding #[cfg(test)] modules and integration test files). CLAUDE.md's self-review checklist includes "No .unwrap() in library code" — dylint makes it structural.
no_panic_in_lib
Forbid panic!(), unreachable!(), todo!(), unimplemented!() in library crates. Production library code should return Result, not panic.
parking_lot_only
Forbid std::sync::Mutex, std::sync::RwLock. parking_lot was adopted as a perf quick win (#1076) but nothing prevents new std::sync mutexes from being introduced.
no_std_collections_in_hot_paths
Forbid HashMap / HashSet (which use the slow SipHash by default) in specific hot-path modules; require rustc_hash::FxHashMap or similar. FxHasher was adopted in #1076; this lint prevents regression.
Add 3: loom for shared-state critical sections
loom exhaustively explores thread interleavings for code in a loom::sync module. Recent example of a bug it would have caught:
fix(query): row_group_keys invariant in parallel non-DISTINCT path (closes #1175)(fix(query): row_group_keys invariant in parallel non-DISTINCT path (closes #1175) #1177)
The fix worked because the author identified the specific interleaving. loom-tested critical sections would have flagged the missing invariant at PR time.
Scope: the few modules that use rayon::par_iter or share mutable state via Mutex/RwLock. Not "everything that has threads" — loom's exhaustive search is exponential.
What "done" looks like
- A new CI job that runs each of the three checks. Failures block merge.
- Per-lint allowlists for legitimate exceptions, with a code comment naming the lint and the reason.
cargo-public-apibaseline files checked in for the Tier-1 crates (plugin-typesat minimum,coreandparseras stretch goals — overlaps with Lock public API surface via cargo-semver-checks (+ cargo-public-api for visibility) #1233).dylintlints checked in to a newlints/workspace crate.loomtests for at least the BQL parallel execution path; expand from there.
Open questions
1. dylint runtime cost
dylint rebuilds the lint crate when toolchain changes. On the order of 5-10s in CI, less locally with a warm cache. Probably acceptable but worth measuring before committing.
2. loom test scope creep
Easy to over-instrument code with loom::sync wrappers and then run only cargo loom weekly. Conservative scope: start with the BQL executor's parallel iteration paths; expand only when a concrete bug suggests it's worth it.
3. cargo-public-api for which crates?
Same question as #1233. Start with plugin-types; expand to core and parser once the baseline is comfortable.
Related
cargo deny checktightening (chore(deny): tighten multiple-versions, wildcards, sources; deny openssl #1126) — same family of ratcheting.perf: trivial quick wins bundle (blake3 cache, parking_lot, FxHasher, wasm fat-LTO)(perf: trivial quick wins bundle (blake3 cache, parking_lot, FxHasher, wasm fat-LTO) #1076) — introduced parking_lot and FxHasher; this issue prevents regression to the slower std types.fix(query): row_group_keys invariant in parallel non-DISTINCT path(fix(query): row_group_keys invariant in parallel non-DISTINCT path (closes #1175) #1177) — the loom-testable bug.#![forbid(unsafe_code)]+ grep invariant — the existing precedent for "ratchet a property and enforce it in CI."
Activity
robcohen commentedon Jun 15, 2026
Review + first slice landed (#1363)
Reviewed this against the current codebase. Summary: the three "Adds" are independent and have very different cost/value, and two of them carry a hidden nightly-toolchain cost that isn't called out in the issue.
Current state
None of it exists yet (no
lints/crate, nopublic-api.txt, no loom/dylint deps), and none of the four tools (cargo-public-api,cargo-dylint,dylint-link,cargo-loom) are in the nix dev shell — all would need flake additions.Violation counts (grounds the dylint effort)
std::sync::Mutex/RwLockin lib code: 1.unwrap()/.expect()in non-test lib code: ~136 across 47 filespanic!/unreachable!/todo!/unimplemented!in non-test lib code: ~29(The naive grep showed 2119 unwraps, but that's almost entirely inline
#[cfg(test)]modules.)Key friction not in the issue
dylintrequires a pinned nightly toolchain to build lint crates. This repo pins stable 1.95.0 via nix, so dylint means carrying a second nightly toolchain — real flake/CI-cache complexity.cargo-public-apialso needs nightly rustdoc. So the "Add 1" piece shares the same cost, and it overlaps the still-open Lock public API surface via cargo-semver-checks (+ cargo-public-api for visibility) #1233 (cargo-semver-checks + public-api). Better tracked there.no_unwrap_in_lib/no_panic_in_libare not drop-in gates — the ~165 existing sites (many likely infallible) need a cleanup/allowlist pass first.Insight: most of these can be grep ratchets
The repo already has the precedent (
scripts/check-unsafe-invariant.sh, the "Unsafe Invariant" CI status).parking_lot_only,no_std_collections_in_hot_paths, and even baseline-styleno_unwrap/no_panicchecks can be implemented as grep ratchets — avoiding the dylint nightly cost entirely.Landed now: #1363 —
parking_lot_onlyas a grep ratchetscripts/check-sync-primitives.sh+ a "Sync Primitives" CI jobstd::sync::RwLock(query regex cache) toparking_lot::RwLock(itsinto_inner()poison-recovery already matched parking_lot's no-poison semantics)Recommended split of the remainder
no_std_collections_in_hot_paths— do as a grep ratchet (cheap, same pattern as ci(ratchet): forbid std::sync Mutex/RwLock in library code (#1237) #1363).cargo-public-api— fold into Lock public API surface via cargo-semver-checks (+ cargo-public-api for visibility) #1233 rather than duplicate here.dylintlint crate +no_unwrap/no_paniccleanup — its own issue; weigh the nightly-toolchain cost vs. doing the unwrap/panic checks as baseline grep ratchets instead.loom— defer until a concrete parallel bug recurs (matches this issue's own Q2).Suggest narrowing this issue to track that remainder (or splitting into per-tool issues), now that the cheapest, highest-value piece is in flight.
robcohen commentedon Jun 15, 2026
Item 1 of the recommended split is in flight: #1364 implements
no_std_collections_in_hot_pathsas a marker-based grep ratchet (// ratchet: fxhash-only), marking five hot modules (booking, inventory, loader booking pass, balance validator, query executor types) and convertingbook.rs's one stdHashSettoFxHashSet. No nightly toolchain. Joins #1363 (parking_lot ratchet). Remaining: cargo-public-api (→ #1233), the dylint crate + unwrap/panic cleanup, and loom.fix(ci): wire sync-primitives into merge gate + harden script (#1237)
fix(ci): wire hot-path-collections into merge gate + harden awk (#1237)
ci(ratchet): forbid std::sync Mutex/RwLock in library code (#1237)
fix(ci): wire sync-primitives into merge gate + harden script (#1237)
ci(ratchet): forbid std SipHash collections in hot-path modules (#1237)
fix(ci): wire hot-path-collections into merge gate + harden awk (#1237)
perf(booking): restore booked_indices preallocation (#1237 review)
ci(ratchet): forbid std SipHash collections in hot-path modules (#1237)
fix(ci): wire hot-path-collections into merge gate + harden awk (#1237)
perf(booking): restore booked_indices preallocation (#1237 review)
robcohen commentedon Jun 15, 2026
Closing — the high-value ratchets shipped; heavier items deferred
Delivered the two tractable, high-ROI pieces as grep ratchets (the existing
check-unsafe-invariant.shpattern), deliberately avoiding the nightly-toolchain cost adylintlint crate would add to this stable-pinned flake:parking_lot_only:scripts/check-sync-primitives.sh+ aSync PrimitivesCI job forbiddingstd::sync::Mutex/RwLockin non-test library code (converted the one pre-existing usage toparking_lot). Wired into the requiredbuildgate.no_std_collections_in_hot_paths:scripts/check-hot-path-collections.sh+ aHot-path CollectionsCI job, marker-based (// ratchet: fxhash-only), forbidding std SipHash maps in five hot modules. Wired into the requiredbuildgate.Deferred (closing rather than tracking indefinitely)
dylintlint crate (no_unwrap_in_lib,no_panic_in_lib): requires a separate nightly toolchain in CI, and there are ~136 unwrap/expect + ~29 panic-family sites in non-test lib code that would need a cleanup/allowlist pass first. Several of these could alternatively be done as grep ratchets if revisited.cargo-public-api: folded into Lock public API surface via cargo-semver-checks (+ cargo-public-api for visibility) #1233.loom: deferred per this issue's own conservative-scope note — revisit if a concrete parallel bug recurs.Closing as substantially complete; reopen or file a focused issue if the dylint/loom work is wanted later.
docs: bring roadmaps in line with shipped reality