Commit Graph

220714 Commits

Author SHA1 Message Date
lcnr
0c13565ca6 Add a builtin FnPtr trait 2023-03-27 12:16:54 +00:00
bors
7a0600714a Auto merge of #109091 - Nilstrieb:match-on-attr, r=cjgillot
Cleanup `codegen_fn_attrs`

The `match` control flow construct has been stable since 1.0, we should use it here.

Sorry for the hard to review diff, I did try to at least split it into two commits. But looking at before-after side-by-side (instead of whatever github is doing) is probably the easiest way to make sure that I didn't forget about anything.

On top of #109088, you can wait for that
2023-03-27 05:01:19 +00:00
bors
1d5820784e Auto merge of #109643 - nikic:fix-mingw, r=pietroalbini
Limit to one link job on mingw builders

This is another attempt to work around
https://github.com/rust-lang/rust/issues/108227.

By limiting to one link job, we should be able to avoid file name clashes in mkstemp().
2023-03-26 22:00:17 +00:00
Nikita Popov
dd7db8b1df Limit to one job on mingw builders
This is another attempt to work around
https://github.com/rust-lang/rust/issues/108227.

By limiting to one link job, we should be able to avoid file name
clashes in mkstemp().
2023-03-26 23:52:59 +02:00
bors
db0cbc48d4 Auto merge of #109357 - saethlin:inline-as-deref, r=thomcc
Add #[inline] to as_deref

While working on https://github.com/rust-lang/rust/pull/109247 I found an `as_deref` call in the compiler that should have been inlined. This fixes the missing inlining (but doesn't address the perf issues I was chasing).

r? `@thomcc`
2023-03-26 18:32:17 +00:00
bors
89c2e3d3d7 Auto merge of #109626 - matthiaskrgr:rollup-k0y7bdd, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #109007 (rustdoc: skip `// some variants omitted` if enum is `#[non_exhaustive]`)
 - #109593 (Rustdoc Book refer to rustdoc::missing_doc_code_examples. Fixes #109592.)
 - #109595 (Improve "Auto-hide trait implementation documentation" GUI test)
 - #109619 (Still-further-specializable projections are ambiguous in new solver)
 - #109620 (Correct typo (`back_box` -> `black_box`))
 - #109621 (Refactor: `VariantIdx::from_u32(0)` -> `FIRST_VARIANT`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-03-26 12:05:38 +00:00
Matthias Krüger
4aa4ce6ee2
Rollup merge of #109621 - scottmcm:update-variantidx, r=compiler-errors
Refactor: `VariantIdx::from_u32(0)` -> `FIRST_VARIANT`

Since structs are always `VariantIdx(0)`, there's a bunch of files where the only reason they had `VariantIdx` or `vec::Idx` imported at all was to get the first variant.

So this uses a constant for that, and adds some doc-comments to `VariantIdx` while I'm there, since [it doesn't have any today](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_target/abi/struct.VariantIdx.html).
2023-03-26 08:39:28 +02:00
Matthias Krüger
776a8f4eca
Rollup merge of #109620 - eievui5:patch-1, r=compiler-errors
Correct typo (`back_box` -> `black_box`)
2023-03-26 08:39:28 +02:00
Matthias Krüger
705435fe01
Rollup merge of #109619 - compiler-errors:new-solver-still-further-specializable, r=BoxyUwU
Still-further-specializable projections are ambiguous in new solver

Fixes https://github.com/rust-lang/rust/pull/108896/files#r1148450781

r? ``@BoxyUwU`` (though feel free to re-roll)

---

This can be used to create an unsound transmute function with the new solver:

```rust
#![feature(specialization)]

trait Default {
   type Id;

   fn intu(&self) -> &Self::Id;
}

impl<T> Default for T {
   default type Id = T;

   fn intu(&self) -> &Self::Id {
        self
   }
}

fn transmute<T: Default<Id = U>, U: Copy>(t: T) -> U {
    *t.intu()
}

use std::num::NonZeroU8;
fn main() {
    let s = transmute::<u8, Option<NonZeroU8>>(0);
    assert_eq!(s, None);
}
```
2023-03-26 08:39:27 +02:00
Matthias Krüger
236178698a
Rollup merge of #109595 - GuillaumeGomez:improve-gui-test-auto-hide-trait, r=notriddle
Improve "Auto-hide trait implementation documentation" GUI test

Part of #66181.

I'll start working on the `include` command for `browser-ui-test` so we can greatly reduce the duplicated code between setting tests.

r? ``@notriddle``
2023-03-26 08:39:27 +02:00
Matthias Krüger
623c4c8881
Rollup merge of #109593 - coop-rs:missing_doc_code_examples, r=GuillaumeGomez
Rustdoc Book refer to rustdoc::missing_doc_code_examples. Fixes #109592.

Fixes #109592. But, please see a related question at #109592 (item `2.`).
2023-03-26 08:39:26 +02:00
Matthias Krüger
df25f15716
Rollup merge of #109007 - Ezrashaw:tweak-some-variants-omitted, r=notriddle,GuillaumeGomez
rustdoc: skip `// some variants omitted` if enum is `#[non_exhaustive]`

Fixes #108925

Never touched rustdoc before so probably not the best code.

cc `@dtolnay`
2023-03-26 08:39:25 +02:00
bors
2420bd34ba Auto merge of #106428 - saethlin:inline-diverging-functions, r=cjgillot
Permit the MIR inliner to inline diverging functions

This heuristic prevents inlining of `hint::unreachable_unchecked`, which in turn makes `Option/Result::unwrap_unchecked` a bad inlining candidate. I looked through the changes to `core`, `alloc`, `std`, and `hashbrown` by hand and they all seem reasonable. Let's see how this looks in perf...

---

Based on rustc-perf it looks like this regresses ctfe-stress, and the cachegrind diff indicates that this regression is in `InterpCx::statement`. I don't know how to do any deeper analysis because that function is _enormous_ in the try toolchain, which has no debuginfo in it. And a local build produces significantly different codegen for that function, even with LTO.
2023-03-26 05:55:32 +00:00
Ezra Shaw
e0ec9c0b9c
rustdoc: tweak some variants omitted
Don't display `// some variants omitted` if enum is marked
`#[non_exhaustive]`
2023-03-26 18:05:42 +13:00
Scott McMurray
0439d13176 Refactor: VariantIdx::from_u32(0) -> FIRST_VARIANT
Since structs are always `VariantIdx(0)`, there's a bunch of files where the only reason they had `VariantIdx` or `vec::Idx` imported at all was to get the first variant.

So this uses a constant for that, and adds some doc-comments to `VariantIdx` while I'm there, since it doesn't have any today.
2023-03-25 18:58:25 -07:00
bors
48ae1b335f Auto merge of #105096 - LegionMammal978:copied-allocators, r=Amanieu
Clarify that copied allocators must behave the same

Currently, the safety documentation for `Allocator` says that a cloned or moved allocator must behave the same as the original. However, it does not specify that a copied allocator must behave the same, and it's possible to construct an allocator that permits being moved or cloned, but sometimes produces a new allocator when copied.

<details>
<summary>Contrived example which results in a Miri error</summary>

