Codegen depends on let-variable ordering for unclear reasons
Open
Nobody has claimed this yet.
A-codegen
A-LLVM
A-panic
C-optimization
I-heavy
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
https://godbolt.org/z/Wx1rvE6vq
use std::borrow::Cow;
pub struct Error {
message: Cow<'static, str>,
cause: Option<Box<[u8]>>,
}
#[no_mangle]
pub fn declear_before(v: u64) -> Error {
let s = format!("{v}");
let mut e = Error {
message: Cow::Borrowed(""),
cause: None,
};
e.message = s.into();
e
}
Declear s before Error produces better codegen than declear after.
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
Reproduce the two declaration-order variants from the linked Godbolt example and compare their generated code. Trace the compiler codegen path responsible for the difference; done means the ordering dependence is explained and, if confirmed unintended, covered by a regression test.
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
- Needs clarification
- Newbie friendliness
- 35/100