Skip to content

fix(mir-lower): support bounded packed AS3 arrays - #1073

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

nihalpasham merged 5 commits into
NVIDIA:mainfrom
uurl:fix/packed-as3-array-internal-abi

Conversation

@uurl

@uurl uurl commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1072

Depends on #1064

This PR is stacked on #1064. Until #1064 merges, GitHub's diff against main also includes the recursive/multi-leaf packed-AS3 changes from that PR.
The incremental change in this PR is the bounded fixed-array support.

Summary

Extend the recursive packed-AS3 internal device ABI support with bounded fixed arrays of shared-memory pointer leaves.

Packed structs can now be returned from internal device functions when their supported recursive shape contains fixed AS3 pointer arrays whose total array-expanded shared-pointer leaf count does not exceed 16.

The function body continues to operate on the semantic packed aggregate containing AS3 pointers. Internal device arguments retain the existing flattened argument ABI. At the return boundary, the existing target-stable storage machinery recursively rebuilds admitted arrays and replaces their AS3 leaves with generic pointers.

Implementation

This change widens packed_shared_internal_abi_info without duplicating the existing recursive storage or value-coercion machinery.

The classifier now:

  • recursively traverses MIR structs and tuples as before;
  • recursively admits fixed arrays;
  • accepts up to 16 array-expanded AS3 pointer leaves per packed return carrier;
  • continues to accept direct and recursively nested non-array AS3 leaves without charging them against the array-specific budget;
  • continues to require a byte-faithful packed root struct;
  • keeps vectors and unrelated aggregate kinds fail-closed.

target_stable_storage_type remains responsible for the recursive AS3 -> generic storage rewrite and already reconstructs arrays element by element at the physical value boundary.

The packed aggregate construction path continues to keep semantic AS3 pointers in SSA. No address-space conversion is introduced during semantic aggregate construction.

Tests

Added coverage for:

  • a bounded fixed AS3 pointer array using the target-stable return carrier;
  • acceptance at the exact 16-leaf array rewrite bound;
  • rejection above the 16-leaf array rewrite bound;
  • explicit rejection of AS3 pointer vectors;
  • semantic packed SSA construction containing an AS3 pointer array;
  • end-to-end device call/return flow exercising the bounded array return carrier.

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

The packed-AS3 classifier coverage passes with 8 tests, including the explicit vector rejection and both sides of the array rewrite bound.

The mir-lower suite passes 260 unit tests and 117 lowering tests.

The end-to-end packed_aggregate_abi regression passes on sm_120a, including the bounded-array packed shared internal ABI path.

Out of scope

This PR intentionally does not add support for:

  • AS3 pointer arrays above the explicit 16-leaf rewrite budget;
  • AS3 pointer vectors;
  • whole-value packed AS3 memory loads/stores;
  • packed-AS3 field projections requiring local materialization;
  • kernel-entry ABI changes.

Those remain separate work.

uurl and others added 4 commits August 19, 2026 19:20
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
nihalpasham force-pushed the fix/packed-as3-array-internal-abi branch from 15d33f0 to 5e1605a Compare August 20, 2026 11:56
@nihalpasham nihalpasham added enhancement New feature or request IR-lowering Lowering between dialects (dialect-mir to LLVM dialect) codegen Device code-generation pipeline (Rust MIR to IR to PTX) Depends Blocked on another PR/issue or an upstream dependency labels Aug 20, 2026
@nihalpasham

Copy link
Copy Markdown
Collaborator

@nihalpasham
nihalpasham merged commit d1d73a4 into NVIDIA:main Aug 20, 2026
50 checks passed
@uurl
uurl deleted the fix/packed-as3-array-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

codegen Device code-generation pipeline (Rust MIR to IR to PTX) Depends Blocked on another PR/issue or an upstream dependency enhancement New feature or request IR-lowering Lowering between dialects (dialect-mir to LLVM dialect)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support bounded AS3 pointer arrays in the packed internal device ABI

2 participants