Skip to content

fix(mir-importer): lower array constants - #183

Merged
nihalpasham merged 2 commits into
NVIDIA:mainfrom
niklebedenko:prepare-array-constants
Jun 17, 2026
Merged

nihalpasham merged 2 commits into
NVIDIA:mainfrom
niklebedenko:prepare-array-constants

Conversation

@niklebedenko

Copy link
Copy Markdown
Contributor

Closes #182.

Problem

The MIR importer could lower pointer-to-array constants such as &[T; N], but bare array value constants such as const TABLE: [T; N] could still fall through as unsupported when indexed by runtime values. Nested constants such as [[T; M]; N] also lacked recursive array construction, so only flat primitive arrays were effectively covered.

Fix

Array constant lowering now has one shared value-construction path. Pointer-to-array constants decode the array value through that helper and then wrap it in MirRefOp; bare array constants return the constructed MirConstructArrayOp value directly. The helper recursively handles nested arrays whose leaves are primitive scalar elements.

Unsupported element types are rejected explicitly. The supported byte-lowered array leaves are integer, f16, f32, and f64 values, plus nested arrays of those leaves. Byte-backed constants with uninitialized bytes are now diagnosed instead of silently zero-filled.

Diligence

Checked the sibling pointer-to-array path and routed it through the same array-value helper so bare arrays and &[T; N] cannot drift. Kept the existing scalar constant and aggregate paths separate, but hardened the shared constant_bytes helper used by byte-backed constants so unsupported uninitialized bytes are not hidden.

Struct/ADT array elements remain unsupported in this PR because they need layout-aware recursive field decoding rather than the primitive byte-slicing rule used here.

Tests

Added crates/rustc-codegen-cuda/examples/array_constants covering:

  • bare [f32; 4] constants indexed by runtime thread id,
  • nested [[u32; 3]; 2] constants with runtime row/column selection,
  • pointer-to-array &[u32; 4] constants to preserve existing behavior.

Validation

Passed local targeted validation:

cargo fmt -p mir-importer -- --check
cargo fmt --manifest-path crates/rustc-codegen-cuda/examples/array_constants/Cargo.toml -- --check
scripts/smoketest.sh --compile-only --no-color --only '^array_constants$'

niklebedenko and others added 2 commits June 17, 2026 08:53
… value constants

Layered on top of the contributor PR:
- replace the U+2014 em-dash in the translate_array_value_constant doc
  comment (tracked files must not contain em-dashes)
- supported-features: note bare/nested array value constants are
  materialized, and that struct/ADT array-element constants are not yet
@nihalpasham
nihalpasham force-pushed the prepare-array-constants branch from bd744a0 to bbf938f Compare June 17, 2026 04:27
@nihalpasham nihalpasham added codegen Device code-generation pipeline (Rust MIR to IR to PTX) enhancement New feature or request labels Jun 17, 2026
@nihalpasham

Copy link
Copy Markdown
Collaborator

LGTM.

  • layered: added the supported-features row
  • heads up: the description says uninitialized bytes are now diagnosed - they aren't (the shared constant_bytes helper - still zero-fills, same as the tuple/enum paths). This I guess is harmless for the primitive leaves you accept (no padding), but dropping the claim makes more sense.
  • GPU sm_120: array_constants → PASS (24 threads); reverting only the importer arm reproduces Unsupported constant type

@nihalpasham
nihalpasham merged commit cebcc41 into NVIDIA:main Jun 17, 2026
24 checks passed
@niklebedenko
niklebedenko deleted the prepare-array-constants branch June 24, 2026 11:40
meefs pushed a commit to meefs/cuda-oxide that referenced this pull request Sep 30, 2026
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]>
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.

Lower bare and nested array constants in MIR import

2 participants