Different codegen between index and iterator
Open
Nobody has claimed this yet.
A-codegen
needs-triage
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
They should produce the same codegen.
https://godbolt.org/z/W5hKTedd3
#[inline(never)]
pub fn f_index(data: &mut [u32]) {
for i in 0..data.len() {
data[i] += 1;
}
}
#[inline(never)]
pub fn f_iter(data: &mut [u32]) {
for v in data.iter_mut() {
*v += 1;
}
}
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 reproducing the comparison in the Godbolt link using the two functions, f_index and f_iter, and inspect their generated code. Trace the relevant Rust compiler codegen behavior to determine why indexed and iterator loops differ. Done means both examples produce equivalent codegen, with a regression test covering the behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100