]> git.lizzy.rs Git - rust.git/commit
Assume slice len is bounded by allocation size
authorAndreas Molzer <andreas.molzer@gmx.de>
Sun, 20 Sep 2020 15:22:17 +0000 (17:22 +0200)
committerAndreas Molzer <andreas.molzer@gmx.de>
Sun, 4 Oct 2020 18:43:36 +0000 (20:43 +0200)
commite44784b8750016a695361c990024750e037d8f9f
tree60652ccb46cce808024badc56173593400be44a4
parentd92d28e523bf056ab4eb752510ec52fe4f1c6311
Assume slice len is bounded by allocation size

Uses assume to check the length against a constant upper bound. The
inlined result then informs the optimizer of the sound value range.

This was tried with unreachable_unchecked before which introduces a
branch. This has the advantage of not being executed in sound code but
complicates basic blocks. It resulted in ~2% increased compile time in
some worst cases.

Add a codegen test for the assumption, testing the issue from #67186
library/core/src/lib.rs
library/core/src/slice/mod.rs
src/test/codegen/len-is-bounded.rs [new file with mode: 0644]