Skip to content

d3d12: fix remaining workspace clippy warnings - #2873

Merged
OreoFR merged 1 commit into
ProjectLeonida:mainfrom
kirigayakazima:fix/d3d12-clippy-workspace-clean
Dec 1, 2026
Merged

OreoFR merged 1 commit into
ProjectLeonida:mainfrom
kirigayakazima:fix/d3d12-clippy-workspace-clean

Conversation

@kirigayakazima

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: D3D12-CLIPPY-WORKSPACE-CLEAN (#2570 (comment))

What and why

Clears the four workspace clippy warnings reported in #2570 (comment) so cargo clippy --workspace --locked -- -D warnings passes cleanly again:

  1. d3d12/crates/leonida-gpu/src/pipeline/host.rs (mesh_pipeline, line 1214): grouped amplify, ms, and ps into a small private MeshStages struct, reducing the argument count from 8 to 6 without suppressing clippy::too_many_arguments.
  2. d3d12/crates/leonida-gpu/src/pipeline/known.rs:
    • Replaced drop(places.insert(hash, (stage, at, len))) (Option<(u8, u64, u32)>, Copy) with let _ = places.insert(...); (clippy::dropping_copy_types).
    • Replaced loop { let Some(&n) = ... else { break }; ... } with while let Some(&n) = ... (clippy::while_let_loop).
  3. d3d12/crates/leonida-hle/src/modules/glyphs/live.rs (plausible, line 121): replaced v.is_finite() && v >= 0.0 && v < 1e9 with (0.0..1e9).contains(&v) (clippy::manual_range_contains, preserving NaN/infinity/sign boundary semantics) and added unit test plausible_checks_nonnegative_whole_counters_below_one_billion.

Tested

Verified locally (Windows 11, Rust 1.98.1 / clippy 0.1.98, no game data):

  • Red before fix: cargo clippy --workspace --locked -- -D warnings failed (rc = 101) with errors in pipeline/host.rs:1214 and pipeline/known.rs:246,268 (plus glyphs/live.rs:121 downstream).
  • Green after fix:
    • cargo clippy --workspace --locked -- -D warnings: 0 warnings, exit 0
    • cargo test --locked -p leonida-hle --lib modules::glyphs::live: 13 passed, 0 failed
    • cargo test --locked -p leonida-gpu --lib pipeline::known: 2 passed, 0 failed
    • cargo check --workspace --all-targets --locked: exit 0
    • python -I scripts/check_no_game_data.py & git diff --check: clean

GPUs tested: n/a (lint/check and unit tests without GPU device creation)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a)

@KelboLive KelboLive left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The four targeted fixes are behaviour-preserving, and I checked the ones that could bite rather than the ones that look safe:

  • (0.0..1e9).contains(&v) is exactly the old is_finite && v >= 0.0 && v < 1e9 (NaN/±inf/−0.0/1e9 all agree; is_finite was redundant) — a separate check over those values found zero differences.
  • while let keeps one fetch_add(Relaxed) per iteration including the final failing one, and continue still re-tests the condition.
  • let _ = places.insert(...) is the same no-op: Option<(u8,u64,u32)> is Copy, so drop never did anything.
  • MeshStages regroups POD arguments in the same source order (amplify, ms, ps), no allocation, no drops.

No #[allow] was added — the only too_many_arguments allow in the touched file is pre-existing on the inner build.

Two caveats before merge:

  1. --all-targets is not clean: six pre-existing leonida-shader test warnings remain (double_comparisons, neg_cmp_op_on_partial_ord in valu_tests.rs), so cargo clippy --workspace --all-targets -- -D warnings still fails. The body's command (without --all-targets) is clean — say which one you mean.
  2. The branch is 14 commits behind main, and current main already has an unused_mut at leonida-gpu/src/host.rs:7435 that this PR does not touch (it disappeared in the diff only because of the stale base). Rebase before merging or the "remaining warnings" claim is not true of the merged tree.

Tests: same pre-existing xtask asset-policy failure before and after (it names host.rs, lower.rs and amplify_dxil.rs); the only PR-attributable change is the new HLE test (+1 passed), no failures moved. One GPU test (texture::alias_cast_tests::committed_and_placed_r32_uint_textures_cast_to_r9g9b9e5_under_legacy_barriers) flaked once when two suites ran concurrently and passed in isolation — pre-existing, unrelated, but worth knowing.

@merzleckeier

Copy link
Copy Markdown
Contributor

I tested the overlap with #2877 on 3e7b34a5. Both fix the same four warnings. A direct merge of the pair conflicts in pipeline/host.rs, pipeline/known.rs, and modules/glyphs/live.rs. Resolving those by keeping this PR's implementation and test leaves only #2877's scoped NaN test annotation as an additional change.

Independent Win64 MSVC-target cargo xwin clippy --workspace --all-targets outputs (Rust 1.98.1, separate target directories) have 11 unique diagnostics on main, 7 with this PR and 1 with the combination. The remaining unused_mut is in send_published; the code that mutates h is already #[cfg(feature = "diagnostics")]. Binding let mut h = h; under the same cfg and removing mut from the parameter gives exit 0 with -D warnings under default features. With diagnostics enabled the combined tree still reports ten separate pre-existing diagnostics, so the clean result applies to the default configuration.

MEASURED, AI-assisted (Codex).

@imShangLi

Copy link
Copy Markdown
Contributor

VERIFY-2873 — Linux, Rust 1.98.1 (the pinned toolchain), no GPU device, no game files

Verdict: PASS. The rewrites are correct, and the one that is not strictly required by clippy is semantically identical to what it replaces — I checked that over two million random bit patterns. It conflicts with #2877, which does the same work.

Head 7feda433, base the current main 88a9f133, merge base ed867d7b, 1 commit, 3 files, +53/−11: d3d12/crates/leonida-gpu/src/pipeline/host.rs, d3d12/crates/leonida-gpu/src/pipeline/known.rs, d3d12/crates/leonida-hle/src/modules/glyphs/live.rs.

1. What it fixes

The same three clippy warnings #2877 fixes, in a different spelling:

  • known.rs: drop(places.insert(..)) → let _ = places.insert(..), and loop { … else { break } } → while let … { … };
  • host.rs: the three shader bytecodes become a MeshStages struct, so mesh_pipeline takes six arguments instead of eight;
  • live.rs: v >= 0.0 && v < 1e9 → (0.0..1e9).contains(&v) — and here v.is_finite() is dropped, which the contains form does not need.

And it adds a test for the last one, plausible_checks_nonnegative_whole_counters_below_one_billion, which drives plausible() with a Fake memory over 0.0, −0.0, 999 999 999.0, 1e9, −1.0, 0.5, NaN, ±∞.

2. The rewrite is semantically identical — checked

Dropping is_finite() is safe because the range form already rejects every non-finite value: (0.0..1e9).contains(&v) is 0.0 <= v && v < 1e9, and both comparisons are false for a NaN and for ±∞.

I checked it rather than reasoning it, comparing the old and the new closure over:

  • the 17 values the new test uses (0.0, −0.0, 1e9, 1e9−1, −1.0, 0.5, NaN, ±∞, 1e300, −1e300, f64::MIN_POSITIVE, f64::MAX, 2.0, −2.0, 1e-300);
  • 2 000 000 random f64 bit patterns;
  • 4 000 values around the 1e9 boundary.
随机 2,000,000 个 f64 位型中不同的: 0
手工用例中不同的: 0
1e9 边界附近不同的: 0

3. Clippy does not require dropping is_finite()

The repository enables clippy::all ([workspace.lints.clippy] all = { level = "warn", priority = -1 }). I ran the pinned clippy (1.98) over the three spellings:

