Emit `dereferenceable` assumptions for slices
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Rust currently emits dereferenceable attributes/metadata for pointers to Sized types. The number of bytes in dereferenceable attributes/metadata must be a constant, so cannot be used for pointers to dynamically sized types like [T], str. But assume operand bundles can be non-constants. So for pointers to DSTs, Rust should emit appropriate assumes.
Currently LLVM does not make use of variable-sized dereferenceable assumptions, but that may be changing soon, so it would be good if Rust could exploit this once it is added.
fn ptr_to_slice_u8(xs: &[u8]) {}
fn ptr_to_slice_u16(xs: &[u16]) {}
define void @ptr_to_slice_u8(ptr noalias nocapture noundef nonnull readonly align 1 %xs.0, i64 noundef %xs.1) unnamed_addr #0 {
call void @llvm.assume(i1 true) [ "dereferenceable"(ptr %xs.0, i64 %xs.1) ]
ret void
}
define void @ptr_to_slice_u16(ptr noalias nocapture noundef nonnull readonly align 2 %xs.0, i64 noundef %xs.1) unnamed_addr #0 {
%len_bytes = mul nsw nuw i64 %xs.1, 2
call void @llvm.assume(i1 true) [ "dereferenceable"(ptr %xs.0, i64 %len_bytes) ]
ret void
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing how Rust emits existing dereferenceable attributes and metadata for pointers to Sized types, then inspect the compiler's LLVM assume operand-bundle support. Verify behavior using slice references such as &[u8] and &[u16]. Done means dynamically sized slice pointers receive assumptions with byte lengths derived from their metadata, as shown in the issue's LLVM examples.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100