Rustup
Done with
```bash
git subtree push -P src/tools/clippy git@github.com:flip1995/rust-clippy rustup
```
from https://github.com/flip1995/rust/tree/clippyup
A rebase was required to get rid of empty merge commits, that somehow were not empty? 🤔
changelog: none
Currently it uses `for x in self`, which seems dubious within an
iterator method. Furthermore, `self.next()` is used in all the other
iterator methods.
The default implementations of several `Iterator` methods use `fold` or
`try_fold`, which works, but is overkill for slices and bloats the
amount of LLVM IR generated and consequently hurts compile times.
This commit adds the simple, obvious implementations for `for_each`,
`all`, `any`, `find`, `find_map`, and simplifies the existing
implementations for `position` and `rposition`. These changes reduce
compile times significantly on some benchmarks.
`DroplessArena` and `TypedArena` use an aggressive growth strategy: the
first chunk is 4 KiB, the second is 8 KiB, and it keeps on doubling
indefinitely. DHAT profiles show that sometimes this results in large
chunks (e.g. 16-128 MiB) that are barely filled. Although these don't
contribute to RSS, they clog up the DHAT profiles.
This commit changes things so that the doubling stops at 2 MiB. This is
large enough that chunk allocations are still rare (you might get 100s
instead of 10s of them) but avoids lots of unused space in the worst
case. It gives a slight speed-up to cycle counts in some cases.
For the given code paths, the amount of space used in the previous chunk
is irrelevant.
(This will almost never make a difference to behaviour, but it makes the
code clearer.)
Rollup of 5 pull requests
Successful merges:
- #71737 (Miri: run liballoc tests with threads)
- #71928 (Add strikethrough support to rustdoc)
- #72048 (Visit move out of `_0` when visiting `return`)
- #72096 (Make MIR typeck use `LocalDefId` and fix docs)
- #72128 (strings do not have to be valid UTF-8 any more)
Failed merges:
r? @ghost
The amortized case is much more common than the exact case, and it is
typically instantiated many times.
Also, we can put a chunk of the code into a function that isn't generic
over T, which reduces the amount of LLVM IR generated quite a lot,
improving compile times.
It's only used once, for `VecDeque`, and can easily be replaced by
something else. The commit changes `grow_if_necessary` to `grow` to
avoid some small regressions caused by changed inlining.
The commit also removes `Strategy::Double`, and streamlines the
remaining variants of `Strategy`.
It's a compile time win on some benchmarks because the many
instantations of `RawVec::grow` are a little smaller.
I also added test cases to make sure the optimization can fire on all of
these cases:
```rust
fn case_1(o: Option<u8>) -> Option<u8> {
match o {
Some(u) => Some(u),
None => None,
}
}
fn case2(r: Result<u8, i32>) -> Result<u8, i32> {
match r {
Ok(u) => Ok(u),
Err(i) => Err(i),
}
}
fn case3(r: Result<u8, i32>) -> Result<u8, i32> {
let u = r?;
Ok(u)
}
```
Without MIR inlining, this still does not completely optimize away the
`?` operator because the `Try::into_result()`, `From::from()` and
`Try::from_error()` calls still exist. This does move us a bit closer to
that goal though because:
- We can now run the pass on mir-opt-level=1
- We no longer depend on the copy propagation pass running which is
unlikely to stabilize anytime soon.