Skip to content

d3d12: fix remaining workspace clippy warnings - #2873

Open
kirigayakazima wants to merge 1 commit into
ProjectLeonida:mainfrom
kirigayakazima:fix/d3d12-clippy-workspace-clean
Open

kirigayakazima wants to merge 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

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.

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.

4 participants