rust-lang / rust-lang/rust

select_nth_unstable (partition_at_index) has plenty of redundant bounds checks

Open
#144,326 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-optimization T-libs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I wouldn't expect any panics other than panic_on_ord_violation and input arguments check, which should get optimized out.

https://rust.godbolt.org/z/h5P6Er8zr

.LBB2_96:
        lea     rax, [rip + .Lanon.c0a2eb89440bc2e212dbf84361b066b5.10]
        mov     qword ptr [rsp + 24], rax
        mov     qword ptr [rsp + 32], 1
        mov     qword ptr [rsp + 40], 8
        xorps   xmm0, xmm0
        movups  xmmword ptr [rsp + 48], xmm0
        lea     rsi, [rip + .Lanon.c0a2eb89440bc2e212dbf84361b066b5.13]
        lea     rdi, [rsp + 24]
        call    qword ptr [rip + core::panicking::panic_fmt::h22107f1a113fdabe@GOTPCREL]
.LBB2_97:
        lea     rax, [rip + .Lanon.c0a2eb89440bc2e212dbf84361b066b5.10]
        mov     qword ptr [rsp + 24], rax
        mov     qword ptr [rsp + 32], 1
        mov     qword ptr [rsp + 40], 8
        xorps   xmm0, xmm0
        movups  xmmword ptr [rsp + 48], xmm0
        lea     rsi, [rip + .Lanon.c0a2eb89440bc2e212dbf84361b066b5.14]
        lea     rdi, [rsp + 24]
        call    qword ptr [rip + core::panicking::panic_fmt::h22107f1a113fdabe@GOTPCREL]
.LBB2_95:
        ud2
.LBB2_15:
        lea     rdx, [rip + .Lanon.c0a2eb89440bc2e212dbf84361b066b5.12]
        mov     rsi, r13
        call    qword ptr [rip + core::panicking::panic_bounds_check::hdaa6e5107cd75dd9@GOTPCREL]
.LBB2_24:
        lea     rdx, [rip + .Lanon.c0a2eb89440bc2e212dbf84361b066b5.11]
        mov     rsi, r13
        call    qword ptr [rip + core::panicking::panic_bounds_check::hdaa6e5107cd75dd9@GOTPCREL]

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Rust Compiler Explorer link and the select_nth_unstable/partition_at_index implementation named in the issue. Inspect the generated assembly and trace the indexed accesses that produce the reported bounds-check panics. Done means only panic_on_ord_violation and input-argument checks remain, with redundant bounds checks optimized out.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.