Commit graph

7633 commits

Author SHA1 Message Date
Chris Denton
daed9e2d9f
Rollup merge of #139710 - thaliaarchi:move-args-pal, r=joboet
Move `args` into `std::sys`

Move platform definitions of `args` into `std::sys`, as part of https://github.com/rust-lang/rust/issues/117276.

cc ``@joboet``
2025-04-13 11:48:19 +00:00
Chris Denton
8a6d6f5ae5
Rollup merge of #139683 - ChrisDenton:windows-with-native, r=tgross35,joboet
Use `with_native_path` for Windows

Ideally, each platform should use their own native path type internally. This will, for example, allow passing a UTF-16 string directly to `std::fs::File::open` and therefore avoid the need for allocating a new null-terminated wide string. However, doing that for every function and platform all at once makes for a large PR that is way too prone to breaking. So this just does some of the Windows parts.

As with the previous Unix PR (#138832) this is intended to be merely a refactoring so I've avoided anything that may require more substantial changes.
2025-04-13 11:48:18 +00:00
Chris Denton
9d2d6a040f
Rollup merge of #138972 - thaliaarchi:nuttx-build, r=Mark-Simulacrum
std: Fix build for NuttX targets

Fix std build for all NuttX targets. It is the single largest set of failures on <https://does-it-build.noratrieb.dev/>. Although, ESP-IDF also requires these same gates, there are other issues for those targets.

This can verified be running `x check library/std --target=` for all NuttX targets.

cc ``@no1wudi``
2025-04-13 11:48:15 +00:00
bors
65fa0ab924 Auto merge of #139734 - ChrisDenton:rollup-28qn740, r=ChrisDenton
Rollup of 6 pull requests

Successful merges:

 - #139107 (std: make `cmath` functions safe)
 - #139607 (Add regression test for #127424)
 - #139691 (Document that `opt-dist` requires metrics to be enabled)
 - #139707 (Fix comment in bootstrap)
 - #139708 (Fix name of field in doc comment)
 - #139709 (bootstrap: fix typo in doc string)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-13 07:10:43 +00:00
Chris Denton
5b2fd54829
Rollup merge of #139107 - joboet:safe_cmath, r=ibraheemdev
std: make `cmath` functions safe

The floating point intrinsics are more difficult, I'll probably wait until #119899 has merged before making them safe as well.
2025-04-13 03:07:06 +00:00
Chris Denton
e0f92bb53c
Rollup merge of #139688 - rust-lang:notriddle/io-result-unbox, r=GuillaumeGomez
rustdoc-search: add unbox flag to Result aliases

Fixes #139665
2025-04-12 21:05:30 +00:00
Chris Denton
096369d97f
Rollup merge of #139382 - ChrisDenton:windows-bindgen-0-61, r=Mark-Simulacrum
Update windows-bindgen to 0.61.0

This updates the automatically generate Windows API bindings. Not much changed this time:

- There's now `Default` implementations for many types, which is convenient. It does however conflict with one place where we implemented a non-zeroed default (to set the length field). But that's no big problem.
- The `--no-core` flag has been renamed to `--no-deps` to more accurately reflect its meaning (i.e. generate all necessary code without requiring additional dependencies).
- The `--link` flag allows us to set the location of the `link!` macro. Currently we use our workspace's `windows_targets` crate but we could move it into library/std using `--link`. However, this would need to be co-ordinated with the `backtrace` crate (which is a separate crate but included in std using `#[path]`). So I've left that for another time.
2025-04-12 21:05:29 +00:00
Chris Denton
0ea345a3c3
Rollup merge of #139276 - tgross35:enable-f16-without-neon, r=Mark-Simulacrum
Revert "Disable `f16` on Aarch64 without `neon`"

The LLVM issue [1] was resolved and the fix was synced to rust-lang/rust in [2].

This reverts commit c51b229140.

[1]: https://github.com/llvm/llvm-project/issues/129394
[2]: https://github.com/rust-lang/rust/pull/138695

try-job: aarch64-gnu
try-job: aarch64-gnu-debug
try-job: armhf-gnu
try-job: dist-various-1
2025-04-12 21:05:28 +00:00
Thalia Archibald
bea202253e Unify owned Args types between platforms 2025-04-12 05:11:27 -07:00
Thalia Archibald
e014fd6b87 Use unsupported args for espidf and vita 2025-04-12 04:38:20 -07:00
Thalia Archibald
6ffebb65d6 Move args into std::sys 2025-04-12 03:10:21 -07:00
Michael Howell
e013cf8afc rustdoc-search: add unbox flag to Result aliases
Fixes #139665
2025-04-11 11:36:40 -07:00
Chris Denton
b613e9781a
Use with_native_path for Windows
Also add a WCStr type
2025-04-11 18:02:03 +00:00
Stuart Cook
c8acc23d1d
Rollup merge of #139600 - tgross35:update-builtins, r=tgross35
Update `compiler-builtins` to 0.1.153

Includes the following changes:

* Avoid OOB access in `memcpy` and `memmove` [1]
* Enable intrinsics on AVR [2]
* `libm` updates to avoid using `core::arch` vector intrinsics [3]
* Re-enable `f16` on aarch64 without Neon [4]

[1]: https://github.com/rust-lang/compiler-builtins/pull/799
[2]: https://github.com/rust-lang/compiler-builtins/pull/791
[3]: https://github.com/rust-lang/compiler-builtins/pull/814
[4]: https://github.com/rust-lang/compiler-builtins/pull/809
2025-04-11 13:31:49 +10:00
Trevor Gross
b435def33c Update compiler-builtins to 0.1.153
Includes the following changes:

* Avoid OOB access in `memcpy` and `memmove` [1]
* Enable intrinsics on AVR [2]
* `libm` updates to avoid using `core::arch` vector intrinsics [3]
* Re-enable `f16` on aarch64 without Neon [4]

[1]: https://github.com/rust-lang/compiler-builtins/pull/799
[2]: https://github.com/rust-lang/compiler-builtins/pull/791
[3]: https://github.com/rust-lang/compiler-builtins/pull/814
[4]: https://github.com/rust-lang/compiler-builtins/pull/809
2025-04-10 17:40:15 +00:00
bors
6813f955a6 Auto merge of #139279 - BoxyUwU:bump-boostrap, r=jieyouxu
Bump boostrap compiler to new beta

try-job: `*msvc*`
2025-04-10 00:43:25 +00:00
Matthias Krüger
d5f930fe76
Rollup merge of #139164 - xizheyin:issue-139034, r=joboet
std: improve documentation for get_mut() methods regarding forgotten guards

Fixes #139034

This PR improves the documentation for `get_mut()` methods in `Mutex`, `RefCell`, and `RwLock` to clarify their behavior when lock guards are forgotten (e.g., via std::mem::forget).

The current documentation for these methods states that a mutable borrow "statically guarantees no locks exist", which is not entirely accurate. While a mutable borrow prevents new locks from being created, it does not clear or detect previously abandoned locks through `forget()`. This can lead to counterintuitive behavior:

https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=e68cefec12dcd435daf2237c16824ed3
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=81263ad652c752afd63c903113d3082c
https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=311baa4edb3abf82a25c8d7bf21a4a52

r? libs
2025-04-09 20:23:09 +02:00
Matthias Krüger
9e541c4673
Rollup merge of #138869 - ChrisDenton:command-curdir, r=tgross35
Try not to use verbatim paths in `Command::current_dir`

If possible, we should try not to use verbatim paths in `Command::current_dir`. It might work but it might also break code in the subprocess that assume the current directory isn't verbatim (including Windows APIs). cc ``@ehuss``

Side note: we now have a lot of ad-hoc fixes like this spread about the place. It'd be good to make a proper `WindowsPath` type that handles all this in one place. But that's a bigger job for another PR.
2025-04-09 14:52:36 +02:00
Boxy
c93005ee65 update cfgs 2025-04-09 12:29:59 +01:00
Boxy
a6c2ec04b4 replace version placeholder 2025-04-09 12:29:59 +01:00
Chris Denton
edfc747225
Avoid verbatim paths in Command::current_dir
If possible, we should try not to use verbatim paths in Command::current_dir. It might work but it might also break code (including some Windows APIs) that assume the current directory isn't verbatim.
2025-04-09 01:32:19 +00:00
Guillaume Gomez
962fa98eeb
Rollup merge of #138876 - thaliaarchi:trusty-stdio, r=Noratrieb
Trusty: Implement `write_vectored` for stdio

Currently, `write` for stdout and stderr on Trusty is implemented with the semantics of `write_all`. Instead, call the underlying syscall only once in `write` and use the default implementation of `write_all` like other platforms. Also, implement `write_vectored` by adding support for `IoSlice`.

Refactor stdin to reuse the unsupported type like https://github.com/rust-lang/rust/pull/136769.

It requires #138875 to fix the build for Trusty, though they do not conflict and can merge in either order.

cc `@randomPoison`
2025-04-06 18:08:09 +02:00
Thalia Archibald
0acac2cbe3 std: Fix build for NuttX targets
Fix std build for all NuttX targets. It is the single largest set of
failures on <https://does-it-build.noratrieb.dev/>. Although, ESP-IDF
also requires these same gates, there are other issues for those
targets.

This can verified be running `x check library/std --target=` for all
NuttX targets.
2025-04-05 12:05:43 -07:00
Matthias Krüger
527725b025
Rollup merge of #139121 - thaliaarchi:rename-thread_local-statik, r=Noratrieb
Rename internal module from `statik` to `no_threads`

This module is named in reference to the keyword, but the term is somewhat overloaded. Rename it to more clearly describe it and avoid the misspelling.
2025-04-05 19:40:24 +02:00
Matthias Krüger
a64ccf4a46
Rollup merge of #139092 - thaliaarchi:move-fd-pal, r=joboet
Move `fd` into `std::sys`

Move platform definitions of `fd` into `std::sys`, as part of https://github.com/rust-lang/rust/issues/117276.

Unlike other modules directly under `std::sys`, this is only available on some platforms and I have not provided a fallback abstraction for unsupported platforms. That is similar to how `std::os::fd` is gated to only supported platforms.

Also, fix the `unsafe_op_in_unsafe_fn` lint, which was allowed for the Unix fd impl. Since macro expansions from `std::sys::pal::unix::weak` trigger this lint, fix it there too.

cc `@joboet,` `@ChrisDenton`

try-job: x86_64-gnu-aux
2025-04-05 10:18:04 +02:00
Thalia Archibald
9b889e9198 Rename internal module from statik to no_threads
This module is named in reference to the keyword, but the term is
somewhat overloaded. Rename it to more clearly describe it and avoid the
misspelling.
2025-04-04 20:31:15 -07:00
Thalia Archibald
3ab22fabf1 Fix unsafe_op_in_unsafe_fn for Unix fd and weak 2025-04-04 20:11:08 -07:00
Thalia Archibald
4085af0183 Move fd into sys 2025-04-04 20:11:08 -07:00
Stuart Cook
92bb7261c4
Rollup merge of #137897 - xTachyon:tls-fix, r=thomcc,jieyouxu
fix pthread-based tls on apple targets

Tries to fix #127773.
2025-04-05 13:18:13 +11:00
Stuart Cook
2e4e196a5b
Rollup merge of #136457 - calder:master, r=tgross35
Expose algebraic floating point intrinsics

# Problem

A stable Rust implementation of a simple dot product is 8x slower than C++ on modern x86-64 CPUs. The root cause is an inability to let the compiler reorder floating point operations for better vectorization.

See https://github.com/calder/dot-bench for benchmarks. Measurements below were performed on a i7-10875H.

### C++: 10us 

With Clang 18.1.3 and `-O2 -march=haswell`:
<table>
<tr>
    <th>C++</th>
    <th>Assembly</th>
</tr>
<tr>
<td>
<pre lang="cc">
float dot(float *a, float *b, size_t len) {
    #pragma clang fp reassociate(on)
    float sum = 0.0;
    for (size_t i = 0; i < len; ++i) {
        sum += a[i] * b[i];
    }
    return sum;
}
</pre>
</td>
<td>
<img src="https://github.com/user-attachments/assets/739573c0-380a-4d84-9fd9-141343ce7e68" />
</td>
</tr>
</table>

### Nightly Rust: 10us 

With rustc 1.86.0-nightly (8239a37f9) and `-C opt-level=3 -C target-feature=+avx2,+fma`:
<table>
<tr>
    <th>Rust</th>
    <th>Assembly</th>
</tr>
<tr>
<td>
<pre lang="rust">
fn dot(a: &[f32], b: &[f32]) -> f32 {
    let mut sum = 0.0;
    for i in 0..a.len() {
        sum = fadd_algebraic(sum, fmul_algebraic(a[i], b[i]));
    }
    sum
}
</pre>
</td>
<td>
<img src="https://github.com/user-attachments/assets/9dcf953a-2cd7-42f3-bc34-7117de4c5fb9" />
</td>
</tr>
</table>

### Stable Rust: 84us 

With rustc 1.84.1 (e71f9a9a9) and `-C opt-level=3 -C target-feature=+avx2,+fma`:
<table>
<tr>
    <th>Rust</th>
    <th>Assembly</th>
</tr>
<tr>
<td>
<pre lang="rust">
fn dot(a: &[f32], b: &[f32]) -> f32 {
    let mut sum = 0.0;
    for i in 0..a.len() {
        sum += a[i] * b[i];
    }
    sum
}
</pre>
</td>
<td>
<img src="https://github.com/user-attachments/assets/936a1f7e-33e4-4ff8-a732-c3cdfe068dca" />
</td>
</tr>
</table>

# Proposed Change

Add `core::intrinsics::f*_algebraic` wrappers to `f16`, `f32`, `f64`, and `f128` gated on a new `float_algebraic` feature.

# Alternatives Considered

https://github.com/rust-lang/rust/issues/21690 has a lot of good discussion of various options for supporting fast math in Rust, but is still open a decade later because any choice that opts in more than individual operations is ultimately contrary to Rust's design principles.

In the mean time, processors have evolved and we're leaving major performance on the table by not supporting vectorization. We shouldn't make users choose between an unstable compiler and an 8x performance hit.

# References

* https://github.com/rust-lang/rust/issues/21690
* https://github.com/rust-lang/libs-team/issues/532
* https://github.com/rust-lang/rust/issues/136469
* https://github.com/calder/dot-bench
* https://www.felixcloutier.com/x86/vfmadd132ps:vfmadd213ps:vfmadd231ps

try-job: x86_64-gnu-nopt
try-job: x86_64-gnu-aux
2025-04-05 13:18:12 +11:00
Calder Coalson
8ff70529f2 Expose algebraic floating point intrinsics 2025-04-04 16:13:57 -07:00
Matthias Krüger
fa7d66eaaa
Rollup merge of #139366 - RalfJung:ToSocketAddrs, r=jieyouxu
ToSocketAddrs: fix typo

It's "a function", never "an function".

I noticed the same typo somewhere in the compiler sources so figured I'd fix it there as well.
2025-04-04 21:54:59 +02:00
Chris Denton
8b12153e35
Update windows-bindgen to 0.61.0 2025-04-04 16:41:40 +00:00
Ralf Jung
0f12a2c4ad ToSocketAddrs: fix typo 2025-04-04 14:47:04 +02:00
Matthias Krüger
f701a5cc38
Rollup merge of #139295 - JakeWharton:jw.duplicate-anon-pipe.2025-04-02, r=joboet
Remove creation of duplicate `AnonPipe`

The `File` is unwrapped to a `Handle` into an `AnonPipe`, and then that `AnonPipe` was unwrapped to a `Handle` into another `AnonPipe`. The second operation is entirely redundant.
2025-04-04 08:02:06 +02:00
Matthias Krüger
ff8f2eff3a
Rollup merge of #139068 - a1phyr:less_uninit, r=joboet
io: Avoid marking some bytes as uninit

These bytes were marked as uninit, which would cause them to be initialized multiple times even though it was not necessary.
2025-04-03 21:18:31 +02:00
xizheyin
0162f29436 std: clarify RwLock::get_mut more clearly
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-04-03 19:25:47 +08:00
Jake Wharton
0d8c33f6f1 Remove creation of duplicate AnonPipe
The File is unwrapped to a Handle into an AnonPipe, and then that AnonPipe was unwrapped to a Handle into another AnonPipe. The second operation is entirely redundant.
2025-04-02 23:03:55 -04:00
Trevor Gross
4a8d35709e Revert "Disable f16 on Aarch64 without neon"
The LLVM issue [1] was resolved and the fix was synced to rust-lang/rust
in [2].

This reverts commit c51b229140.

[1]: https://github.com/llvm/llvm-project/issues/129394
[2]: https://github.com/rust-lang/rust/pull/138695
2025-04-02 19:21:10 +00:00
bors
e2014e876e Auto merge of #138928 - ChrisDenton:fix-uwp, r=tgross35
Fix UWP reparse point check

Fixes #138921
2025-04-01 18:22:03 +00:00
Benoît du Garreau
878786848f io: Avoid Avoid marking bytes as uninit in BufReader::peek 2025-04-01 00:08:02 +02:00
Benoît du Garreau
2feb911818 io: Avoid marking buffer as uninit when copying to BufWriter 2025-04-01 00:07:59 +02:00
xizheyin
04d9d864b3
std: clarify Mutex::get_mut more clearly
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-03-31 15:23:17 +08:00
bors
2196affd01 Auto merge of #139119 - matthiaskrgr:rollup-7l2ri0f, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #137928 (stabilize const_cell)
 - #138431 (Fix `uclibc` LLVM target triples)
 - #138832 (Start using `with_native_path` in `std::sys::fs`)
 - #139081 (std: deduplicate `errno` accesses)
 - #139100 (compiletest: Support matching diagnostics on lines below)
 - #139105 (`BackendRepr::is_signed`: comment why this may panics)
 - #139106 (Mark .pp files as Rust)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-29 23:12:40 +00:00
Matthias Krüger
821e0fe0a2
Rollup merge of #139081 - joboet:errno_dedup, r=Noratrieb
std: deduplicate `errno` accesses

By marking `__errno_location` as `#[ffi_const]` and `std::sys::os::errno` as `#[inline]`, this PR allows merging multiple calls to `io::Error::last_os_error()` into one.
2025-03-29 21:08:12 +01:00
Matthias Krüger
fb6d10e13b
Rollup merge of #138832 - ChrisDenton:with_native_path, r=joboet
Start using `with_native_path` in `std::sys::fs`

Ideally, each platform should use their own native path type internally. This will, for example, allow passing a `CStr` directly to `std::fs::File::open` and therefore avoid the need for allocating a new null-terminated C string.

However, doing that for every function and platform all at once makes for a large PR that is way too prone to breaking. So this PR does some minimal refactoring which should help progress towards that goal. The changes are Unix-only and even then I avoided functions that require more changes so that this PR is just moving things around.

r? joboet
2025-03-29 21:08:12 +01:00
bors
1799887bb2 Auto merge of #133572 - frank-king:feature/unique_arc, r=Amanieu
Implement `alloc::sync::UniqueArc`

This implements the `alloc::sync::UniqueArc` part of #112566.
2025-03-29 20:05:06 +00:00
Chris Denton
89c9c21b06
Start using with_native_path in std::sys::fs 2025-03-29 14:43:41 +00:00
joboet
3a4dd1b7b2
std: make cmath functions safe 2025-03-29 13:08:18 +01:00
Matthias Krüger
111351fcc1
Rollup merge of #138988 - madsmtm:internal-weak-macro-syntax, r=ibraheemdev
Change the syntax of the internal `weak!` macro

Change the syntax to include parameter names and a trailing semicolon.

Motivation:
- Mirror the `syscall!` macro.
- Allow rustfmt to format it (when wrapped in parentheses, and when not inside `cfg_if!`).
- For better documentation (having the parameter names available in the source code is a bit nicer).
- Allow a future improvement to this macro where we can sometimes use the symbol directly when it's statically known to be available (and thus need the parameter names to be available), see https://github.com/rust-lang/rust/pull/136868.

r? libs
2025-03-29 11:43:46 +01:00