Repository navigation
fix(mir-importer): load DisjointSlice through &self before extracting len - #392
Merged
nihalpasham merged 5 commits intoJul 23, 2026
Merged
Conversation
SomeB1oody
force-pushed
the
fix/disjoint-slice-len-through-ref
branch
from
July 20, 2026 22:00
6b9a032 to
508a390
Compare
…ting `len` Fixes NVIDIA#343 Problem: `DisjointSlice::len` is intercepted by the mir-importer as an intrinsic (`emit_len`). Because `len(&self)` receives the slice behind a reference, the translated operand is a thin `mir.ptr<mir.disjoint_slice<T>>`, not the fat `(ptr, len)` value. `emit_len` fed that pointer straight into `mir.extract_field`, which only accepts the fat value, so device codegen died in dialect verification It only happens when inline is disabled. The default release pipeline inlines `len()` into the kernel Fix: Add `resolve_disjoint_slice_value`, which parses `DisjointSlice` to the fat `(ptr, len)` value. A pointer operand carries the fat pointee type to load. A fat value passes through unchanged. Add `crates/rustc-codegen-cuda/examples/disjoint_slice_len` for regression test. It runs with inline disabled. Signed-off-by: SomeB1oody <[email protected]>
Keep the repair at the len interceptor boundary: require exactly the fully monomorphized &DisjointSlice receiver shape, emit one typed load, and reject direct, double-pointer, and ordinary-slice near misses. Leave the unrelated get_thread_local path and private values helper unchanged. Strengthen the GPU regression with a non-block-multiple length, refresh its lockfile against current main, and add exact operation-shape tests. Signed-off-by: nihalp <[email protected]>
Append the forced no-inline flag after inherited plain or encoded Cargo flags, then require the generated LLVM to load the DisjointSlice receiver before extracting its length. This prevents conflicting environment flags from turning the regression into a false pass. Signed-off-by: nihalp <[email protected]>
nihalpasham
force-pushed
the
fix/disjoint-slice-len-through-ref
branch
from
July 22, 2026 08:10
508a390 to
bd1d68e
Compare
Restrict the no-inline regression assertion to the write_len kernel and require one non-empty load/extract SSA def-use pair. Unrelated DisjointSlice helpers elsewhere in the module can no longer make the gate pass. Signed-off-by: nihalp <[email protected]>
Treat CARGO_ENCODED_RUSTFLAGS presence, rather than non-emptiness, as Cargo's selected flag source. An explicitly empty encoded value now receives the forced no-inline flag instead of shadowing the plain RUSTFLAGS update. Signed-off-by: nihalp <[email protected]>
Collaborator
|
Thanks for the PR. Loading I layered four maintainer commits on top:
Validated against current main: 805 importer tests, the example on an RTX 5090 (257 elements, deliberately not a block-size multiple), and the shape gate confirming the single load-then-extract sequence. Closes #343. |
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.
Summary
Fixes #343.
DisjointSlice::len()inside a kernel crashed device codegen withMirExtractFieldOp operand must be tuple, slice, struct, array, or scalar (newtype).DisjointSlice::lenis intercepted by the mir-importer as an intrinsic (emit_len). Becauselen(&self)receives the slice behind a reference, the translated operand is a thinmir.ptr<mir.disjoint_slice<T>>, not the fat(ptr, len)value.emit_lenfed that pointer straight intomir.extract_field, which only accepts the fat value, so device codegen died in dialect verification. The bug only happens when MIR inliner makes the call intact (len()is#[inline]and normally inlined into the kernel).Changes
mir-importer/…/intrinsics/indexing.rs: addresolve_disjoint_slice_value, which parsesDisjointSliceto the fat(ptr, len)value. A pointer operand carries the fat pointee type to load. A fat value passes through unchanged. Use it in bothemit_lenandemit_get_thread_local. An unexpected operand type reports aTypeError.mir-importer/…/values.rs: make the existinginsert_athelperpub(crate)so the new helper can reuse it.crates/rustc-codegen-cuda/examples/disjoint_slice_len: every in-bounds thread writeslen() + is_empty() as u32to its slot. The host asserts all 256 elements equal 256 (compilation check and correctness check).scripts/smoketest.sh: addNOINLINE_MIR_EXAMPLESlist pinsRUSTFLAGS=-Zinline-mir=nofordisjoint_slice_len.Testing
On an RTX 5090, CUDA 13, pinned nightly-2026-04-03, error in #343 is reproduced under
RUSTFLAGS="-Zinline-mir=no". Same command compiles and runs after the fix.cargo oxide run <example>passescargo test --workspacepassesChecklist
git commit -s)