Skip to content

feat(mir-importer): support bare struct array constants - #855

Merged
nihalpasham merged 3 commits into
NVIDIA:mainfrom
uurl:feat/bare-struct-array-constants
Aug 13, 2026
Merged

nihalpasham merged 3 commits into
NVIDIA:mainfrom
uurl:feat/bare-struct-array-constants

Conversation

@uurl

@uurl uurl commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Closes #854

Summary

Adds support for bare arrays whose elements are structs.

The MIR importer already has layout-aware struct constant decoding for allocation-backed constants and byte-backed aggregate decoding. This change extends the bare-array element boundary and byte-array dispatch so struct elements can reuse those existing paths.

What changed

  • Allow MirStructType elements in bare array value constants.
  • Extend byte-backed array materialization to dispatch struct elements through the existing aggregate constant decoder.
  • Keep immutable-global promotion unchanged.
  • Keep pointer-to-array struct constants unsupported.
  • Add regression coverage for:
    • padded #[repr(C)] structs,
    • nested structs,
    • over-aligned zero-sized structs.
  • Add LLVM code-shape checks for padded and nested struct array storage.

Scope

This intentionally does not change promotable_array_element.

Bare array values can fall back to element-wise materialization, while pointer-to-array constants require the immutable-global path. Widening the promotion predicate here would therefore also widen pointer-to-array semantics, which is outside this change.

Unions are also out of scope.

Validation

cargo test -p mir-importer
1068 passed; 0 failed

cargo clippy -p mir-importer --all-targets -- -D warnings
PASS

cargo oxide run array_constants
PASS

./crates/rustc-codegen-cuda/examples/array_constants/verify-code-shape.sh
array_constants code shape: PASS

CUDA_OXIDE_NO_OPT=1 cargo oxide run array_constants
PASS

The GPU regression covers primitive, enum, tuple, padded/nested/ZST struct, pointer-to-array, and tuple-array static-pointer constants.

uurl and others added 3 commits August 12, 2026 21:46
…ntract

The PR rewrote promotable_array_element's doc contract (bare-value
admission is now wider than promotion; structs fall back to
element-wise materialization), but the tuple pointer-to-array test
still cited the old cannot-drift-apart phrasing. Comment only.

Signed-off-by: nihalpasham <[email protected]>
@nihalpasham nihalpasham added enhancement New feature or request codegen Device code-generation pipeline (Rust MIR to IR to PTX) labels Aug 13, 2026
@nihalpasham

Copy link
Copy Markdown
Collaborator

Gist: the project's own missing-arm protocol, done right: the bare-array gate admits MirStructType and the byte-path builder routes struct elements through the layout-aware decoders that already served structs inside tuples and enum payloads, so rustc offsets, padding, ZST stripping, and the relocation audit all apply unchanged. Immutable-global promotion and pointer-to-array stay narrower on purpose, and the rewritten doc contracts say why. Pushed c146b31 fixing one stale test comment that still cited the old cannot-drift-apart phrasing. Closes #854.

Verified here:

  • ran on an RTX 5090 (sm_120): array_constants PASS in both optimization modes, verify-code-shape.sh PASS, and the padded layout alloca [2 x { i8, [3 x i8], i32 }] present in the generated IR;
  • all 1068 mir-importer tests pass;
  • pointer-to-array rejection confirmed unchanged (structs still refused there, with the fallback rationale now documented).

The perf follow-up (promoting struct tables to one module-image global, as nvcc emits) is real but correctly out of scope; a tracking issue is being filed. Landing once CI is green.

@nihalpasham
nihalpasham merged commit cce79ac into NVIDIA:main Aug 13, 2026
44 checks passed
@uurl
uurl deleted the feat/bare-struct-array-constants branch August 13, 2026 08:21
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) enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support bare arrays of struct constants

2 participants