Skip to content

fix(codegen): align export and call names - #185

Merged
nihalpasham merged 1 commit into
NVIDIA:mainfrom
niklebedenko:prepare-fqdn-export-name
Jun 17, 2026
Merged

nihalpasham merged 1 commit into
NVIDIA:mainfrom
niklebedenko:prepare-fqdn-export-name

Conversation

@niklebedenko

Copy link
Copy Markdown
Contributor

Closes #184.

Problem

Definition-side export names and call-side names could diverge because they used different facts to decide between a raw FQDN and rustc's mangled symbol name. The collector sees a resolved rustc Instance, while MIR call lowering classified generic calls from raw FnDef substitutions and used the raw FnDef FQDN for non-generic calls. Concrete trait impl calls can carry operand substitutions even when they resolve to a monomorphic instance, and their trait item FQDN can differ from the resolved impl FQDN. The collector also treated invalid FQDN characters as a reason to mangle, while call lowering sends non-generic FQDNs through pliron's legalizer.

Fix

Use resolved rustc instance data as the single rule:

  • resolved instances with generic args use rustc's mangled symbol name;
  • non-generic resolved instances keep the resolved Instance::name() FQDN and let the shared pliron legalizer produce the final identifier;
  • raw-name collisions still fall back to rustc's mangled symbol name;
  • foreign items keep using their link symbol because no local definition is exported.

Diligence

Checked both duplicate naming paths:

  • rustc-codegen-cuda::DeviceCollector::compute_export_name now documents that invalid FQDN characters are not a mangle trigger and that resolved Instance::args is the authority.
  • mir-importer::translator::terminator::extract_func_info now resolves the stable MIR FnDef before choosing FQDN vs Instance::mangled_name, and uses Instance::name() for non-generic call symbols so concrete trait impl calls target the impl definition rather than the trait item.
  • body.rs::translate_body already legalizes definition export names with the same Legaliser instance used by call lowering, so raw FQDNs match after legalization.

Tests

Added crates/rustc-codegen-cuda/examples/export_name_policy, a focused regression example covering:

  • concrete trait impl method naming: <Vec2 as DeviceMeasure>::trait_impl_value;
  • sibling concrete inherent impl FQDN legalization: Wrapper<Vec2>::inherent_concrete_value.

Validation

Targeted validation:

scripts/smoketest.sh --compile-only --no-color --only '^export_name_policy$'

@nihalpasham
nihalpasham force-pushed the prepare-fqdn-export-name branch from 49ceca7 to 7a9f43c Compare June 17, 2026 04:27
@nihalpasham nihalpasham added codegen Device code-generation pipeline (Rust MIR to IR to PTX) bug Something isn't working labels Jun 17, 2026
@nihalpasham

Copy link
Copy Markdown
Collaborator

Thanks for the PR. The names line up now: def side and call side both key off the resolved Instance through the same legaliser.

@nihalpasham
nihalpasham merged commit 3000d3f into NVIDIA:main Jun 17, 2026
24 checks passed
@niklebedenko
niklebedenko deleted the prepare-fqdn-export-name branch June 24, 2026 11:40
meefs pushed a commit to meefs/cuda-oxide that referenced this pull request Sep 30, 2026
…t arch (NVIDIA#185)

Follow-ups to NVIDIA#183 (issue NVIDIA#172):

- Extract redist archives with --skip-old-files --warning=existing-file:
  cross-archive path collisions become first-wins and visible in the
  build log instead of silently taking whichever archive extracted last.
  Reorder libnvvm ahead of cuda_nvcc so canonical nvvm/ files win under
  first-wins, and document that the list order now matters.
- Assert bin/tileiras and nvvm/lib64/libnvvm.so exist after assembly so
  the exe-relative-lookup failure mode from NVIDIA#172 cannot silently regress
  on a future version bump.
- Derive the Debian multiarch driver directory from uname -m instead of
  enumerating per-arch triplets: shorter, searches the host arch first,
  and covers future architectures without edits.
- Point the hash bookkeeping at NVIDIA's redistrib_13.3.0.json manifest
  for future version bumps.

Signed-off-by: Melih Elibol <[email protected]>
meefs pushed a commit to meefs/cuda-oxide that referenced this pull request Sep 30, 2026
…NVIDIA#225, NVIDIA#185) (NVIDIA#256)

Three squash merges landed from branches that had resolved a merge against
main by keeping pre-merge copies of files, so each one quietly reverted an
earlier, unrelated merge:

- NVIDIA#239 (2482cb9) reverted NVIDIA#240 (1216aef): the const raw-pointer surface
  (as_ptr, program_id/num_programs, the cast_* and get_tensor_base helpers,
  unsafe on load_ptr_tko/store_ptr_tko), the compiler's const-pointer
  typing, the two GPU test files and the matching book and tutorial text.
- NVIDIA#247 (5f5f4c5) reverted NVIDIA#225 (a2843e7): integer division and remainder
  serialization (rounding<zero> and inferred signedness on divi/remi) and
  its test.
- NVIDIA#187 (35a9cc2) reverted NVIDIA#185 (cbf52c0): the flake.nix toolkit-assembly
  hardening and host-arch driver directory derivation.

This re-applies all three verbatim as cherry-picks. The only overlapping
file, cutile-book/guide/performance.md, merges cleanly with NVIDIA#239's own
edits. A per-file scan of the last 60 merges finds no other reversal still
missing at HEAD: NVIDIA#249's removal of the About page was deliberate, and the
two setup-python flips in .github/workflows/pages.yml were re-applied by
the later dependabot bump.

Verified: cargo fmt, cargo build, and the restored GPU tests
(const_pointers, program_id) plus integer_ops, memory_and_atomic_ops and
optimization_hints pass on an RTX 5090 with CUDA 13.3.

Signed-off-by: Melih Elibol <[email protected]>
Co-authored-by: Gabriel Wu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working codegen Device code-generation pipeline (Rust MIR to IR to PTX)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Align definition export names with resolved call target names

2 participants