Skip to content

fix(mir-lower): support recursive packed address-space 3 internal ABI - #1064

Merged
nihalpasham merged 3 commits into
NVIDIA:mainfrom
uurl:fix/recursive-packed-as3-internal-abi
Aug 20, 2026
Merged

nihalpasham merged 3 commits into
NVIDIA:mainfrom
uurl:fix/recursive-packed-as3-internal-abi

Conversation

@uurl

@uurl uurl commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1063

Summary

Generalize the packed-AS3 internal device ABI support introduced by #1001 from a single direct shared-pointer leaf to recursive and multi-leaf aggregate shapes.

The internal ABI can now carry packed structs containing:

  • multiple direct AS3 pointer leaves;
  • AS3 pointer leaves nested inside structs;
  • AS3 pointer leaves nested inside tuples.

The function body still operates on the semantic packed aggregate containing AS3 pointers. Internal device arguments continue to use the existing flattened argument ABI. At the return boundary, the existing target-stable storage machinery recursively replaces every admitted AS3 leaf with a generic pointer.

Implementation

This change widens packed_shared_internal_abi_info without duplicating the existing recursive storage/coercion machinery.

The classifier now:

  • admits scalar and pointer leaves;
  • recursively traverses MIR structs and tuples;
  • accepts one or more AS3 leaves;
  • continues to require a byte-faithful packed root struct;
  • rejects arrays and vectors for this lane.

target_stable_storage_type remains responsible for the actual recursive AS3 -> generic storage rewrite.

The packed aggregate construction path continues to keep semantic AS3 pointers in SSA and uses the widened classifier only as the admission gate.

Tests

Added coverage for:

  • multiple direct AS3 leaves;
  • nested struct AS3 leaves;
  • nested tuple AS3 leaves;
  • arrays remaining out of scope;
  • semantic packed SSA construction with multiple direct leaves;
  • semantic packed SSA construction with nested leaves;
  • end-to-end device call/return coverage for multi-leaf and nested packed aggregates.

Validation performed:

  • cargo fmt --all -- --check
  • git diff --check
  • cargo test -p mir-lower packed_shared_internal_abi -- --nocapture
  • cargo test -p mir-lower packed_struct_construction_with -- --nocapture
  • cargo test -p mir-lower --all-targets
  • cargo clippy -p mir-lower --all-targets -- -D warnings
  • cargo oxide build packed_aggregate_abi
  • cargo oxide run packed_aggregate_abi
  • cargo oxide run addressof_sharedarray

mir-lower passes 257 unit tests and 117 lowering tests.

The end-to-end packed_aggregate_abi regression passes on sm_120a, including recursive and multi-leaf packed shared internal ABI coverage.

Out of scope

This PR intentionally does not add support for:

  • AS3 pointer arrays;
  • AS3 pointer vectors;
  • whole-value packed AS3 memory loads/stores;
  • packed-AS3 field projections requiring local materialization;
  • kernel-entry ABI changes.

Those remain separate follow-up work.

@nihalpasham nihalpasham changed the title fix(mir-lower): support recursive packed AS3 internal ABI fix(mir-lower): support recursive packed address-space 3 internal ABI Aug 20, 2026
The MIR-shape predicate replaced a post-conversion field scan that
skipped zero-sized fields before classifying. Restore that parity on
the MIR side so a zero-sized non-struct field (e.g. [u8; 0]) does not
knock a previously-admitted packed struct out of the ABI lane.
nihalpasham pushed a commit that referenced this pull request Aug 20, 2026
The docs gate runs `cargo doc` without `--document-private-items`, so it never
renders a private item and never checks the intra-doc links in one. #1014 and
#1042 cleaned `cuda-macros`, `mir-importer/statement.rs` and the codegen
backend's collector; this is one of the four that were left:

    error: unresolved link to `classify_op`
      --> crates/llvm-export/src/export/ops.rs:55

`classify_op` is a `macro_rules!` defined further down the same file, at :138.
A `macro_rules!` macro is in scope only textually after its definition unless
it is exported, so no path resolves from a doc comment above it -- rustdoc says
as much: "`macro_rules` named `classify_op` exists in this crate, but it is not
in scope at this link's location". It becomes a plain code span, and since the
sentence is one step of a four-step contract about this file, it gains "below"
so the reference still points somewhere.

Three of the four remain. One is `make_disjoint_slice_struct` in
`mir-lower/src/convert/ops/aggregate.rs`, which needs only a
`crate::convert::types::` prefix; the other two are `MirFieldAddrOp` and
`MirArrayElementAddrOp` in `mir-importer/src/translator/rvalue.rs`. Both files
are under open pull requests (#1062 and #1064 for the first, #1059 and #1062
for the second), so they are left rather than raced.
`--document-private-items` can join the docs gate once they land.

Verified: `RUSTDOCFLAGS="-D warnings" cargo doc --no-deps
--document-private-items -p llvm-export` reports one unresolved link on `main`
and none with this change. The gate's own invocation passes before and after.
fmt clean.

Comment-only change.

Signed-off-by: Vyncint Ng <[email protected]>
@nihalpasham nihalpasham added bug Something isn't working IR-lowering Lowering between dialects (dialect-mir to LLVM dialect) codegen Device code-generation pipeline (Rust MIR to IR to PTX) labels Aug 20, 2026
@nihalpasham

Copy link
Copy Markdown
Collaborator
  • Verified end to end: mir-lower 262 lib + 117 integration tests green, clippy/fmt clean, cargo oxide run packed_aggregate_abi passes on an RTX 5090 (cc 12.0), full compile-only smoketest 216/216. Also exercised the modern NVVM path this PR had not: built with --emit-nvvm-ir --arch=sm_120 and compiled the result through libNVVM + nvJitLink to a cubin, confirming the multi-leaf/nested carrier is accepted on the data layout where the 32-bit AS3 vs 64-bit generic divergence actually exists (internal call returns <{ i8, ptr, ptr }> while the semantic type keeps ptr addrspace(3)).
  • Two commits pushed to this branch:
    • the new MIR-shape predicate dropped the ZST skip the old post-conversion field scan had, so a packed struct carrying a zero-sized non-struct field (e.g. a [u8; 0] marker) fell out of the ABI lane and hit the fail-closed construction error. Added a MIR-side zero-sized check mirroring is_zero_sized_type plus a classifier test.
    • rustfmt pass on the example.

@nihalpasham
nihalpasham merged commit 3f1c82c into NVIDIA:main Aug 20, 2026
49 checks passed
@uurl
uurl deleted the fix/recursive-packed-as3-internal-abi branch August 22, 2026 06:09
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) IR-lowering Lowering between dialects (dialect-mir to LLVM dialect)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support recursive and multi-leaf packed AS3 aggregates across the internal device ABI

2 participants