Uh oh!
There was an error while loading. Please reload this page.
Hint the maximum length permitted by invariant of slices - #77023
Conversation
rust-highfive
commented
Sep 21, 2020
(rust_highfive has picked a reviewer for you, use r? to override) |
Could you merge the I guess the attr doesn't support auto-merging multiple invocations of it. |
bors
commented
Sep 22, 2020
☔ The latest upstream changes (presumably #77039) made this pull request unmergeable. Please resolve the merge conflicts. Note that reviewers usually do not review pull requests until merge conflicts are resolved! Once you resolve the conflicts, you should change the labels applied by bors to indicate that your PR is ready for review. Post this as a comment to change the labels: |
0553d9a to
e203e4dCompare197g
commented
Sep 22, 2020
@rustbot modify labels: +S-waiting-on-review -S-waiting-on-author |
Uh oh!
There was an error while loading. Please reload this page.
e203e4d to
658722eCompareUh oh!
There was an error while loading. Please reload this page.
197g
commented
Sep 22, 2020
That should do all the implementation work. Would you mind to start a perf run to see if this adversly influences inlining somewhere? |
Mark-Simulacrum
commented
Sep 24, 2020
@bors try @rust-timer queue This seems like it's going to complicate the codegen for len() -- adding an assume or similar construct -- which might have a pretty high compile time cost even if not so high a runtime cost. |
rust-timer
commented
Sep 24, 2020
Awaiting bors try build completion |
bors
commented
Sep 24, 2020
⌛ Trying commit b885434b728adc2bcce88480ed755fb1e4ecb837 with merge 8612477075acc90b2716af836a922f8965189225... |
rust-log-analyzer
commented
Sep 24, 2020
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
bors
commented
Sep 24, 2020
💔 Test failed - checks-actions |
b885434 to
482f306Compare@rustbot modify labels: +S-waiting-on-review -S-waiting-on-author Looks like the feature |
Mark-Simulacrum
commented
Sep 24, 2020
@bors try |
bors
commented
Sep 24, 2020
⌛ Trying commit 482f306df072d2b20507b5577c780b8dfa477edc with merge 9c1568be513095701cd7735f2d9a1b5f1fbac104... |
bors
commented
Sep 25, 2020
☀️ Try build successful - checks-actions, checks-azure |
rust-timer
commented
Sep 25, 2020
Queued 9c1568be513095701cd7735f2d9a1b5f1fbac104 with parent e599b53, future comparison URL. |
Mark-Simulacrum
commented
Oct 4, 2020
I don't know what to do about CI failure either. I presume this is a limitation of the beta compiler? Can you try putting Please also keep commits squashed as you edit (both this change and further ones if they become necessary); this PR has a small line diff which should not need more than one commit. |
c9a0d01 to
517feb3Compare197g
commented
Oct 4, 2020
That seems to have done it 🎉 I've squashed the largest part of the history but kept this at two commits, one introducing the test and the other the actual change. I hope that's okay. @rustbot modify labels: +S-waiting-on-review -S-waiting-on-author |
Mark-Simulacrum
commented
Oct 4, 2020
I would prefer to have a single commit, makes it easier to find the code introduced alongside the test. r=me with it squashed. |
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 rust-lang#67186
517feb3 to
e44784bCompare197g
commented
Oct 4, 2020
Okay, that's fine for me. @rustbot modify labels: +S-waiting-on-review -S-waiting-on-author |
Mark-Simulacrum
commented
Oct 4, 2020
@bors r+ rollup=never |
bors
commented
Oct 4, 2020
📌 Commit e44784b has been approved by |
bors
commented
Oct 4, 2020
bors
commented
Oct 4, 2020
☀️ Test successful - checks-actions, checks-azure |
tesuji
commented
Oct 5, 2020
Note that this PR caused a slight regression on max-rss; https://perf.rust-lang.org/compare.html?start=4ccf5f731bb71db3470002d6baf5ab4792b821d9&end=beb5ae474d2835962ebdf7416bd1c9ad864fe101&stat=max-rss I guess LLVM hasn't changed much since: #54995 (comment) |
ecstatic-morse
commented
Oct 6, 2020
Final perf results are in. This seemed to cause a slowdown across the board with the exception of some synthetic benchmarks. Except for the aforementioned stress test, check builds are not improved or a bit slower. The case in the |
ecstatic-morse
commented
Oct 6, 2020
@lzutao We have an automated script for detecting these kinds of regressions and run it weekly as part of perf-triage. That usually happens on a Monday. Also, there's no |
rust-lang#77023 (comment) suggests that the original PR introduced a significant perf regression. This reverts commit e44784b / rust-lang#77023.
Revert "Assume slice len is bounded by allocation size" rust-lang#77023 (comment) suggests that the original PR introduced a significant perf regression. This reverts commit e44784b / rust-lang#77023. cc `@HeroicKatora`
One of the safety invariants of references, and in particular of references to slices, is that they may not cover more than
isize::MAXbytes. The unsafefrom_raw_partsconstructors of slices explicitly requires the caller to guarantee this fact. Violating it would also be UB with regards to the semantics of generated llvm code.This effectively bounds the length of a (non-ZST) slice from above by a compile time constant. But when the length is loaded from a function argument it appears llvm is not aware of this requirement. The additional value range assertions allow some further elision of code branches, including overflow checks, especially in the presence of artithmetic on the indices.
This may have a performance impact, adding more code to a common method but allowing more optimization. I'm not quite sure, is the Rust side of const-prop strong enough to elide the irrelevant match branches?
Fixes: #67186