Skip to content

chore(backend): scope the codegen backend's blanket dead-code allows - #1016

Merged
nihalpasham merged 2 commits into
NVIDIA:mainfrom
vyncint:chore/backend-scope-blanket-allows
Aug 19, 2026
Merged

nihalpasham merged 2 commits into
NVIDIA:mainfrom
vyncint:chore/backend-scope-blanket-allows

Conversation

@vyncint

@vyncint vyncint commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Summary

crates/rustc-codegen-cuda/src/lib.rs suppresses two lints for the whole crate:

#![allow(unused_imports)]
#![allow(dead_code)]

That is the largest first-party crate in the tree, and those two lines mean no unused import and no dead item anywhere in it has been reported since they were added. #833 is the precedent for caring: "stop exporting the translator, and drop what that hid: six items with no callers anywhere on main. This is the hygiene rustc and LLVM get from non-pub."

Removing both surfaces exactly four items — small enough to resolve rather than re-suppress:

Site Item
lib.rs:345 unused import std::sync::Arc
collector.rs:2442 unused import rustc_index::Idx (inside mod tests)
device_codegen.rs:286 fields ptx_path, ll_path, ptx_content never read
device_codegen.rs:443 variant Translation never constructed

Two deletions, two reasoned keeps

The two unused imports are deleted. collector.rs:2442 is the interesting one: Idx is already imported at the top of the file and the test module gets it via use super::*;, so the explicit import is redundant — and it is only visible under --all-targets, which is how CI's clippy runs but not how cargo check --lib does. I found it by running the real gate after cargo check reported clean.

The other two are kept with a local #[allow(dead_code, reason = ...)] each, because both are deliberate:

  • DeviceCodegenResult's three fields are written by run_device_codegen (device_codegen.rs:826-829) and documented in the module's own diagram at :75-78. They record what codegen produced. Nothing links this crate as a library — it is a dylib rustc loads via -Zcodegen-backend — so pub does not make them reachable from anywhere either.
  • DeviceCodegenError::Translation has a Display arm at :457 but no constructor: translation failures arrive as cuda_oxide_codegen::PipelineError and are reported through that. Keeping the variant keeps this taxonomy mirroring the pipeline's.

So two invisible crate-wide suppressions become one deletion pair and two local, reasoned decisions — and any future dead code in the backend is caught instead of absorbed.

Testing

Local, no GPU, on the backend's own workspace with the gates CI runs there.

  • Mutation: adding an unused import and an uncalled fn now produces 2 warnings, and 3 errors under -D warnings — where before both passed silently
  • cargo clippy --all-targets -- -D warnings passes
  • cargo test --lib 23/23
  • RUSTDOCFLAGS="-D warnings" cargo doc --no-deps passes
  • cargo fmt --all --check clean
  • cargo oxide run <example> — not applicable, no behaviour change

vyncint and others added 2 commits August 18, 2026 17:54
`crates/rustc-codegen-cuda/src/lib.rs` suppresses two lints for the whole
crate:

    #![allow(unused_imports)]
    #![allow(dead_code)]

That is the largest first-party crate in the tree, and those two lines mean no
unused import and no dead item anywhere in it has been reported since they were
added. NVIDIA#833 is the precedent for caring: "stop exporting the translator, and
drop what that hid: six items with no callers anywhere on main. This is the
hygiene rustc and LLVM get from non-pub."

Removing both surfaces exactly four items, which is small enough to resolve
rather than re-suppress:

  lib.rs:345              unused import `std::sync::Arc`
  collector.rs:2442       unused import `rustc_index::Idx` (in `mod tests`)
  device_codegen.rs:286   fields `ptx_path`, `ll_path`, `ptx_content` never read
  device_codegen.rs:443   variant `Translation` never constructed

Two are genuinely unused imports and are deleted. `collector.rs:2442` is the
interesting one: `Idx` is already imported at the top of the file, and the test
module gets it through `use super::*;`, so the explicit import is redundant --
and it is only visible under `--all-targets`, which is how CI's clippy runs but
not how `cargo check --lib` does.

The other two are kept, with a local `#[allow(dead_code, reason = ...)]` each,
because both are deliberate rather than accidental:

  * `DeviceCodegenResult`'s three fields are *written* by `run_device_codegen`
    (device_codegen.rs:826-829) and documented in the module's own diagram at
    :75-78. They record what codegen produced. Nothing links this crate as a
    library -- it is a `dylib` rustc loads via `-Zcodegen-backend` -- so `pub`
    does not make them reachable from anywhere either.
  * `DeviceCodegenError::Translation` has a `Display` arm at :457 but no
    constructor: translation failures arrive as
    `cuda_oxide_codegen::PipelineError` and are reported through that. Keeping
    the variant keeps this taxonomy mirroring the pipeline's.

So two invisible crate-wide suppressions become one deletion pair and two
local, reasoned decisions -- and any *future* dead code in the backend is now
caught instead of absorbed. Verified by adding an unused import and an uncalled
fn: 2 warnings, and 3 errors under `-D warnings`, where before both passed
silently.

Verified on the backend's own workspace with the gates CI runs there:
`cargo clippy --all-targets -- -D warnings` passes, `cargo test --lib` is 23/23,
`RUSTDOCFLAGS="-D warnings" cargo doc --no-deps` passes, and
`cargo fmt --all --check` is clean.

Signed-off-by: Vyncint Ng <[email protected]>
The DeviceCodegenResult doc block named a run_device_codegen function
that does not exist; the real entry point is generate_device_code.

Replace the two type-level #[allow(dead_code)] attributes with
member-level #[expect(dead_code, reason = ...)] on the three
write-only fields (ptx_path, ll_path, ptx_content) and the
unconstructed Translation variant. The live fields and variants of
both types are lint-checked again, and #[expect] will flag each
suppression the moment its member gains a reader or constructor.
@nihalpasham nihalpasham added refactor Internal restructuring with no behavior change QoL-improvement Quality-of-life improvement; not a correctness fix codegen Device code-generation pipeline (Rust MIR to IR to PTX) labels Aug 19, 2026
@nihalpasham

Copy link
Copy Markdown
Collaborator
  • Verified both deleted imports are unused and the two kept items are genuinely dead: the three fields are written in generate_device_code and never read, and the Translation variant has a Display arm but no construction site.
  • One commit layered on: the new doc block named a function that does not exist (run_device_codegen; the real writer is generate_device_code), and the two type-level allows are now member-level #[expect(dead_code, reason = ...)] so the live members of both types are lint-checked again.

@nihalpasham
nihalpasham merged commit cc0be10 into NVIDIA:main Aug 19, 2026
48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codegen Device code-generation pipeline (Rust MIR to IR to PTX) QoL-improvement Quality-of-life improvement; not a correctness fix refactor Internal restructuring with no behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants