Commit Graph

217004 Commits

Author SHA1 Message Date
Vincenzo Palazzo
2bdc9a046a
fix: improve the suggestion on future not awaited
Considering the following code

```rust
fn foo() -> u8 {
    async fn async_fn() -> u8 {  22 }

    async_fn()
}

fn main() {}
```

the error generated before this commit from the compiler is

```
➜  rust git:(macros/async_fn_suggestion) ✗ rustc test.rs --edition 2021
error[E0308]: mismatched types
 --> test.rs:4:5
  |
1 | fn foo() -> u8 {
  |             -- expected `u8` because of return type
...
4 |     async_fn()
  |     ^^^^^^^^^^ expected `u8`, found opaque type
  |
  = note:     expected type `u8`
          found opaque type `impl Future<Output = u8>`
help: consider `await`ing on the `Future`
  |
4 |     async_fn().await
  |               ++++++

error: aborting due to previous error
```

In this case the error is nor perfect, and can confuse the user
that do not know that the opaque type is the future.

So this commit will propose (and conclude the work start in
https://github.com/rust-lang/rust/issues/80658)
to change the string `opaque type` to `future` when applicable
and also remove the Expected vs Received note by adding a more
specific one regarding the async function that return a future type.

So the new error emitted by the compiler is

```
error[E0308]: mismatched types
 --> test.rs:4:5
  |
1 | fn foo() -> u8 {
  |             -- expected `u8` because of return type
...
4 |     async_fn()
  |     ^^^^^^^^^^ expected `u8`, found future
  |
note: calling an async function returns a future
 --> test.rs:4:5
  |
4 |     async_fn()
  |     ^^^^^^^^^^
help: consider `await`ing on the `Future`
  |
4 |     async_fn().await
  |               ++++++

error: aborting due to previous error
```

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2023-02-13 16:23:23 +01:00
bors
2d91939bb7 Auto merge of #107634 - scottmcm:array-drain, r=thomcc
Improve the `array::map` codegen

The `map` method on arrays [is documented as sometimes performing poorly](https://doc.rust-lang.org/std/primitive.array.html#note-on-performance-and-stack-usage), and after [a question on URLO](https://users.rust-lang.org/t/try-trait-residual-o-trait-and-try-collect-into-array/88510?u=scottmcm) prompted me to take another look at the core [`try_collect_into_array`](7c46fb2111/library/core/src/array/mod.rs (L865-L912)) function, I had some ideas that ended up working better than I'd expected.

There's three main ideas in here, split over three commits:
1. Don't use `array::IntoIter` when we can avoid it, since that seems to not get SRoA'd, meaning that every step writes things like loop counters into the stack unnecessarily
2. Don't return arrays in `Result`s unnecessarily, as that doesn't seem to optimize away even with `unwrap_unchecked` (perhaps because it needs to get moved into a new LLVM type to account for the discriminant)
3. Don't distract LLVM with all the `Option` dances when we know for sure we have enough items (like in `map` and `zip`).  This one's a larger commit as to do it I ended up adding a new `pub(crate)` trait, but hopefully those changes are still straight-forward.

(No libs-api changes; everything should be completely implementation-detail-internal.)

It's still not completely fixed -- I think it needs pcwalton's `memcpy` optimizations still (#103830) to get further -- but this seems to go much better than before.  And the remaining `memcpy`s are just `transmute`-equivalent (`[T; N] -> ManuallyDrop<[T; N]>` and `[MaybeUninit<T>; N] -> [T; N]`), so hopefully those will be easier to remove with LLVM16 than the previous subobject copies 🤞

r? `@thomcc`

As a simple example, this test
```rust
pub fn long_integer_map(x: [u32; 64]) -> [u32; 64] {
    x.map(|x| 13 * x + 7)
}
```
On nightly <https://rust.godbolt.org/z/xK7548TGj> takes `sub rsp, 808`
```llvm
start:
  %array.i.i.i.i = alloca [64 x i32], align 4
  %_3.sroa.5.i.i.i = alloca [65 x i32], align 4
  %_5.i = alloca %"core::iter::adapters::map::Map<core::array::iter::IntoIter<u32, 64>, [closure@/app/example.rs:2:11: 2:14]>", align 8
```
(and yes, that's a 6**5**-element array `alloca` despite 6**4**-element input and output)

But with this PR it's only `sub rsp, 520`
```llvm
start:
  %array.i.i.i.i.i.i = alloca [64 x i32], align 4
  %array1.i.i.i = alloca %"core::mem::manually_drop::ManuallyDrop<[u32; 64]>", align 4
```

Similarly, the loop it emits on nightly is scalar-only and horrifying
```nasm
.LBB0_1:
        mov     esi, 64
        mov     edi, 0
        cmp     rdx, 64
        je      .LBB0_3
        lea     rsi, [rdx + 1]
        mov     qword ptr [rsp + 784], rsi
        mov     r8d, dword ptr [rsp + 4*rdx + 528]
        mov     edi, 1
        lea     edx, [r8 + 2*r8]
        lea     r8d, [r8 + 4*rdx]
        add     r8d, 7
.LBB0_3:
        test    edi, edi
        je      .LBB0_11
        mov     dword ptr [rsp + 4*rcx + 272], r8d
        cmp     rsi, 64
        jne     .LBB0_6
        xor     r8d, r8d
        mov     edx, 64
        test    r8d, r8d
        jne     .LBB0_8
        jmp     .LBB0_11
.LBB0_6:
        lea     rdx, [rsi + 1]
        mov     qword ptr [rsp + 784], rdx
        mov     edi, dword ptr [rsp + 4*rsi + 528]
        mov     r8d, 1
        lea     esi, [rdi + 2*rdi]
        lea     edi, [rdi + 4*rsi]
        add     edi, 7
        test    r8d, r8d
        je      .LBB0_11
.LBB0_8:
        mov     dword ptr [rsp + 4*rcx + 276], edi
        add     rcx, 2
        cmp     rcx, 64
        jne     .LBB0_1
```

whereas with this PR it's unrolled and vectorized
```nasm
	vpmulld	ymm1, ymm0, ymmword ptr [rsp + 64]
	vpaddd	ymm1, ymm1, ymm2
	vmovdqu	ymmword ptr [rsp + 328], ymm1
	vpmulld	ymm1, ymm0, ymmword ptr [rsp + 96]
	vpaddd	ymm1, ymm1, ymm2
	vmovdqu	ymmword ptr [rsp + 360], ymm1
```
(though sadly still stack-to-stack)
2023-02-13 10:18:48 +00:00
bors
20081880ad Auto merge of #107980 - Dylan-DPC:rollup-u4b19bl, r=Dylan-DPC
Rollup of 7 pull requests

Successful merges:

 - #107654 (reword descriptions of the deprecated int modules)
 - #107915 (Add `array::map` benchmarks)
 - #107961 (Avoid copy-pasting the `ilog` panic string in a bunch of places)
 - #107962 (Add a doc note about why `Chain` is not `ExactSizeIterator`)
 - #107966 (Update browser-ui-test version to 0.14.3)
 - #107970 (Hermit: Remove floor symbol)
 - #107973 (Fix unintentional UB in SIMD tests)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-02-13 07:07:33 +00:00
Dylan DPC
4bf58083ac
Rollup merge of #107973 - saethlin:fix-simd-test-ub, r=workingjubilee
Fix unintentional UB in SIMD tests

r? `@workingjubilee`
2023-02-13 11:12:52 +05:30
Dylan DPC
55f36ed0a4
Rollup merge of #107970 - hermitcore:hermit-rm-floor, r=thomcc
Hermit: Remove floor symbol

This symbol should be provided by Hermit.

It was introduced in 2019 (https://github.com/rust-lang/rust/pull/65167). Since 2020, Hermit provides these math functions on its own (https://github.com/hermitcore/rusty-hermit/pull/37). I think moving this to Hermit was merely an oversight.

Related:
* https://github.com/hermitcore/libhermit-rs/pull/654
* https://github.com/hermitcore/rusty-hermit/pull/406

CC: `@stlankes`
2023-02-13 11:12:51 +05:30
Dylan DPC
b5aeba8706
Rollup merge of #107966 - GuillaumeGomez:update-browser-ui-test, r=notriddle
Update browser-ui-test version to 0.14.3

It brings a few fixes to the `NEAR` checks. The PR for it in [here](https://github.com/GuillaumeGomez/browser-UI-test/pull/436).

r? `@notriddle`
2023-02-13 11:12:51 +05:30
Dylan DPC
f7caaa573e
Rollup merge of #107962 - scottmcm:why-not-exact, r=Mark-Simulacrum
Add a doc note about why `Chain` is not `ExactSizeIterator`

Inspired by <https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/Why.20isn't.20Chain.3CA.2C.20B.3E.20an.20ExactSizeIterator.3F/near/327395874>.
2023-02-13 11:12:50 +05:30
Dylan DPC
2ec6aebb41
Rollup merge of #107961 - scottmcm:unify-ilog-panics, r=Mark-Simulacrum
Avoid copy-pasting the `ilog` panic string in a bunch of places

I also ended up changing the implementations to `if let` because it doesn't work to
```rust
self.checked_ilog2().unwrap_or_else(panic_for_nonpositive_argument)
```
due to the `!`.  But as a bonus that meant I could remove the `rustc_allow_const_fn_unstable` too.
2023-02-13 11:12:50 +05:30
Dylan DPC
c0d1e324d5
Rollup merge of #107915 - JulianKnodt:array_benches, r=Mark-Simulacrum
Add `array::map` benchmarks

Since there were no previous benchmarks for `array::map`, and it is known to have mediocre/poor performance, add some simple benchmarks. These benchmarks vary the length of the array and size of each item.
2023-02-13 11:12:49 +05:30
Dylan DPC
47358298f6
Rollup merge of #107654 - pitaj:reword-integral-modules, r=thomcc
reword descriptions of the deprecated int modules

Based on recommendation by `@est31` here: https://github.com/rust-lang/rust/pull/107587#issuecomment-1416131590

This is meant to make it more clear, when looking at the `std` or `core` docs, that these are deprecated modules - not deprecated integer types (a common misunderstanding).

Before:
![image](https://user-images.githubusercontent.com/803701/216733011-fabc22e1-4e77-4a47-96e3-a765ac4690b6.png)

After:
![image](https://user-images.githubusercontent.com/803701/216733660-02071ced-883d-4ab5-8c0a-d28547d1d5db.png)
2023-02-13 11:12:49 +05:30
bors
96834f0231 Auto merge of #107191 - Voultapher:reverse-timsort-scan-direction, r=thomcc
Reverse Timsort scan direction

Another PR in the series of stable sort improvements. Best reviewed by looking at the individual commits.

The main perf gain here is for fully ascending (sorted) or reversed inputs for cheap to compare types such as `u64`, these see a ~1.5x speedup.

![timsort_evo2_hot_u64_10k](https://user-images.githubusercontent.com/6864584/213913351-cfdf452f-a37c-4bc6-a811-d10c60e66eca.png)

![timsort_evo2_hot_string_10k](https://user-images.githubusercontent.com/6864584/213913354-d9cc395a-2b48-4f54-b687-09174b9e35ce.png)

Types such as string with indirect pre-fetching see only minor changes. Further speedups are planned in future PRs so, I wouldn't spend too much time for benchmarks here.
2023-02-13 04:06:04 +00:00
Ben Kimock
9c4696b940 Fix unintentional UB in SIMD tests 2023-02-12 20:18:48 -05:00
bors
7740f9a571 Auto merge of #107869 - nnethercote:reduce-interning, r=compiler-errors
Reduce interning

r? `@compiler-errors`
2023-02-13 00:35:26 +00:00
Martin Kröning
913a566c22 Hermit: Remove floor symbol
This symbol should be provided by Hermit.
2023-02-12 23:37:58 +01:00
Nicholas Nethercote
e261665b2c Avoid interning empty tuples. 2023-02-13 09:32:51 +11:00
Nicholas Nethercote
7a72560154 Reduce direct mk_ty usage.
We use more specific `mk_*` functions in most places, might as well use
them as much as possible.
2023-02-13 09:32:48 +11:00
Nicholas Nethercote
6248bbbf26 Pre-intern some commonly used type variables.
This requires some rearrangement of plumbing, such as adding
`mk_fresh_{,int_,float_}ty` and removing `mk_ty_infer`.
2023-02-13 09:25:36 +11:00
bors
59083c57d4 Auto merge of #107967 - matthiaskrgr:rollup-7wvbla5, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #107748 (refer to new home)
 - #107842 (Patch `build/rustfmt/lib/*.so` for NixOS)
 - #107930 (Improve JS function itemTypeFromName code a bit)
 - #107934 (rustdoc: account for intra-doc links in `<meta name="description">`)
 - #107943 (Document `PointerLike`)
 - #107954 (avoid mixing accesses of ptrs derived from a mutable ref and parent ptrs)
 - #107955 (fix UB in ancient test)
 - #107964 (rustdoc: use tighter line height in h1 and h2)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-02-12 21:32:23 +00:00
Matthias Krüger
1d4397ba70
Rollup merge of #107964 - notriddle:notriddle/title-line-height, r=GuillaumeGomez
rustdoc: use tighter line height in h1 and h2

This keeps the line height for body text the same, as required by WCAG, but for headers, it makes sense to have wrapped lines be a bit tighter packed.

## Before

![image](https://user-images.githubusercontent.com/1593513/218332683-88a02467-7811-4e6b-81f8-67dded691465.png)

## After

![image](https://user-images.githubusercontent.com/1593513/218332698-a1b2a265-0658-4306-8473-b835f663172d.png)
2023-02-12 22:29:50 +01:00
Matthias Krüger
f81cb97cb2
Rollup merge of #107955 - RalfJung:ancient-ub, r=jyn514
fix UB in ancient test

This seems to go back all the way to the [original version of this test](b9aa9def85/src/test/run-pass/regions-mock-trans.rs) from ten years ago... ``@nikomatsakis`` trip down memory lane? ;)

Clearly deallocation is a form of mutation so doing it to a (pointer derived from a) shared reference cannot be legal. Let's use mutable references instead.
2023-02-12 22:29:49 +01:00
Matthias Krüger
454ae9fb8b
Rollup merge of #107954 - RalfJung:tree-borrows-fix, r=m-ou-se
avoid mixing accesses of ptrs derived from a mutable ref and parent ptrs

``@Vanille-N`` is working on a successor for Stacked Borrows. It will mostly accept strictly more code than Stacked Borrows did, with one exception: the following pattern no longer works.
```rust
let mut root = 6u8;
let mref = &mut root;
let ptr = mref as *mut u8;
*ptr = 0; // Write
assert_eq!(root, 0); // Parent Read
*ptr = 0; // Attempted Write
```
This worked in Stacked Borrows kind of by accident: when doing the "parent read", under SB we Disable `mref`, but the raw ptrs derived from it remain usable. The fact that we can still use the "children" of a reference that is no longer usable is quite nasty and leads to some undesirable effects (in particular it is the major blocker for resolving https://github.com/rust-lang/unsafe-code-guidelines/issues/257). So in Tree Borrows we no longer do that; instead, reading from `root` makes `mref` and all its children read-only.

Due to other improvements in Tree Borrows, the entire Miri test suite still passes with this new behavior, and even the entire libcore and liballoc test suite, except for these 2 cases this PR fixes. Both of these involve code where the programmer wrote `&mut` but then used pointers derived from that reference in ways that alias with the parent pointer, which arguably is violating uniqueness. They are fixed by properly using raw pointers throughout.
2023-02-12 22:29:49 +01:00
Matthias Krüger
4b91b673b7
Rollup merge of #107943 - compiler-errors:document-pointer-like, r=jyn514
Document `PointerLike`

I forgot to document this, and even though it's currently more of an implementation detail, the old doc was kinda embarrassing 😅
2023-02-12 22:29:48 +01:00
Matthias Krüger
9b503325b4
Rollup merge of #107934 - notriddle:notriddle/intra-doc-link-meta-description, r=camelid,GuillaumeGomez
rustdoc: account for intra-doc links in `<meta name="description">`

Similar to #86451, but for the SEO descriptions instead of the search descriptions.
2023-02-12 22:29:48 +01:00
Matthias Krüger
76c47fb904
Rollup merge of #107930 - GuillaumeGomez:js-func-improvement, r=notriddle
Improve JS function itemTypeFromName code a bit

Very small code improvement replacing a `for` loop with `findIndex` method.

r? ````@notriddle````
2023-02-12 22:29:48 +01:00
Matthias Krüger
ca99d51b6d
Rollup merge of #107842 - fee1-dead-contrib:patch_rustfmt_nixos, r=Mark-Simulacrum
Patch `build/rustfmt/lib/*.so` for NixOS

fixes #107676.
2023-02-12 22:29:47 +01:00
Matthias Krüger
d29aba19d0
Rollup merge of #107748 - tshepang:renamed, r=cuviper
refer to new home

The module has since been made its own crate...
see 2d75a339ca.
2023-02-12 22:29:47 +01:00
Guillaume Gomez
5fe1046668 Update browser-ui-test version to 0.14.3 2023-02-12 22:02:39 +01:00
Michael Howell
b0df355f80 rustdoc: use tighter line height in h1 and h2 2023-02-12 12:30:57 -07:00
Scott McMurray
79d2430e99 Add a doc note about why Chain is not ExactSizeIterator 2023-02-12 10:37:25 -08:00
bors
5b8f284536 Auto merge of #107643 - Zoxc:single-cache, r=cjgillot
Create a single value cache for the () query key

Since queries using `()` as the key can only store a single value, specialize for that case.

This looks like a minor performance improvement:
<table><tr><td rowspan="2">Benchmark</td><td colspan="1"><b>Before</b></th><td colspan="2"><b>After</b></th></tr><tr><td align="right">Time</td><td align="right">Time</td><td align="right">%</th></tr><tr><td>🟣 <b>clap</b>:check</td><td align="right">1.8477s</td><td align="right">1.8415s</td><td align="right"> -0.33%</td></tr><tr><td>🟣 <b>hyper</b>:check</td><td align="right">0.2666s</td><td align="right">0.2655s</td><td align="right"> -0.40%</td></tr><tr><td>🟣 <b>syntex_syntax</b>:check</td><td align="right">6.3943s</td><td align="right">6.3686s</td><td align="right"> -0.40%</td></tr><tr><td>🟣 <b>syn</b>:check</td><td align="right">1.6413s</td><td align="right">1.6345s</td><td align="right"> -0.42%</td></tr><tr><td>🟣 <b>regex</b>:check</td><td align="right">1.0337s</td><td align="right">1.0313s</td><td align="right"> -0.24%</td></tr><tr><td>Total</td><td align="right">11.1836s</td><td align="right">11.1414s</td><td align="right"> -0.38%</td></tr><tr><td>Summary</td><td align="right">1.0000s</td><td align="right">0.9964s</td><td align="right"> -0.36%</td></tr></table>
2023-02-12 17:20:33 +00:00
Ralf Jung
0ea0c90d58 fix UB in ancient test 2023-02-12 16:30:37 +01:00
bors
00cf19a75a Auto merge of #107933 - petrochenkov:rmdlc, r=GuillaumeGomez
rustdoc: Remove cache for preprocessed markdown links

It's quite possible that it's no longer useful after https://github.com/rust-lang/rust/pull/94857 is merged.
2023-02-12 14:28:43 +00:00
Ralf Jung
c3a2e7a809 avoid mixing accesses of ptrs derived from a mutable ref and parent ptrs 2023-02-12 15:16:27 +01:00
bors
adb4bfd25d Auto merge of #105671 - lukas-code:depreciate-char, r=scottmcm
Use associated items of `char` instead of freestanding items in `core::char`

The associated functions and constants on `char` have been stable since 1.52 and the freestanding items have soft-deprecated since 1.62 (https://github.com/rust-lang/rust/pull/95566). This PR ~~marks them as "deprecated in future", similar to the integer and floating point modules (`core::{i32, f32}` etc)~~ replaces all uses of `core::char::*` with `char::*` to prepare for future deprecation of `core::char::*`.
2023-02-12 11:09:06 +00:00
bors
51cb5614dd Auto merge of #105601 - BelovDV:change-rlib-with-not-stable, r=petrochenkov
Enable new rlib in non stable cases

If bundled static library uses cfg (unstable) or whole-archive (wasn't supported) bundled libs are packed even without packed_bundled_libs.

r? `@petrochenkov`
2023-02-12 07:15:27 +00:00
bors
b7089e0dd3 Auto merge of #107894 - Voultapher:improve-heapsort-fallback, r=scottmcm
Speedup heapsort by 1.5x by making it branchless

`slice::sort_unstable` will fall back to heapsort if it repeatedly fails to find a good pivot. By making the core child update code branchless it is much faster. On Zen3 sorting 10k `u64` and forcing the sort to pick heapsort, results in:

455us -> 278us
2023-02-12 03:30:10 +00:00
Michael Goulet
cca82fd997 Document PointerLike 2023-02-12 01:23:02 +00:00
bors
d094016128 Auto merge of #106677 - tbu-:pr_less_doc_hidden_pub, r=scottmcm
Remove a couple of `#[doc(hidden)] pub fn` and their `#[feature]` gates
2023-02-11 23:57:05 +00:00
Michael Howell
72b3f46b43 rustdoc: account for intra-doc links in <meta name="description"> 2023-02-11 16:10:28 -07:00
John Kåre Alsaker
80d265240b Create a single value cache for the () query key 2023-02-11 23:38:01 +01:00
bors
585f3eef26 Auto merge of #107851 - cjgillot:sroa-const, r=oli-obk
Put deaggregated statements after original constant.

Fixes https://github.com/rust-lang/rust/issues/107818
2023-02-11 20:59:18 +00:00
Vadim Petrochenkov
0e61d3ab3f rustdoc: Remove cache for preprocessed markdown links 2023-02-11 22:27:02 +04:00
bors
2b3f260e74 Auto merge of #107928 - matthiaskrgr:rollup-qnn380r, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #107657 (Add only modified subcommand for compiletest)
 - #107864 (rustdoc: clean up `write!` calls with less stuttering)
 - #107873 (Emit JSON output for the building of bootstrap itself)
 - #107895 (remove redundant clones)
 - #107897 (Reexported macros docs)
 - #107909 (rustdoc: remove redundant `if s.is_empty()` from `find_testable_code`)
 - #107912 (rustdoc: Don't resolve link to field on different variant)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-02-11 18:01:17 +00:00
Guillaume Gomez
d505c5abe4 Improve JS function itemTypeFromName code a bit 2023-02-11 18:03:21 +01:00
Matthias Krüger
c8614a7479
Rollup merge of #107912 - clubby789:doc-bad-enum-field, r=camelid,GuillaumeGomez
rustdoc: Don't resolve link to field on different variant

Fix #107903

This also gives a more specific diagnostic when the enum has any fields
2023-02-11 17:18:45 +01:00
Matthias Krüger
f95f68e619
Rollup merge of #107909 - notriddle:notriddle/register-header-empty-cond, r=camelid
rustdoc: remove redundant `if s.is_empty()` from `find_testable_code`
2023-02-11 17:18:45 +01:00
Matthias Krüger
1305119a3f
Rollup merge of #107897 - GuillaumeGomez:reexported-macros-docs, r=notriddle
Reexported macros docs

Part of #59368 (doesn't fix it, only improve the current situation a bit).

Macros were not correctly handled in reexports and the reexport attributes were not merged with the item either. This PR fixes both.

r? `@notriddle`
2023-02-11 17:18:44 +01:00
Matthias Krüger
4b7b5698a4
Rollup merge of #107895 - matthiaskrgr:cl, r=compiler-errors
remove redundant clones
2023-02-11 17:18:44 +01:00
Matthias Krüger
420e756c8a
Rollup merge of #107873 - zephaniahong:issue-107832-fix, r=albertlarsan68
Emit JSON output for the building of bootstrap itself

Fixes #107832 .
Main changes are from line 792 onwards. Other changes are due to the flake8 formatter. Let me know if I should not use the formatter.
2023-02-11 17:18:43 +01:00
Matthias Krüger
240d5e0f68
Rollup merge of #107864 - notriddle:notriddle/rustdoc-write-stutter, r=GuillaumeGomez
rustdoc: clean up `write!` calls with less stuttering
2023-02-11 17:18:43 +01:00