Repository navigation
fix(mir-importer): compute element addresses through fat-pointer derefs - #165
Merged
Merged
Conversation
Writes through `a.get_mut(i)` on a `&mut [f32; N]` were rejected with "cannot compute a mutable in-memory address through fat-pointer deref (projection [Deref, Index(..)])": the inlined `slice::get_mut` body takes `&mut (*fat)[i]` through a fat `&mut [f32]` local, and the unified place-address walker refused to walk through slice-shaped pointees. The direct form `a[i] = v` failed separately because the 2-level assignment match had no `(Deref, Index)` arm. Teach `translate_place_addr_from_slot` to handle a mid-chain fat deref the same way the value-space read path already does: load the whole scalarized (data ptr, len) value from the slot, extract field 0 (the thin data pointer, which addresses the ORIGINAL elements), and continue the walk. A following `Index` / `ConstantIndex` over that pointer now emits `mir.ptr_offset` (the pointee is the element type, not an array), while array pointees keep the existing `mir.array_element_addr` path. This is sound for both mutable and shared borrows, so the shared-read value-copy fallback for this shape disappears as well. The 2-level assignment match in statement.rs gains a `(Deref, Index | ConstantIndex)` arm that obtains the element address from the same walker (now `pub(crate)`) and stores through it, covering both thin `&mut [T; N]` and fat `&mut [T]` bases. The new `slice_get_mut` example pins all six shapes (get_mut + map, get_mut + if let, indexed assignment through thin and fat pointers, `&mut a[i]`, and a struct-field write through a get_mut element) with full host-side readback verification. Fixes #58 Validation: - cargo test -p mir-importer -p mir-lower: all green - cargo clippy -p mir-importer --all-targets -- -D warnings: clean - cargo fmt --check (root) and cargo fmt --all -- --check (example) - scripts/smoketest.sh --compile-only --skip '^issue': 81/81 pass - Pre-fix backend reproduces both original errors on the new example
EthanAnro
pushed a commit
to EthanAnro/cuda-oxide
that referenced
this pull request
Jun 11, 2026
Reconcile two independent extensions of the place-address walker in mir-importer: - This branch (issue NVIDIA#138) taught the walker to continue through fat-pointer derefs for MirSliceType (tail borrows of slice-tailed unsized structs, deep projection-chain assignments, indexed element addresses), but punted on MirDisjointSliceType. - origin/main (PR NVIDIA#165, issue NVIDIA#58) taught the same walker to compute mutable element addresses through fat derefs for BOTH MirSliceType and MirDisjointSliceType, with a (Deref, Index) assignment arm in statement translation. Unified resolution, one mechanism with the union of capabilities: - Fat-pointee detection uses main's broader fat_elem_ty (slice AND disjoint slice), feeding this branch's continuation machinery (load pair, extract data pointer, tail-borrow slice construction, next-projection dispatch). DisjointSlice no longer punts mid-chain. - Index / ConstantIndex arms keep the emit_indexed_element_addr helper, with main's PointeeKind::Direct naming (array GEP vs plain ptr_offset off a slice data pointer). - statement.rs: main's (Deref, Index | ConstantIndex) arm and this branch's generic 3+ projection fallback now share one store_through_place_address helper (walk the chain mutably, store through the address; punts are loud errors, never value copies). Validated: mir-importer + mir-lower tests, clippy -D warnings, fmt, array_for_loop + slice_get_mut compile with stores through GEPs off the fat data pointer (no spilled copy), error_drop_glue still fails with the destructor diagnostic, compile-only smoketest 84/84.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Writes through
a.get_mut(i)on a&mut [f32; N], and direct(*fat)[i] = xassignments, now compile and hit the original memory.The assignment translator also gains the missing
(Deref, Index | ConstantIndex)arm, reusing the same walker, so read and write paths agree.Evidence
slice_get_mutcovers the issue's exactget_mutshape plus index-assignment variants across six kernels; executes on sm_120.Fixes #58