spelling clippy 1.98
v.is_finite() && v >= 0.0 && v < 1e9 && v.fract() == 0.0 (main) manual_range_contains
(0.0..1e9).contains(&v) && v.fract() == 0.0 (this pull request) no warning
v.is_finite() && (0.0..1e9).contains(&v) && v.fract() == 0.0 (#2877) no warning

So the is_finite() may stay; dropping it is tidier, and the test that comes with it is what makes the dropping safe to do. The #[allow] in valu_tests.rs that #2877 adds is not in this pull request — that is the one file of the four the two pull requests do not share.

4. It conflicts with #2877

Merging the two together fails:

$ git merge pr2873 pr2877
ERROR: content conflict in d3d12/crates/leonida-gpu/src/pipeline/known.rs
ERROR: content conflict in d3d12/crates/leonida-hle/src/modules/glyphs/live.rs

They are two versions of the same fixes — the same let _ = and while let, the same struct for the arguments (MeshStages here, Stages in #2877), the same range rewrite — differing in the comments and in which of them brings a test. One needs to be rebased onto the other; the parts worth keeping are this one's test and #2877's comments.

5. What I did not check

  • The tests of leonida-gpu and leonida-hle. Neither crate builds on Linux for reasons that predate this pull request (upstream: "The crates are Windows-only today … Linux follows Linux: build leonida.exe and run it under Proton or Wine #2577"), so the new test plausible_checks_nonnegative_whole_counters_below_one_billion could not be run here — I checked the rewrite it pins by an independent equivalence test instead (§2), which is what the test asserts, but not the test itself.
  • The warning count. Clippy needs the crate to compile, so I could not run cargo clippy --workspace here; I ran clippy on the three spellings of the live.rs line in isolation (§3) instead.
  • mesh_pipeline's new argument shape. The struct is a mechanical change to satisfy too_many_arguments; the four call sites are the only thing that changes shape, and I read all four. I did not run the mesh pipeline (it needs a D3D12 device).
  • cargo fmt is left out of the d3d12 workflow; this pull request's host.rs call sites are formatted across several lines, which is the other of the two spellings of the same change.
  • cargo clippy --workspace --all-targets --locked -- -D warnings fails on main for unrelated reasons (the workflow runs it as a report too).

AI-assisted: MiniMax M3.1 Flash.

@OreoFR

OreoFR commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Merging as part of a group. Head 7feda43; the group branch main 1e3e316 + #2862 + #2824 + #2873 (7988c1c, merged in that order) passed the full CI (https://github.com/OreoFR/leonida/actions/runs/46740411028, the same workflow file as here, run on that branch) and No Game Data (https://github.com/OreoFR/leonida/actions/runs/46740416586); main was 1e3e316 with its CI green when the group merged. Claim: D3D12-CLIPPY-WORKSPACE-CLEAN (#2570 (comment)). Red/green: no red/green possible (behaviour-preserving clippy cleanup); merzleckeier and imShangLi (Linux, PASS) checked it, KelboLive review on this head. I ran: the five PRs #2860-#2862, #2824 and #2873 merged together onto main ab374c7 (main since gained only #2935, a CI workflow change, and #2860 and #2861, both part of that test), with the shader (418 passed, 0 failed), gpu (644/0) and hle (247/0) cargo tests. In-game run: RTX 4070 Laptop 8 GB, NVIDIA 621.40, a cold start to the world then a 330 s warm walking run, 0 device lost, no panic. CI: green on head, main and the group branch. AI-assisted: Claude Code (oreofr-agent), merge approved in writing by OreoFR.

@Johnqui92 Johnqui92 mentioned this pull request Dec 1, 2026
fiestorra added a commit to fiestorra/leonida-carry that referenced this pull request Dec 1, 2026
The four fixes this branch started with are on main already, from the other
version of them (ProjectLeonida#2873): `let _ = places.insert(..)`, `while let` in
`pipeline/known.rs`, `(0.0..1e9).contains(&v)` in `glyphs/live.rs` and the
`MeshStages` struct for `mesh_pipeline`. What is left is the part that commit
did not carry:

  - the six `--all-targets` warnings in `emit/valu_tests.rs`: clippy wants
    `a != b` for `a < b || a > b`, and in a table of RDNA2's sixteen f32
    compare predicates those are not the same function - with a NaN the first
    is false and the second is true. The two lints are allowed on that one
    test, with the reason above it.

  - `unused_mut` on `send_published`'s `Handoff`: what writes it is behind
    `diagnostics`, so the parameter loses `mut` and keeps a `let mut h = h;`
    under that feature.

Measured on main 1fff691, before and after:

  cargo clippy --workspace                    2 warnings -> 0
  cargo clippy --workspace --all-targets     10 warnings -> 0
  cargo test -p leonida-shader float_compares_with_nan  1 passed
  cargo test -p leonida-gpu --lib -- --test-threads=1   643 passed; 1 failed,
      descriptor::host::tests::views_are_made_beside_the_heap_and_copied_in,
      which fails the same way on main without this change

With --features diagnostics nothing new appears: the one warning in
`leonida-gpu/src/host.rs` under that feature is at line 4677, not here.

Written with an AI assistant.
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.

5 participants