Repository navigation
chore(backend): scope the codegen backend's blanket dead-code allows - #1016
Merged
nihalpasham merged 2 commits intoAug 19, 2026
Merged
Conversation
`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.
Collaborator
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
crates/rustc-codegen-cuda/src/lib.rssuppresses two lints for the whole crate: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:
lib.rs:345std::sync::Arccollector.rs:2442rustc_index::Idx(insidemod tests)device_codegen.rs:286ptx_path,ll_path,ptx_contentnever readdevice_codegen.rs:443Translationnever constructedTwo deletions, two reasoned keeps
The two unused imports are deleted.
collector.rs:2442is the interesting one:Idxis already imported at the top of the file and the test module gets it viause super::*;, so the explicit import is redundant — and it is only visible under--all-targets, which is how CI's clippy runs but not howcargo check --libdoes. I found it by running the real gate aftercargo checkreported clean.The other two are kept with a local
#[allow(dead_code, reason = ...)]each, because both are deliberate:DeviceCodegenResult's three fields are written byrun_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 adylibrustc loads via-Zcodegen-backend— sopubdoes not make them reachable from anywhere either.DeviceCodegenError::Translationhas aDisplayarm at:457but no constructor: translation failures arrive ascuda_oxide_codegen::PipelineErrorand 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.
-D warnings— where before both passed silentlycargo clippy --all-targets -- -D warningspassescargo test --lib23/23RUSTDOCFLAGS="-D warnings" cargo doc --no-depspassescargo fmt --all --checkcleancargo oxide run <example>— not applicable, no behaviour change