Repository navigation
mir-importer: support pointer distance intrinsics - #206
Merged
nihalpasham merged 2 commits intoJun 16, 2026
Merged
Conversation
Collaborator
|
Lowering looks right and it checks out on GPU ([6, -6, 24, 24], the negative slot exercises the signed path). Layered one thing on top:
Same types.rs insertion point as #212, so one of the two will want a quick rebase at merge. Otherwise good to go. |
nihalpasham
force-pushed
the
upstream-ptr-offset-unsigned
branch
from
June 16, 2026 09:49
4368f60 to
316cb67
Compare
5 tasks done
meefs
pushed a commit
to meefs/cuda-oxide
that referenced
this pull request
Sep 30, 2026
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.
Closes #205.
Problem
Rust raw pointer distance methods lower to compiler intrinsics such as
ptr_offset_fromandptr_offset_from_unsigned. cuda-oxide did not handle those intrinsics, so device code usingoffset_from,offset_from_unsigned, or their byte-oriented wrappers failed during MIR import.The compiler rule is that pointer distance is an address difference divided by the pointee size, with signed and unsigned result types preserved.
Fix
Add shared lowering for
core/std::intrinsics::{ptr_offset_from, ptr_offset_from_unsigned}.The lowering:
this - other;isizefor the signed intrinsic andusizefor the unsigned intrinsic.The importer now errors explicitly when the pointer operand type cannot be identified, when layout lookup fails, or when the pointee is zero-sized.
Diligence
The signed and unsigned intrinsic paths share one helper so the address-difference rule cannot drift. The helper uses rustc layout data for pointee size rather than deriving size from surface syntax or falling back to
1.The regression covers stable Rust pointer methods instead of calling compiler intrinsics directly, so it exercises the user-visible API shape. It includes both element-distance and byte-distance wrappers.
Tests
Added
crates/rustc-codegen-cuda/examples/ptr_offset_fromwith a standaloneCargo.tomlandCargo.lock.The example computes four distances on device:
offset_from_unsigned;offset_from;byte_offset_from;byte_offset_from_unsigned.The host asserts exact results for a
u32slice withlo = 3andhi = 9:[6, -6, 24, 24].The regression fails on
upstream/mainwithout the lowering and passes on this branch.Validation