```rust
#![feature(allocator_api, once_cell, strict_provenance)]
use std::{
    alloc::{AllocError, Allocator, Global, Layout},
    collections::HashMap,
    hint,
    marker::PhantomPinned,
    num::NonZeroUsize,
    pin::Pin,
    ptr::{addr_of, NonNull},
    sync::{LazyLock, Mutex},
};

mod source_allocator {
    use super::*;

    // `SourceAllocator` has 3 states:
    // - invalid value: is_cloned == false, source != self.addr()
    // - source value:  is_cloned == false, source == self.addr()
    // - cloned value:  is_cloned == true
    pub struct SourceAllocator {
        is_cloned: bool,
        source: usize,
        _pin: PhantomPinned,
    }

    impl SourceAllocator {
        // Returns a pinned source value (pointing to itself).
        pub fn new_source() -> Pin<Box<Self>> {
            let mut b = Box::new(Self {
                is_cloned: false,
                source: 0,
                _pin: PhantomPinned,
            });
            b.source = b.addr();
            Box::into_pin(b)
        }

        fn addr(&self) -> usize {
            addr_of!(*self).addr()
        }

        // Invalid values point to source 0.
        // Source values point to themselves.
        // Cloned values point to their corresponding source.
        fn source(&self) -> usize {
            if self.is_cloned || self.addr() == self.source {
                self.source
            } else {
                0
            }
        }
    }

    // Copying an invalid value produces an invalid value.
    // Copying a source value produces an invalid value.
    // Copying a cloned value produces a cloned value with the same source.
    impl Copy for SourceAllocator {}

    // Cloning an invalid value produces an invalid value.
    // Cloning a source value produces a cloned value with that source.
    // Cloning a cloned value produces a cloned value with the same source.
    impl Clone for SourceAllocator {
        fn clone(&self) -> Self {
            if self.is_cloned || self.addr() != self.source {
                *self
            } else {
                Self {
                    is_cloned: true,
                    source: self.source,
                    _pin: PhantomPinned,
                }
            }
        }
    }

    static SOURCE_MAP: LazyLock<Mutex<HashMap<NonZeroUsize, usize>>> =
        LazyLock::new(Default::default);

    // SAFETY: Wraps `Global`'s methods with additional tracking.
    // All invalid values share blocks with each other.
    // Each source value shares blocks with all cloned values pointing to it.
    // Cloning an allocator always produces a compatible allocator:
    // - Cloning an invalid value produces another invalid value.
    // - Cloning a source value produces a cloned value pointing to it.
    // - Cloning a cloned value produces another cloned value with the same source.
    // Moving an allocator always produces a compatible allocator:
    // - Invalid values remain invalid when moved.
    // - Source values cannot be moved, since they are always pinned to the heap.
    // - Cloned values keep the same source when moved.
    unsafe impl Allocator for SourceAllocator {
        fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
            let mut map = SOURCE_MAP.lock().unwrap();
            let block = Global.allocate(layout)?;
            let block_addr = block.cast::<u8>().addr();
            map.insert(block_addr, self.source());
            Ok(block)
        }

        unsafe fn deallocate(&self, block: NonNull<u8>, layout: Layout) {
            let mut map = SOURCE_MAP.lock().unwrap();
            let block_addr = block.addr();
            // SAFETY: `block` came from an allocator that shares blocks with this allocator.
            if map.remove(&block_addr) != Some(self.source()) {
                hint::unreachable_unchecked()
            }
            Global.deallocate(block, layout)
        }
    }
}
use source_allocator::SourceAllocator;

// SAFETY: `alloc1` and `alloc2` must share blocks.
unsafe fn test_same(alloc1: &SourceAllocator, alloc2: &SourceAllocator) {
    let ptr = alloc1.allocate(Layout:🆕:<i32>()).unwrap();
    alloc2.deallocate(ptr.cast(), Layout:🆕:<i32>());
}

fn main() {
    let orig = &*SourceAllocator::new_source();
    let orig_cloned1 = &orig.clone();
    let orig_cloned2 = &orig.clone();
    let copied = &{ *orig };
    let copied_cloned1 = &copied.clone();
    let copied_cloned2 = &copied.clone();
    unsafe {
        test_same(orig, orig_cloned1);
        test_same(orig_cloned1, orig_cloned2);
        test_same(copied, copied_cloned1);
        test_same(copied_cloned1, copied_cloned2);
        test_same(orig, copied); // error
    }
}
```
</details>

This could result in issues in the future for algorithms that specialize on `Copy` types. Right now, nothing in the standard library that depends on `Allocator + Clone` is susceptible to this issue, but I still think it would make sense to specify that copying an allocator is always as valid as cloning it.
2023-03-26 01:21:12 +00:00
Michael Goulet
3310f72db9 transmute test 2023-03-26 00:03:14 +00:00
Evie M
323551abb1
Correct typo (back_box -> black_box) 2023-03-25 19:57:46 -04:00
Michael Goulet
20679b1166 Still-further-specializable projections are ambiguous 2023-03-25 23:51:08 +00:00
Ben Kimock
b932751984 Ignore the unwrap_unchecked test on wasm32-unknown-unknown 2023-03-25 19:33:19 -04:00
bors
0c61c7a978 Auto merge of #109474 - nikic:llvm-16-again, r=cuviper
Upgrade to LLVM 16, again

