`isqrt` treated as a `black_box`
Open
Nobody has claimed this yet.
C-optimization
I-slow
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
#[inline(never)]
pub const fn f(n: u8) {
assert!(n >= 4);
assert!(2 <= n.isqrt());
}
[!note]
I've tried:
- removing
const- replacing
u8byusize- replacing
4by9and2by3Outcome was the same
I expected to see this happen: 2nd assertion non-existent in assembly.
Instead, this happened:
# ... (snip)
.LBB0_4:
leaq .L__unnamed_4(%rip), %rdi
leaq .L__unnamed_5(%rip), %rdx
movl $32, %esi
callq *core::panicking::panic@GOTPCREL(%rip)
# ...
.L__unnamed_4:
.ascii "assertion failed: 2 <= n.isqrt()"
# ...
Meta
rustc --version --verbose:
1.84.0-nightly (2024-11-06 8549802939cd01111c46)
No Backtrace
@rustbot label: +I-slow, -C-bug
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 example in the linked Rust Playground with the reported nightly compiler and inspect the release assembly. Compare the handling of the const isqrt call with the surrounding assertions and compiler evaluation or optimization behavior. Done means the second assertion is eliminated when its condition is provably true, with appropriate regression coverage.
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
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100