Repository navigation
refactor(mir-importer): stop exporting the translator, and drop what that hid - #833
Merged
nihalpasham merged 1 commit intoAug 12, 2026
Conversation
…that hid `pub mod translator` made every item under it reachable API, so `dead_code` was off for the whole module tree. The only in-tree consumer reaches the translator through `pipeline`, and the two predicates outsiders need are already re-exported from the crate root, so the module is now `pub(crate)`. That switches the lint back on and it finds six orphans, all removed: - `intrinsics::warp::emit_warp_redux` -- the whole 118-line module. Called out as dead in the NVIDIA#816 merge note; the redux family is catalog-generated. Its doc claimed to be "shared by the whole integer reduction family", which is what sent the book's Stage 3 to the wrong place twice. - `intrinsics::indexing::emit_index_2d` and its `generated_sreg_op` helper. Its own doc says the dispatcher routes index helpers as normal function calls instead; `try_dispatch_intrinsic` returns `Ok(None)` for all of them. - `helpers::emit_nvvm_intrinsic` / `emit_nvvm_intrinsic_u64` -- the pre-catalog twins of `emit_generated_nvvm_intrinsic{,_u}`, differing only in not stamping the ABI marker. - `translator::translate_function` -- the crate doc example's entry point. The example passed four arguments to a five-argument function, so it had not been compiled against reality in some time. - `types::get_f32_type`. `index_1d_sreg_ops_carry_their_exact_generated_markers` built its ops with the dead `generated_sreg_op`, so it could not have caught a regression in what the compiler actually emits. It now asserts the same three markers against the target table the backend reads back at verification time, which cross-checks the two generated artifacts against each other. The seventh orphan is generated: `generated_intrinsic_marker`, a 2142-line path-keyed table whose only callers are the generated tests in the same file. Gated on `cfg(test)` in the renderer rather than deleted, since whether the catalog should still render it is a generator decision. If you want it gone, that is one more line in `render.rs` and -10k in output. Book and crate docs updated where they named a removed symbol: the quick-reference checklist pointed new contributors at `emit_nvvm_intrinsic`, and both flow diagrams still started at `translate_function()`. No behaviour change: nothing deleted had a caller. Signed-off-by: Vyncint Ng <[email protected]>
Collaborator
|
Gist: the translator module stops being Verified here:
Landing once CI is green. Doesn't close #811; the redux gap it references stays open. |
nihalpasham
approved these changes
Aug 12, 2026
2 of 3 tasks
nihalpasham
pushed a commit
that referenced
this pull request
Aug 18, 2026
… not exist (#978) `README.md`'s "`terminator/intrinsics/` — GPU Intrinsics" table has 12 rows. Only 7 name a module that exists; the other 5 were deleted: intrinsics/sync.rs deleted in 6a9a637 (#406) intrinsics/cluster.rs deleted in 6a9a637 (#406) intrinsics/tcgen05.rs deleted in 6a9a637 (#406) intrinsics/clc.rs deleted in 6a9a637 (#406) intrinsics/warp.rs deleted in 4c1d583 (#833) #406 moved those families onto the catalog path and #833 dropped the last of them, so all five are handled by `generated.rs` today. Meanwhile eight modules that do exist had no row: `asm`, `bigint`, `bitops`, `exact_div`, `float_math`, `iket`, `layout`, `saturating`. Between the two, the table describes a directory that has not existed for a long time -- and it is the one place a contributor looks to find where an intrinsic is translated. The book's `compiler/mir-importer.md` already describes the current model correctly ("`intrinsics/catalog.json` has its arm generated into ... `generated.rs`", and "the `intrinsics/` modules beside the generated file hold the cases the ..."), so this README was the last copy still on the old one. Rewritten to match, one row per file, each description taken verbatim from that module's own `//!` doc comment. The per-module "GPU" column is dropped for the reason #964 dropped its equivalent: minimum-SM is a per-intrinsic property the catalog already records and `intrinsics/generated-reference.md` already renders. Two smaller gaps on the same page: * The `translator/` table was missing `layout`, `location` and `payload_store`. * The Error Types table lists 7 of `PipelineError`'s 12 variants, missing `Optimization`, `TargetSelection`, `UnsupportedLinking`, `LibdeviceUnavailable` and `InvalidMirPassPipeline`. It also never says that `PipelineError` is defined in `cuda-oxide-codegen` and re-exported here, nor that the crate's own `TranslationErr` -- `Unsupported`, `TypeError`, `InvalidOp` -- is a different, narrower error. Both are now stated. (I first read this table against `error.rs` and thought every row was fictional; it is not. The variants are real, just defined a crate away.) Verified by script against the tree, with no ghost and no missing row in any of the three tables: the intrinsics table is now exactly the 15 files in `terminator/intrinsics/`; the translator table exactly the 9 files in `translator/` plus the `terminator` subdirectory it also lists; and the error table exactly the 12 `PipelineError` variants. Signed-off-by: Vyncint Ng <[email protected]>
This was referenced Aug 18, 2026
nihalpasham
pushed a commit
that referenced
this pull request
Aug 19, 2026
…ranslator rows were missing (#996) Two follow-ups from the #978 merge note. **The TMA expansion.** You flagged that #978's `tma` row was copied verbatim from `tma.rs`, whose own doc comment says "Tensor Memory Access". The unit is the Tensor Memory *Accelerator*, and the tree already says so in 22 places -- including `cuda-device/src/tma.rs`, `dialect-nvvm/src/ops/generated/tma.rs`, and the book chapter of that name. mir-importer was the holdout, in four places, so fixing the source alone would have left the README I just landed disagreeing with it: src/translator/terminator/intrinsics/tma.rs:6 module doc src/translator/terminator/intrinsics/tma.rs:34 fn doc prose src/translator/terminator/intrinsics/mod.rs:18 table row README.md:105 table row All four now read "Accelerator", and `Tensor Memory Access` no longer appears anywhere under `crates/mir-importer/`. This is the cost of the verbatim-from-doc-comment rule #977 and #978 adopted: it cannot drift from the source, which also means it faithfully reproduces the source's mistakes. Worth the trade, but the fix has to land in the source. **The three translator rows.** `src/translator/mod.rs` carries the same module table as the README and was short the same three modules #978 added there: `layout`, `location` and `payload_store`. One thing I checked and will not claim: unlike #977's table, making these rows intra-doc links does **not** put them under the docs gate. `translator` is `pub(crate) mod` since 4c1d583 (#833, "stop exporting the translator"), so `cargo doc --no-deps` never documents it and an unresolved link there is not an error. Verified by adding a `[`ghost_module`]` row and watching the gate pass. It does fail under `--document-private-items` -- but that flag also surfaces three pre-existing unresolved links elsewhere in the crate (`MirFieldAddrOp`, `MirArrayElementAddrOp`, `MirArrayType`), so turning it on is its own piece of work, not a free win here. The rows are links because the seven around them are; the enforcement claim belongs only to #977's table. Verified: the translator table is now exactly the 9 files in `translator/` plus the `terminator` subdirectory; the README's `tma` row and `tma.rs`'s doc comment are byte-identical again; `cargo test -p mir-importer` and the docs gate are clean. Signed-off-by: Vyncint Ng <[email protected]>
nihalpasham
added a commit
that referenced
this pull request
Aug 19, 2026
…1016) * chore(backend): scope the codegen backend's blanket dead-code allows `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, 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]> * chore(backend): narrow dead-code suppressions to the dead members 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. --------- Signed-off-by: Vyncint Ng <[email protected]> Co-authored-by: nihalpasham <[email protected]>
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.
The #816 merge note said
emit_warp_redux"is dead code and the redux familyis catalog-generated". It is, and it is still in the tree — because nothing was
ever going to tell us.
mir-importer'slib.rsdeclarespub mod translator,so every item under that module counts as reachable public API and
dead_codeis switched off for the entire translator subtree.
Nothing in the workspace uses that public surface.
rustc-codegen-cuda, theonly in-tree consumer, imports
mir_importer::Xroot re-exports and nevermir_importer::translator::*; no test or bench names the path either. So themodule is now
pub(crate), the two predicates outsiders do need stayre-exported from the root, and the compiler starts answering the question.
What the lint finds
Six hand-written orphans, all removed. None had a caller.
intrinsics::warp::emit_warp_reduxintrinsics::indexing::emit_index_2d+generated_sreg_ophelpers::emit_nvvm_intrinsic,emit_nvvm_intrinsic_u64translator::translate_functiontypes::get_f32_typeTwo of them are worth a sentence each.
emit_warp_reduxadvertised itself as "shared by the whole integerreduction family". It is shared by nothing, and that sentence is plausibly why
the book's Stage 3 pointed at this file twice — #815 and then 336a70b.
emit_index_2ddocuments its own obsolescence: "the dispatcher currentlytranslates every index helper as a normal function call instead of routing it
here". That is accurate —
try_dispatch_intrinsicreturnsOk(None)for allsixteen paths in that arm. The semantic warning it carried, that
index_2d_runtimemust never be flat-expanded, already appears in the module header, so nothing
is lost with it. The
generated_sreg_ophelper went with it as a cascade.emit_nvvm_intrinsic{,_u64}are the pre-catalog twins ofemit_generated_nvvm_intrinsic{,_u}: same private core,emit_nvvm_integer_intrinsic, differing only in passingNonewhere the livepair passes the ABI marker.
translate_functionwas the crate doc example's entry point. The examplepassed four arguments to a five-argument function, so it had not been compiled
against reality in a while.
One test changed rather than deleted
index_1d_sreg_ops_carry_their_exact_generated_markersbuilt its three ops bycalling
generated_sreg_op— production-dead. It therefore could not havecaught a regression in the marker the compiler actually stamps, since the
compiler does not take that path.
It now asserts the same three markers against
generated_intrinsic_marker_by_op_name, the table the backend reads back atverification time. Same intent, but the assertion now spans the two generated
artifacts — a renumbering that reached the dispatcher and not the target table
(or the reverse) fails it.
The seventh orphan is generated, so it is your call
generated::generated_intrinsic_markeris a 2142-line path-keyed table whoseonly callers are the generated tests in the same file — and those tests assert
it against
intrinsic_marker(catalog, record), which is the same expressionthat rendered it, for the same record, in the same loop. It compares the
generator to itself.
I gated it on
cfg(test)inrender.rs(one line in the output) rather thandecide that for you. Dropping it outright is one more line in the renderer and
about −10k in
generated.rs; say the word and I will send it separately.Docs that named a removed symbol
adding-new-intrinsics.md's quick-reference checklist still told newcontributors to "Use
helpers::emit_nvvm_intrinsic()for zero-argintrinsics" — the one spot the 336a70b sweep did not reach. It now points
at the
typed_swaparm you made the hand-dispatch example, and sayszero-operand intrinsics are catalog territory.
mir-importer.mdandtranslator/mod.rsboth drew a call flow starting attranslate_function(); the pipeline callsbody::translate_bodydirectly.run_pipeline.Verification
macOS (
aarch64-apple-darwin):cargo clippy -p mir-importer --all-targets -- -D warnings— cleancargo test -p mir-importer --no-fail-fast— 1068 passed, 0 failedcargo test -p cuda-intrinsics-gen --no-fail-fast— 289 passed, 0 failedcargo run -p cuda-intrinsics-gen -- check— outputs currentcargo fmt --all -- --check— cleanLinux
x86_64, Tesla T4 (sm_75), driver 595.71.05, CUDA 13.2, onnightly-2026-04-03:cargo clippy --workspace --all-targets -- -D warnings— clean, which is therun that matters here: it is what would have caught these six in the first
place, and it is green with the lint no longer suppressed
cargo test --workspace --no-fail-fast— every target ok, 0 failedcargo run -p cuda-intrinsics-gen -- check— outputs currentcargo fmt --all -- --check— cleansphinx-build -W --keep-going -b html— build succeededscripts/smoketest.shover the eight examples that exercise what changed —row_width_slice,sharedmem,swizzle_smem,thread_runs,tiled_gemm,vecadd,warp_reduce,warp_sums— 8/8 PASS, 261s. The indexing and warpones are deliberate: those are the paths whose hand-written emitters this
removes.
(Found by asking why a function the #816 note called dead was still
compiling.)