Relative to the previous attempt in https://github.com/rust-lang/rust/pull/107224:
 * Update to GCC 8.5 on dist-x86_64-linux, to avoid std::optional ABI-incompatibility between libstdc++ 7 and 8.
 * Cherry-pick 96df79af02.
 * Cherry-pick 6fc670e5e3.

r? `@cuviper`
2023-03-25 19:55:10 +00:00
Ben Kimock
88e78aba82 Explain how we get to skip checking for cleanup blocks in the visitor 2023-03-25 13:58:49 -04:00
bors
2d429f3064 Auto merge of #109458 - Nilstrieb:smol-cute-little-bits, r=wesleywiser
Use `SmallVec` in bitsets

This doesn't increase their size and means that we don't have to heap allocate for small sets.
2023-03-25 17:06:43 +00:00
bors
96bd50dd47 Auto merge of #109581 - matthiaskrgr:rollup-e8fi2vi, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #109355 (Fix bad suggestion for clone/is_some in field init shorthand)
 - #109484 (Bugfix: avoid panic on invalid json output from libtest)
 - #109539 (Refactor `find_*_stability` functions)
 - #109542 (rustdoc: clean up `storage.js`)
 - #109545 (Deeply check well-formedness of return-position `impl Trait` in trait)
 - #109568 (miri: fix raw pointer dyn receivers)
 - #109570 (Add GUI test for "Auto-hide item methods' documentation" setting)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-03-25 14:34:13 +00:00
Guillaume Gomez
16bb7196a8 Improve "Auto-hide trait implementation documentation" GUI test 2023-03-25 15:28:18 +01:00
Peter Kehl
1491c6f311 Rustdoc Book refer to rustdoc::missing_doc_code_examples. Fixes #109592. 2023-03-25 06:19:52 -07:00
bors
b72e896268 Auto merge of #109100 - Zoxc:merge-query-try, r=cjgillot
Refactor `try_execute_query`

This merges `JobOwner::try_start` into `try_execute_query`, removing `TryGetJob` in the processes. 3 new functions are extracted from `try_execute_query`: `execute_job`, `cycle_error` and `wait_for_query`. This makes the control flow a bit clearer and improves performance.

Based on https://github.com/rust-lang/rust/pull/109046.

<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.7134s</td><td align="right">1.7061s</td><td align="right"> -0.43%</td></tr><tr><td>🟣 <b>hyper</b>:check</td><td align="right">0.2519s</td><td align="right">0.2510s</td><td align="right"> -0.35%</td></tr><tr><td>🟣 <b>regex</b>:check</td><td align="right">0.9517s</td><td align="right">0.9481s</td><td align="right"> -0.38%</td></tr><tr><td>🟣 <b>syn</b>:check</td><td align="right">1.5389s</td><td align="right">1.5338s</td><td align="right"> -0.33%</td></tr><tr><td>🟣 <b>syntex_syntax</b>:check</td><td align="right">5.9488s</td><td align="right">5.9258s</td><td align="right"> -0.39%</td></tr><tr><td>Total</td><td align="right">10.4048s</td><td align="right">10.3647s</td><td align="right"> -0.38%</td></tr><tr><td>Summary</td><td align="right">1.0000s</td><td align="right">0.9962s</td><td align="right"> -0.38%</td></tr></table>

r? `@cjgillot`
2023-03-25 12:04:46 +00:00
bors
e10eab5956 Auto merge of #109371 - Zoxc:verify-hash-opt, r=cjgillot
Optimize `incremental_verify_ich`

This optimizes `incremental_verify_ich` by operating on `SerializedDepNodeIndex`, saving 2 hashmap lookups. The panic paths are also changed to get a `TyCtxt` reference using TLS.
2023-03-25 09:22:15 +00:00
bors
9fa6b3c157 Auto merge of #99929 - the8472:default-iters, r=scottmcm
Implement Default for some alloc/core iterators

Add `Default` impls to the following collection iterators:

* slice::{Iter, IterMut}
* binary_heap::IntoIter
* btree::map::{Iter, IterMut, Keys, Values, Range, IntoIter, IntoKeys, IntoValues}
* btree::set::{Iter, IntoIter, Range}
* linked_list::IntoIter
* vec::IntoIter

and these adapters:

* adapters::{Chain, Cloned, Copied, Rev, Enumerate, Flatten, Fuse, Rev}

For iterators which are generic over allocators it only implements it for the global allocator because we can't conjure an allocator from nothing or would have to turn the allocator field into an `Option` just for this change.

These changes will be insta-stable.

ACP: https://github.com/rust-lang/libs-team/issues/77
2023-03-25 06:29:46 +00:00
bors
24a69af213 Auto merge of #109546 - saethlin:inline-into, r=scottmcm
Add #[inline] to the Into for From impl

I was skimming through the standard library MIR and I noticed a handful of very suspicious `Into::into` calls in `alloc`. ~Since this is a trivial wrapper function, `#[inline(always)]` seems appropriate.;~ `#[inline]` works too and is a lot less spooky.

r? `@thomcc`
2023-03-25 03:09:09 +00:00
Matthias Krüger
beac95a4ab
Rollup merge of #109570 - GuillaumeGomez:add-gui-test, r=notriddle
Add GUI test for "Auto-hide item methods' documentation" setting

Part of https://github.com/rust-lang/rust/issues/66181.

r? `@notriddle`
2023-03-25 03:37:13 +01:00
Matthias Krüger
31df7f1ecd
Rollup merge of #109568 - RalfJung:miri-raw-ptr-dyn, r=oli-obk
miri: fix raw pointer dyn receivers

r? `@oli-obk`
Fixes https://github.com/rust-lang/miri/issues/2786
2023-03-25 03:37:12 +01:00
Matthias Krüger
3b49ad3814
Rollup merge of #109545 - compiler-errors:rpitit-wf, r=eholk
Deeply check well-formedness of return-position `impl Trait` in trait

Walk the bounds of RPITITs to see if we find any more RPITITs 😸
2023-03-25 03:37:12 +01:00
Matthias Krüger
8c8305843b
Rollup merge of #109542 - notriddle:notriddle/storage-js, r=GuillaumeGomez
rustdoc: clean up `storage.js`
2023-03-25 03:37:11 +01:00
Matthias Krüger
15ea2276ff
Rollup merge of #109539 - cjgillot:find-stability, r=b-naber
Refactor `find_*_stability` functions

The idea is to split the monolithic function into the 3 cases: stability, const stability, and body stability.
2023-03-25 03:37:11 +01:00
Matthias Krüger
65220b5ba9
Rollup merge of #109484 - fortanix:raoul/bugfix_libtest_json_output, r=pietroalbini
Bugfix: avoid panic on invalid json output from libtest

#108659 introduces a custom test display implementation. It does so by using libtest to output json. The stdout is read and parsed; The code trims the line read and checks whether it starts with a `{` and ends with a `}`. If so, it concludes that it must be a json encoded `Message`. Unfortunately, this does not work in all cases:

