Commit Graph

10619 Commits

Author SHA1 Message Date
Matthias Krüger 041f6668b5
Rollup merge of #108540 - WaffleLapkin:atomic_thingy_from_thingy_pointer, r=m-ou-se
Add `Atomic*::from_ptr`

This PR adds functions in the following form to all atomic types:
```rust
impl AtomicT {
    pub const unsafe fn from_ptr<'a>(ptr: *mut T) -> &'a AtomicT;
}
```
r? `@m-ou-se` (we've talked about it before)

I'm not sure about docs & safety requirements, I'd appreciate some feedback on them.
2023-03-03 20:45:00 +01:00
Léo Lanteri Thauvin bfe5189904 Revert "Stabilize `#![feature(target_feature_11)]`"
This reverts commit b379d216ee.
2023-03-02 13:41:17 +01:00
Maybe Waffle a2baba09a2 Fill-in tracking issue for `feature("atomic_from_ptr")` 2023-03-02 12:00:26 +00:00
bors 864b6258fc Auto merge of #106673 - flba-eb:add_qnx_nto_stdlib, r=workingjubilee
Add support for QNX Neutrino to standard library

This change:

- adds standard library support for QNX Neutrino (7.1).
- upgrades `libc` to version `0.2.139` which supports QNX Neutrino

`@gh-tr`

⚠️ Backtraces on QNX require https://github.com/rust-lang/backtrace-rs/pull/507 which is not yet merged! (But everything else works without these changes) ⚠️

Tested mainly with a x86_64 virtual machine (see qnx-nto.md) and partially with an aarch64 hardware (some tests fail due to constrained resources).
2023-03-02 02:41:42 +00:00
bors 0b4ba4cf0e Auto merge of #108483 - scottmcm:unify-bytewise-eq-traits, r=the8472
Merge two different equality specialization traits in `core`

Arrays and slices each had their own version of this, without a matching set of `impl`s.

Merge them into one (still-`pub(crate)`) `cmp::BytewiseEq` trait, so we can stop doing all these things twice.

And that means that the `[T]::eq` → `memcmp` specialization picks up a bunch of types where that previously only worked for arrays, so examples like <https://rust.godbolt.org/z/KjsG8MGGT> will use it now instead of emitting loops.

r? the8472
2023-03-01 23:34:37 +00:00
Scott McMurray 44eec1d9b0 Merge two different equality specialization traits in `core` 2023-03-01 14:42:06 -08:00
Dylan DPC 093a53f134
Rollup merge of #108462 - pommicket:fix-vecdeque-zst-overflow, r=Amanieu
Fix `VecDeque::append` capacity overflow for ZSTs

Fixes #108454.
2023-03-01 23:40:20 +05:30
bors 5423745db8 Auto merge of #105871 - llogiq:option-as-slice, r=scottmcm
Add `Option::as_`(`mut_`)`slice`

This adds the following functions:

* `Option<T>::as_slice(&self) -> &[T]`
* `Option<T>::as_mut_slice(&mut self) -> &[T]`

The `as_slice` and `as_mut_slice_mut` functions benefit from an optimization that makes them completely branch-free. ~~Unfortunately, this optimization is not available on by-value Options, therefore the `into_slice` implementations use the plain `match` + `slice::from_ref` approach.~~

Note that the optimization's soundness hinges on the fact that either the niche optimization makes the offset of the `Some(_)` contents zero or the mempory layout of `Option<T>` is equal to that of `Option<MaybeUninit<T>>`.

The idea has been discussed on [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Option.3A.3Aas_slice). Notably the idea for the `as_slice_mut` and `into_slice´ methods came from `@cuviper` and `@Sp00ph` hardened the optimization against niche-optimized Options.

The [rust playground](https://play.rust-lang.org/?version=nightly&mode=release&edition=2021&gist=74f8e4239a19f454c183aaf7b4a969e0) shows that the generated assembly of the optimized method is basically only a copy while the naive method generates code containing a `test dx, dx` on x86_64.

---

EDIT from reviewer: ACP is https://github.com/rust-lang/libs-team/issues/150
2023-03-01 12:32:57 +00:00
bors 64165aac68 Auto merge of #108476 - saethlin:remove-library-rustc-box, r=thomcc
Remove or document uses of #[rustc_box] in library

r? `@thomcc`

Only one of these uses is tested for in the rustc-perf benchmark suite. The impact there on compile time is somewhat dramatic, but I am inclined to make this change as a simplification to the library and wait for people to complain if it explodes their compilation time. I think in the absence of data or reports from users about what code paths really matter, if we are optimizing for compilation time, it's hard to argue against using `#[rustc_box]` everywhere we currently call `Box::new`.
2023-03-01 09:13:23 +00:00
Florian Bartels a510715749
Update library/std/src/os/nto/mod.rs
Co-authored-by: Jubilee <46493976+workingjubilee@users.noreply.github.com>
2023-03-01 06:42:40 +01:00
Matthias Krüger 3abc41a45c
Rollup merge of #108558 - RalfJung:core-tests, r=thomcc
add missing feature in core/tests

https://github.com/rust-lang/rust/pull/104265 introduced the `ip_in_core` feature. For some reason core tests seem to still build without that feature -- no idea how that is possible. Might be related to https://github.com/rust-lang/rust/issues/15702? I was under the impression that `pub use` with different stability doesn't actually work. That's why `intrinsics::transmute` is stable, for example.

Either way, core tests fail to build in miri-test-libstd, and adding the feature fixes that.

r? ```@thomcc```
2023-03-01 01:20:26 +01:00
Matthias Krüger 24551850a9
Rollup merge of #108531 - Coca162:rustdoc-repeat-const-array, r=thomcc
rustdoc: Show that repeated expression arrays can be made with constant values

The [rust reference](https://doc.rust-lang.org/reference/expressions/array-expr.html) currently says that repeated values for arrays can be constant or `Copy`
> repeat operand is [Copy](https://doc.rust-lang.org/reference/special-types-and-traits.html#copy) or that it must be a [path](https://doc.rust-lang.org/reference/expressions/path-expr.html) to a constant item

This updates the rust documentation on primitive arrays to reflect what the rust reference says (and also compiler suggestions if you do not use a `const` item)
2023-03-01 01:20:23 +01:00
Andre Bogus 41da875fae Add `Option::as_slice`(`_mut`)
This adds the following functions:

* `Option<T>::as_slice(&self) -> &[T]`
* `Option<T>::as_slice_mut(&mut self) -> &[T]`

The `as_slice` and `as_slice_mut` functions benefit from an
optimization that makes them completely branch-free.

Note that the optimization's soundness hinges on the fact that either
the niche optimization makes the offset of the `Some(_)` contents zero
or the mempory layout of `Option<T>` is equal to that of
`Option<MaybeUninit<T>>`.
2023-03-01 00:05:31 +01:00
Florian Bartels cef9d4cbc1
Retry to spawn/fork up to 3 times when it failed because of an interruption 2023-02-28 15:59:53 +01:00
Florian Bartels 3ce2cd059f
Add QNX Neutrino support to libstd
Co-authored-by: gh-tr <troach@qnx.com>
2023-02-28 15:59:47 +01:00
bors 31f858d9a5 Auto merge of #107987 - EFanZh:inline-poll-methods, r=Mark-Simulacrum
Inline `Poll` methods

With `opt-level="z"`, the `Poll::map*` methods are sometimes not inlined (see <https://godbolt.org/z/ca5ajKTEK>). This PR adds `#[inline]` to these methods. I have a project that can benefit from this change, but do we want to enable this behavior universally?

Fixes #101080.
2023-02-28 12:32:04 +00:00
Ralf Jung 229aef1f7d add missing feature in core/tests 2023-02-28 10:07:57 +01:00
bors fd1f1fa0d1 Auto merge of #106774 - Nugine:master, r=Amanieu
Stabilize cmpxchg16b_target_feature

Tracking issue for target features
+ #44839

stdarch issue
+ https://github.com/rust-lang/stdarch/issues/827

stdarch PR
+ https://github.com/rust-lang/stdarch/pull/1358

reference PR
+ https://github.com/rust-lang/reference/pull/1331

It's my first time contributing to rust-lang/rust. Please tell me if I missed something.
2023-02-28 04:12:34 +00:00
Ben Kimock 5448123a11 Remove or justify use of #[rustc_box] 2023-02-27 20:54:55 -05:00
bors b583ede652 Auto merge of #99767 - LeSeulArtichaut:stable-target-feature-11, r=estebank
Stabilize `#![feature(target_feature_11)]`

## Stabilization report

### Summary

Allows for safe functions to be marked with `#[target_feature]` attributes.

Functions marked with `#[target_feature]` are generally considered as unsafe functions: they are unsafe to call, cannot be assigned to safe function pointers, and don't implement the `Fn*` traits.

However, calling them from other `#[target_feature]` functions with a superset of features is safe.

```rust
// Demonstration function
#[target_feature(enable = "avx2")]
fn avx2() {}

fn foo() {
    // Calling `avx2` here is unsafe, as we must ensure
    // that AVX is available first.
    unsafe {
        avx2();
    }
}

#[target_feature(enable = "avx2")]
fn bar() {
    // Calling `avx2` here is safe.
    avx2();
}
```

### Test cases

Tests for this feature can be found in [`src/test/ui/rfcs/rfc-2396-target_feature-11/`](b67ba9ba20/src/test/ui/rfcs/rfc-2396-target_feature-11/).

### Edge cases

- https://github.com/rust-lang/rust/issues/73631

Closures defined inside functions marked with `#[target_feature]` inherit the target features of their parent function. They can still be assigned to safe function pointers and implement the appropriate `Fn*` traits.

```rust
#[target_feature(enable = "avx2")]
fn qux() {
    let my_closure = || avx2(); // this call to `avx2` is safe
    let f: fn() = my_closure;
}
```

This means that in order to call a function with `#[target_feature]`, you must show that the target-feature is available while the function executes *and* for as long as whatever may escape from that function lives.

### Documentation

- Reference: https://github.com/rust-lang/reference/pull/1181

---
cc tracking issue #69098
r? `@ghost`
2023-02-28 01:14:56 +00:00
Maybe Waffle 4a2c555904 Add `Atomic*::from_ptr` 2023-02-27 19:05:19 +00:00
Matthias Krüger 3fe4023370
Rollup merge of #107110 - strega-nil:mbtwc-wctmb, r=ChrisDenton
[stdio][windows] Use MBTWC and WCTMB

`MultiByteToWideChar` and `WideCharToMultiByte` are extremely well optimized, and therefore should probably be used when we know we can (specifically in the Windows stdio stuff).

Fixes #107092
2023-02-27 18:48:48 +01:00
Matthias Krüger cf04603dca
Rollup merge of #104265 - faern:move-ipaddr-to-core, r=joshtriplett
Move IpAddr, SocketAddr and V4+V6 related types to `core`

Implements RFC https://github.com/rust-lang/rfcs/pull/2832. The RFC has completed FCP with disposition merge, but is not yet merged.

Moves IP types to `core` as specified in the RFC.

The full list of moved types is: `IpAddr`, `Ipv4Addr`, `Ipv6Addr`, `SocketAddr`, `SocketAddrV4`, `SocketAddrV6`, `Ipv6MulticastScope` and `AddrParseError`.

Doing this move was one of the main driving arguments behind #78802.
2023-02-27 18:48:47 +01:00
Coca162 22b65fc275
Clarify that Copy is a trait in array docs 2023-02-27 15:16:39 +00:00
Coca162 dc9732620d
Update docs to show [expr; N] can repeat const expr 2023-02-27 13:51:10 +00:00
Josh Triplett 1291216ac9 Add tracking issue 2023-02-26 13:50:10 +01:00
Linus Färnstrand 6cb34492a6 Move IpAddr and SocketAddr to core 2023-02-26 13:50:08 +01:00
Matthias Krüger 9c27fc7d34
Rollup merge of #108484 - Nilstrieb:˂DiagnosticItem˂FromFn˃ as From˂˂LangItemFromFn˃˃˃꞉꞉from, r=cjgillot
Remove `from` lang item

It was probably a leftover from the old `?` desugaring but anyways, it's unused now except for clippy, which can just use a diagnostics item.
2023-02-26 12:05:01 +01:00
Matthias Krüger be23b326dc
Rollup merge of #108475 - Sp00ph:fix_shrink_to, r=thomcc
Fix `VecDeque::shrink_to` and add tests.

Fixes #108453.

Also adds both a specific test with the code from #108453 and an exhaustive test that checks all possible head positions, lengths and target capacities for deques with capacity 16.

cc `@trinity-1686a` `@scottmcm`
2023-02-26 12:05:00 +01:00
Matthias Krüger 3d2319f1d6
Rollup merge of #108299 - scottmcm:literal-bits, r=Nilstrieb
Require `literal`s for some `(u)int_impl!` parameters

The point of these is to be seen *lexically* in the docs, so they should always be passed as the correct literal, not as an expression.

(Otherwise we could just compute `Min`/`Max` from `BITS`, for example.)

r? Nilstrieb
2023-02-26 12:04:57 +01:00
Nilstrieb 312020ef6a Remove `from_fn` lang item
It was probably a leftover from the old `?` desugaring but anyways, it's
unused now except for clippy, which can just use a diagnostics item.
2023-02-26 09:15:54 +00:00
Markus Everling 4a4f43e4e9 Disambiguate comments 2023-02-26 03:13:56 +01:00
Markus Everling 9e22516877 Fix `VecDeque::shrink_to` and add tests.
This adds both a test specific to #108453 as well as an exhaustive test
that goes through all possible combinations of head index, length and target capacity
for a deque with capacity 16.
2023-02-26 03:13:44 +01:00
Matthias Krüger 4ab1c74b77
Rollup merge of #108432 - klensy:test-deps, r=Mark-Simulacrum
test: drop unused deps

Looks unused. Anyway, tests should catch any breakage.
2023-02-26 00:46:26 +01:00
Matthias Krüger fa10a21bd2
Rollup merge of #107890 - obeis:mapping-to-unit, r=cjgillot
Lint against `Iterator::map` receiving a callable that returns `()`

Close #106991
2023-02-26 00:46:25 +01:00
bors 34e6673a04 Auto merge of #107405 - hermitcore:bsd, r=bjorn3
add support of RustyHermit's BSD socket layer

RustyHermit is a tier 3 platform and publishes a new kernel interface. The new version supports a common BSD socket layer. By supporting this interface, the implementation of `std` can be harmonized to other operating systems. In `sys_common/mod.rs` we remove only a special case for RustyHermit. All changes are done in the RustyHermit specific directories.

To realize this socket layer, the handling of file descriptors is also harmonized to other operating systems.
2023-02-25 19:43:00 +00:00
Nicole Mazzuca 7f25580512 [stdio][windows] Use MBTWC and WCTMB 2023-02-25 11:15:23 -08:00
pommicket 12f959ba39 Add test for VecDeque::append ZST capacity overflow 2023-02-25 13:50:56 -05:00
bors 31448badfd Auto merge of #108450 - matthiaskrgr:rollup-rqvfgu3, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #108354 (Update `fuchsia-test-runner.py` and docs)
 - #108404 (support `x fmt` for sub and outside of rust directories)
 - #108407 (docs: use intra-doc links for `Vec::get(_mut)`)
 - #108410 (rustdoc: avoid including `<li>` tags in item table short desc)
 - #108412 (Fix GUI test navigation bug)
 - #108433 (Wrap missing provider message correctly)
 - #108434 (Migrate `rustc_hir_analysis` to session diagnostic [Part One])

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-02-25 16:48:04 +00:00
pommicket 379b18bb0a Use checked_add in VecDeque::append for ZSTs to avoid overflow 2023-02-25 11:05:21 -05:00
Matthias Krüger 7c562ee5a6
Rollup merge of #108407 - notriddle:notriddle/vec-get-mut, r=thomcc
docs: use intra-doc links for `Vec::get(_mut)`

Now that #63351 is fixed, there's no reason not to.

CC #75672
2023-02-25 11:31:33 +01:00
bors 26c98689f2 Auto merge of #108233 - ChrisDenton:move-std-tests, r=thomcc
Move some std tests from `tests/ui-fulldeps` into `library/std`

This allows them to be tested normally along with other `./x test std` tests. Moving `rename_directory` is simple enough but `create_dir_all_bare` needed to be an std integration test.

Additionally, some tests that I couldn't move atm have instead been placed in an `std` subdirectory. These tests include ones that do fun things with processes or that intentionally abort the test process.

r? libs
2023-02-25 10:26:57 +00:00
bors 6ffabf3c8f Auto merge of #107638 - zhangyunhao116:pdqsort-rand, r=cuviper
Optimize break patterns

Use `wyrand` instead of calling `XORSHIFT` 2 times in break patterns for the 64-bit platform. The new PRNG is 2x faster than the previous one.

Bench result(via https://gist.github.com/zhangyunhao116/11ef41a150f5c23bb47d86255fbeba89):
```
old                     time:   [1.3258 ns 1.3262 ns 1.3266 ns]
                        change: [+0.5901% +0.6731% +0.7791%] (p = 0.00 < 0.05)
                        Change within noise threshold.
Found 13 outliers among 100 measurements (13.00%)
  7 (7.00%) high mild
  6 (6.00%) high severe

new                     time:   [657.65 ps 657.89 ps 658.18 ps]
                        change: [-1.6910% -1.6110% -1.5256%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 6 outliers among 100 measurements (6.00%)
  2 (2.00%) high mild
  4 (4.00%) high severe
```
2023-02-25 03:01:40 +00:00
klensy c3749ddf4c test: drop unused deps 2023-02-24 20:45:00 +03:00
Stefan Lankes af8ee641a8 avoid the usage of libc during the creation of documentation 2023-02-24 15:30:14 +01:00
Stefan Lankes 90162a78a9 remove code duplications 2023-02-24 15:30:14 +01:00
Stefan Lankes b5fb4f3d9b move IO traits to std/src/os/hermit
By moving the IO traits, the RustyHermit support is harmonized to
of other operating systems.
2023-02-24 15:30:14 +01:00
Stefan Lankes 7143379a52 add support of RustyHermit's BSD socket layer
RustHermit publishs a new kernel interface and supports
a common BSD socket layer. By supporting this interface,
the implementation can be harmonized to other operating systems.

To realize this socket layer, the handling of file descriptors
is also harmonized to other operating systems.
2023-02-24 15:30:14 +01:00
Dylan DPC 353827a044
Rollup merge of #108391 - sunfishcode:sunfishcode/is-terminal-file-length, r=ChrisDenton
Fix `is_terminal`'s handling of long paths on Windows.

As reported in sunfishcode/is-terminal#18, there are situations where `GetFileInformationByHandleEx` can write a file name length that is longer than the provided buffer. To avoid deferencing memory past the end of the buffer, use a bounds-checked function to form a slice to the buffer and handle the out-of-bounds case.

This ports the fix from sunfishcode/is-terminal#19 to std's `is_terminal` implementation.
2023-02-24 12:02:45 +05:30
Dylan DPC f94c3c9da1
Rollup merge of #108370 - fbq:time-doc-fix, r=thomcc
std: time: Avoid to use "was created" in elapsed() description

".. since this instant was created" is inaccurate and misleading, consider the following case:
```rust
	let i1 = Instant::now(); // i1 is created at T1
	let i2 = i1 + Duration::from_nanos(0); // i2 is "created" at T2
	i2.elapsed(); // at T3
```
Per the current description, `elapsed()` at T3 should return T3 - T2?

To avoid the inaccuracy, removes the "was created" in the description of {Instant,SystemTime}::elapsed().
And since these types represent times, it's OK to use prepostions with them, e.g. "since this instant".
2023-02-24 12:02:42 +05:30