Skip to content

refactor(mir-importer): stop exporting the translator, and drop what that hid - #833

Merged
nihalpasham merged 1 commit into
NVIDIA:mainfrom
vyncint:cleanup/mir-importer-dead-translator-helpers
Aug 12, 2026
Merged

nihalpasham merged 1 commit into
NVIDIA:mainfrom
vyncint:cleanup/mir-importer-dead-translator-helpers

Conversation

@vyncint

@vyncint vyncint commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

The #816 merge note said emit_warp_redux "is dead code and the redux family
is catalog-generated". It is, and it is still in the tree — because nothing was
ever going to tell us. mir-importer's lib.rs declares pub mod translator,
so every item under that module counts as reachable public API and dead_code
is switched off for the entire translator subtree.

Nothing in the workspace uses that public surface. rustc-codegen-cuda, the
only in-tree consumer, imports mir_importer::X root re-exports and never
mir_importer::translator::*; no test or bench names the path either. So the
module is now pub(crate), the two predicates outsiders do need stay
re-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.

Item Why it is there
intrinsics::warp::emit_warp_redux the whole 118-line module — the one #816 named
intrinsics::indexing::emit_index_2d + generated_sreg_op superseded legacy expansion
helpers::emit_nvvm_intrinsic, emit_nvvm_intrinsic_u64 pre-catalog twins
translator::translate_function the crate doc example's entry point
types::get_f32_type —

Two of them are worth a sentence each.

emit_warp_redux advertised itself as "shared by the whole integer
reduction 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_2d documents its own obsolescence: "the dispatcher currently
translates every index helper as a normal function call instead of routing it
here"
. That is accurate — try_dispatch_intrinsic returns Ok(None) for all
sixteen paths in that arm. The semantic warning it carried, that index_2d_runtime
must never be flat-expanded, already appears in the module header, so nothing
is lost with it. The generated_sreg_op helper went with it as a cascade.

emit_nvvm_intrinsic{,_u64} are the pre-catalog twins of
emit_generated_nvvm_intrinsic{,_u}: same private core,
emit_nvvm_integer_intrinsic, differing only in passing None where the live
pair passes the ABI marker.

translate_function was 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 a while.

One test changed rather than deleted

index_1d_sreg_ops_carry_their_exact_generated_markers built its three ops by
calling generated_sreg_op — production-dead. It therefore could not have
caught 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 at
verification 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_marker is a 2142-line path-keyed table whose
only callers are the generated tests in the same file — and those tests assert
it against intrinsic_marker(catalog, record), which is the same expression
that rendered it, for the same record, in the same loop. It compares the
generator to itself.

I gated it on cfg(test) in render.rs (one line in the output) rather than
decide 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 new
    contributors to "Use helpers::emit_nvvm_intrinsic() for zero-arg
    intrinsics"
    — the one spot the 336a70b sweep did not reach. It now points
    at the typed_swap arm you made the hand-dispatch example, and says
    zero-operand intrinsics are catalog territory.
  • mir-importer.md and translator/mod.rs both drew a call flow starting at
    translate_function(); the pipeline calls body::translate_body directly.
  • The crate doc example now uses run_pipeline.

Verification

macOS (aarch64-apple-darwin):

  • cargo clippy -p mir-importer --all-targets -- -D warnings — clean
  • cargo test -p mir-importer --no-fail-fast — 1068 passed, 0 failed
  • cargo test -p cuda-intrinsics-gen --no-fail-fast — 289 passed, 0 failed
  • cargo run -p cuda-intrinsics-gen -- check — outputs current
  • cargo fmt --all -- --check — clean

Linux x86_64, Tesla T4 (sm_75), driver 595.71.05, CUDA 13.2, on
nightly-2026-04-03:

  • cargo clippy --workspace --all-targets -- -D warnings — clean, which is the
    run 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 failed
  • cargo run -p cuda-intrinsics-gen -- check — outputs current
  • cargo fmt --all -- --check — clean
  • sphinx-build -W --keep-going -b html — build succeeded
  • scripts/smoketest.sh over 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 warp
    ones 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.)

…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]>
@nihalpasham nihalpasham added refactor Internal restructuring with no behavior change codegen Device code-generation pipeline (Rust MIR to IR to PTX) intrinsics Device intrinsics and libdevice math mappings labels Aug 12, 2026
@nihalpasham

Copy link
Copy Markdown
Collaborator

Gist: the translator module stops being pub, and what that visibility hid gets deleted: six items with no callers anywhere on main. This is the hygiene rustc and LLVM get from non-pub modules and anonymous namespaces, done Rust's way (reachability-based dead-code detection). On your open question: the cfg(test) gate on the path-keyed marker table is fine as-is; the follow-up that deletes the table (~10k generated lines) is welcome when you want it.

Verified here:

  • every deletion provably dead on origin/main: no caller outside definitions, doc mentions, and the one test the PR rewrites;
  • the root re-exports the backend imports remain intact on the PR head; renderer and checked-in generated.rs stay byte-consistent (the intrinsics-gen check CI leg gates this);
  • ran the six examples over the touched paths on an RTX 5090 (sm_120): warp_reduce, warp_sums, vecadd, thread_runs, tiled_gemm, row_width_slice all pass.

Landing once CI is green. Doesn't close #811; the redux gap it references stays open.

@nihalpasham
nihalpasham merged commit 4c1d583 into NVIDIA:main Aug 12, 2026
42 checks passed
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]>
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]>
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) intrinsics Device intrinsics and libdevice math mappings refactor Internal restructuring with no behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants