Skip to content

fix(#219): remove dead/wrong get_mut and get_unchecked_mut arms from DisjointSlice dispatch - #244

Merged
nihalpasham merged 2 commits into
mainfrom
fix/issue-219-dead-dispatch
Jun 18, 2026
Merged

nihalpasham merged 2 commits into
mainfrom
fix/issue-219-dead-dispatch

Conversation

@nihalpasham

Copy link
Copy Markdown
Collaborator

What

Closes #219.

The DisjointSlice method dispatch in terminator/mod.rs included
get_mut and get_unchecked_mut as candidates to route to
emit_get_thread_local. Both of these are bugs:

  1. Dead code. Both methods are #[inline] in cuda-device; rustc
    inlines them before the translator sees them. The arms were
    unreachable in practice.
  2. Wrong return type. emit_get_thread_local returns a raw
    *mut T pointer, but get_mut and get_unchecked_mut return
    Option<&mut T>. Any call that did reach this path would produce
    a type mismatch.

Fix

Remove "get_mut" | "get_unchecked_mut" from the match. get_thread_local
and len are the only methods that actually need translation-time dispatch.
A comment explains why the two inlined methods are intentionally absent.

Test plan

  • cargo oxide run vecadd (no regression in baseline kernel)
  • cargo test -p mir-importer
  • smoketest passes

…ice dispatch

`get_mut` and `get_unchecked_mut` are marked `#[inline]` in cuda-device
and are always inlined by rustc before MIR reaches the translator, so
the dispatch arms for them were effectively unreachable.

Worse, routing them to `emit_get_thread_local` was wrong: that helper
returns a raw `*mut T` pointer, but both methods return `Option<&mut T>`,
so any path that did reach this code would produce a type mismatch.

Remove both methods from the match; `get_thread_local` and `len` remain
as the only routed DisjointSlice methods.
@nihalpasham nihalpasham added bug Something isn't working codegen Device code-generation pipeline (Rust MIR to IR to PTX) labels Jun 18, 2026
@nihalpasham
nihalpasham merged commit a18befa into main Jun 18, 2026
24 checks passed
@nihalpasham
nihalpasham deleted the fix/issue-219-dead-dispatch branch June 19, 2026 11:30
meefs pushed a commit to meefs/cuda-oxide that referenced this pull request Sep 30, 2026
DivHint::from_ptr narrowed the device address to i32 before taking
its lowest set bit. An address whose low 32 bits are exactly
0x8000_0000 (2 GiB mod 4 GiB) narrows to i32::MIN, whose lowest set
bit does not fit in a positive i32 — the divisor came out NEGATIVE,
and the entry generator's div > 1 guard silently dropped the
assume_div_by for a pointer that is in fact 16-byte aligned. A missed
optimization plus a spurious extra cache specialization, never a
soundness issue: the guard fails conservative.

from_ptr now computes trailing zeros on the u64 directly (zero keeps
meaning maximally aligned). The sibling latent case in the i32 helper,
val = i32::MIN, is pinned to a positive power of two. Regression
tests cover the exact failing bit pattern, realistic high-bit
addresses, unaffected neighbors, and the negative-value paths.

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

bug Something isn't working codegen Device code-generation pipeline (Rust MIR to IR to PTX)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DisjointSlice::{get_mut, get_unchecked_mut, get_thread_local} intrinsic dispatch is effectively dead and fails verification when it actually fires

1 participant