- This assumes that tests running with `--nocapture` will never start and end lines with `{` and `}` characters
- Output is generated by issuing multiple `write_message` [statements](https://github.com/rust-lang/rust/blob/master/library/test/src/formatters/json.rs#L33-L60). Where only the last one issues a `\n`. This likely results in a race condition as we see multiple json outputs on the same line when running tests for the `x86_64-fortanix-unknown-sgx` target:
```
10:21:04      Running tests/run-time-detect.rs (build/x86_64-unknown-linux-gnu/stage1-std/x86_64-fortanix-unknown-sgx/release/deps/run_time_detect-8c66026bd4b1871a)
10:21:04
10:21:04 running 1 tests
10:21:04 test x86_all ... ok
10:21:04      Running tests/thread.rs (build/x86_64-unknown-linux-gnu/stage1-std/x86_64-fortanix-unknown-sgx/release/deps/thread-ed5456a7d80a6193)
10:21:04 thread 'main' panicked at 'failed to parse libtest json output; error: trailing characters at line 1 column 135, line: "{ \"type\": \"suite\", \"event\": \"ok\", \"passed\": 1, \"failed\": 0, \"ignored\": 0, \"measured\": 0, \"filtered_out\": 0, \"exec_time\": 0.000725911 }{ \"type\": \"suite\", \"event\": \"started\", \"test_count\": 1 }\n"', render_tests.rs:108:25
```

This PR implements a partial fix by being much more conservative of what it asserts is a valid json encoded `Message`. This prevents panics, but still does not resolve the race condition. A discussion is needed where this race condition comes from exactly and how it best can be avoided.

cc: `@jethrogb,` `@pietroalbini`
2023-03-25 03:37:10 +01:00
Matthias Krüger
f3d3f350cc
Rollup merge of #109355 - chenyukang:yukang/fix-108470, r=compiler-errors
Fix bad suggestion for clone/is_some in field init shorthand

Fixes #108470
2023-03-25 03:37:10 +01:00
John Kåre Alsaker
820e3a8d6a Pass tcx directly 2023-03-25 03:13:05 +01:00
John Kåre Alsaker
afe4c16b29 Split the if to release the lock earlier 2023-03-25 03:12:41 +01:00
John Kåre Alsaker
dfae9c993d Remove DebugArg 2023-03-25 02:59:54 +01:00
John Kåre Alsaker
8f294066b3 Optimize incremental_verify_ich 2023-03-25 02:59:53 +01:00
bors
d012d2f96e Auto merge of #109399 - petrochenkov:rendersort, r=GuillaumeGomez
rustdoc: Optimize impl sorting during rendering

This should fix the perf regression on [bitmaps-3.1.0](https://github.com/rust-lang/rustc-perf/tree/master/collector/compile-benchmarks/bitmaps-3.1.0) from https://github.com/rust-lang/rust/pull/107765.

The bitmaps crate has a lot of impls:
```rust
impl Bits for BitsImpl<1> { ... }
impl Bits for BitsImpl<2> { ... }
// ...
impl Bits for BitsImpl<1023> { ... }
impl Bits for BitsImpl<1024> { ... }
```
and the logic in `fn print_item` sorts them in natural order.

Before https://github.com/rust-lang/rust/pull/107765 the impls came in source order, which happened to be already sorted in the necessary way.
So the comparison function was called fewer times.

After https://github.com/rust-lang/rust/pull/107765 the impls came in "stable" order (based on def path hash).
So the comparison function was called more times to sort them.

The comparison function was terribly inefficient, so it caused a large perf regression.
This PR attempts to make it more efficient by using cached keys during sorting.
2023-03-24 23:41:53 +00:00
bors
8be3c2bda6 Auto merge of #107932 - petrochenkov:onlyexport, r=jyn514
rustdoc: Skip doc link resolution for non-exported items
2023-03-24 21:10:51 +00:00
Ben Kimock
badfb17d2f Add #[inline] to the Into for From impl 2023-03-24 15:06:31 -04:00
Camille GILLOT
3e9ea5da63 Adjust documentation. 2023-03-24 18:53:36 +00:00
bors
80a933042e Auto merge of #109566 - flip1995:clippyup, r=Manishearth
Update Clippy

r? `@Manishearth`

One day late, sorry 😐
2023-03-24 18:40:19 +00:00
Guillaume Gomez
9cb7d4ca39 Add GUI test for "Auto-hide item methods' documentation" setting 2023-03-24 16:57:55 +01:00
Ralf Jung
c2fddfd8e2 miri: fix raw pointer dyn receivers 2023-03-24 16:53:18 +01:00
bors
31d74fb24b Auto merge of #109220 - nikic:poison, r=cuviper
Use poison instead of undef

In cases where it is legal, we should prefer poison values over undef values.

This replaces undef with poison for aggregate construction and for uninhabited types. There are more places where we can likely use poison, but I wanted to stay conservative to start with.

In particular the aggregate case is important for newer LLVM versions, which are not able to handle an undef base value during early optimization due to poison-propagation concerns.

r? `@cuviper`
2023-03-24 15:39:40 +00:00
Philipp Krones
50475e8648
Merge commit 'd5e2a7aca55ed49fc943b7a07a8eba05ab5a0079' into clippyup 2023-03-24 14:26:19 +01:00