Commit Graph

7606 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
Matthias Krüger
c82b88b009
Rollup merge of #138757 - rust-wasi-web:wasi-thread-stack-size, r=alexcrichton
wasm: increase default thread stack size to 1 MB

The default stack size for the [main thread is 1 MB as specified by linker options](38cf49dde8/compiler/rustc_target/src/spec/base/wasm.rs (L14)).
However, the default stack size for threads was only 64 kB.

This is surprisingly small and thus we increase it to 1 MB to match the main thread.
2025-03-29 11:43:46 +01:00
Matthias Krüger
7c0a14f030
Rollup merge of #139069 - a1phyr:better_take, r=joboet
`io::Take`: avoid new `BorrowedBuf` creation in some case

If `self.limit == buf.capacity()`, doing the whole `BorrowedBuf` dance is not necessary.
2025-03-28 21:18:31 +01:00
joboet
dd4f616423
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-28 19:32:36 +01:00
Benoît du Garreau
9055765ce1 io::Take: avoid new BorrowedBuf creation in some case 2025-03-28 16:36:49 +01:00
Rafael Bachmann
0f418520c6
Fix formatting nit in process.rs 2025-03-28 13:22:09 +01:00
Jacob Pratt
5bd0fd6323
Rollup merge of #139021 - joboet:pre-vista-fallback, r=ChrisDenton
std: get rid of pre-Vista fallback code

We haven't had any Windows XP targets for a long while now...

r? ChrisDenton
2025-03-27 21:41:49 -04:00
Thalia Archibald
41b04653f3 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 #136769.
2025-03-27 16:49:30 -07:00
bors
7586a9f99a Auto merge of #138702 - m-ou-se:spawn-in-atexit, r=Mark-Simulacrum
Allow spawning threads after TLS destruction

Fixes #138696
2025-03-27 21:46:58 +00:00
joboet
3371d498b1
std: get rid of pre-Vista fallback code
We haven't had any Windows XP targets for a long while now...
2025-03-27 15:41:46 +01:00
Mads Marquart
a7bafc0afc 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).
- For better documentation (having the parameter names available in
  the source code is a bit nicer).
- Allow future improvements to this macro where we can sometimes use the
  symbol directly when it's statically known to be available.
2025-03-26 16:25:05 +01:00
Thalia Archibald
a475f5d181 Fix typo in error message 2025-03-25 23:37:22 -07:00
Jacob Pratt
0d61b83f59
Rollup merge of #138875 - thaliaarchi:trusty-build, r=randomPoison,saethlin
Trusty: Fix build for anonymous pipes and std::sys::process

PRs #136842 (Add libstd support for Trusty targets), #137793 (Stablize anonymous pipe), and #136929 (std: move process implementations to `sys`) merged around the same time, so update Trusty to take them into account.

cc `@randomPoison`
2025-03-25 20:34:47 -04:00
Chris Denton
8524a7c4b7
Fix UWP reparse point check 2025-03-25 10:31:05 +00:00
Matthias Krüger
b157594165
Rollup merge of #138662 - Ayush1325:uefi-fs-1, r=nicholasbishop,petrochenkov
Implement some basics in UEFI fs

- Just getting some basics out of the way while waiting for #138236 to be merged.
- Adds `fs::canonicalize`. Should be same as absolute in case of UEFI since there is no symlink support and absolute path is guaranteed to be uniqe according to spec.
- Make `fs::lstat` same as `fs::stat`. Should be same since UEFI does not have symlink support.
- Implement `OptionOptions`.

cc ````@nicholasbishop```` ````@dvdhrm````
2025-03-24 20:40:06 +01:00
Ayush Singh
021d23b64e
std: fs: uefi: Implement OpenOptions
UEFI does not have specific modes for create_new, truncate and append.
So those need to to be simulated after opening the file.

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-03-24 08:44:31 +05:30
Ayush Singh
fc0cf52e28
std: fs: uefi: Make lstat call stat
- UEFI does not have symlinks. So lstat and stat should behave the same.

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-03-24 08:40:08 +05:30
Ayush Singh
0cd1d516ae
std: fs: uefi: Implement canonicalize
- Should be same as absolute in UEFI since there are no symlinks.
- Also each absolute path representation should be unique according to
  the UEFI specification.

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-03-24 08:40:07 +05:30
Thalia Archibald
b672659472 Trusty: Fix build for anonymous pipes and std::sys::process
PRs #136842 (Add libstd support for Trusty targets), #137793 (Stablize
anonymous pipe), and #136929 (std: move process implementations to
`sys`) merged around the same time, so update Trusty to take them into
account.
2025-03-23 19:32:20 -07:00
Jacob Pratt
b406d9aaaa
Rollup merge of #138728 - tgross35:update-builtins, r=tgross35
Update `compiler-builtins` to 0.1.152

Includes the following changes related to unordered atomics:

* Remove element_unordered_atomic intrinsics [1]
* Remove use of `atomic_load_unordered` and undefined behaviour [2]

There are a handful of other small changes, but nothing else user-visible.

[1]: https://github.com/rust-lang/compiler-builtins/pull/789
[2]: https://github.com/rust-lang/compiler-builtins/pull/790
2025-03-23 20:44:12 -04:00
Jacob Pratt
8e30df7f26
Rollup merge of #138671 - ChrisDenton:filetype, r=joshtriplett
Fix `FileType` `PartialEq` implementation on Windows

Fixes #138668

On Windows the [`FileType`](https://doc.rust-lang.org/stable/std/fs/struct.FileType.html) struct was deriving `PartialEq` which in turn means it was doing a bit-for-bit comparison on the file attributes and reparse point. This is wrong because `attributes` may contain many things unrelated to file type.

`FileType` on Windows allows for four possible combinations (see also [`FileTypeExt`](https://doc.rust-lang.org/stable/std/os/windows/fs/trait.FileTypeExt.html)): `file`, `dir`, `symlink_file` and `symlink_dir`. So the new implementation makes sure both symlink and directory information match (and only those things).

This could be considered just a bug fix but it is a behaviour change so someone from libs-api might want to FCP this (or might not)...
2025-03-23 20:44:11 -04:00
Trevor Gross
95181ae170 Update compiler-builtins to 0.1.152
Includes the following changes related to unordered atomics:

* Remove element_unordered_atomic intrinsics [1]
* Remove use of `atomic_load_unordered` and undefined behaviour [2]

There are a handful of other small changes, but nothing else
user-visible.

[1]: https://github.com/rust-lang/compiler-builtins/pull/789
[2]: https://github.com/rust-lang/compiler-builtins/pull/790
2025-03-24 00:29:21 +00:00
Michael Goulet
f4096dcda8
Rollup merge of #138667 - Ayush1325:uefi-mkdir, r=joboet
std: uefi: fs: Implement mkdir

- Since there is no direct mkdir in UEFI, first check if a file/dir with same path exists and then create the directory.

cc `@dvdhrm` `@nicholasbishop`
2025-03-23 14:59:33 -04:00
Michael Goulet
bb49f0d8b6
Rollup merge of #138631 - thaliaarchi:sgx-read-buf-test, r=workingjubilee
Update test for SGX now implementing `read_buf`

In #108326, `read_buf` was implemented for a variety of types, but SGX was saved for later. Update a test from then, now that #137355 implemented it for SGX types.

cc ````@jethrogb````
2025-03-23 14:59:32 -04:00
Michael Goulet
d7c5f5f319
Rollup merge of #138236 - Ayush1325:uefi-event, r=petrochenkov
uefi: Add OwnedEvent abstraction

- Events are going to become quite important for Networking, so needed owned abstractions.
- Switch to OwnedEvent abstraction for Exit boot services event.

cc ````@nicholasbishop````
2025-03-23 14:59:30 -04:00
bors
aa8f0fd716 Auto merge of #136929 - joboet:move_process_pal, r=Mark-Simulacrum
std: move process implementations to `sys`

As per #117276, this moves the implementations of `Process` and friends out of the `pal` module and into the `sys` module, removing quite a lot of error-prone `#[path]` imports in the process (hah, get it ;-)). I've also made the `zircon` module a dedicated submodule of `pal::unix`, hopefully we can move some other definitions there as well (they are currently quite a lot of duplications in `sys`). Also, the `ensure_no_nuls` function on Windows now lives in `sys::pal::windows` – it's not specific to processes and shared by the argument implementation.
2025-03-23 14:10:35 +00:00
bors
60a3084f64 Auto merge of #136769 - thaliaarchi:io-optional-methods/stdio, r=joboet
Provide optional `Read`/`Write` methods for stdio

Override more of the default methods for `io::Read` and `io::Write` for stdio types, when efficient to do so, and deduplicate unsupported types.

Tracked in https://github.com/rust-lang/rust/issues/136756.

try-job: x86_64-msvc-1
2025-03-23 06:23:51 +00:00
bors
756bff97ea Auto merge of #138841 - matthiaskrgr:rollup-bfkls57, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #138018 (rustdoc: Use own logic to print `#[repr(..)]` attributes in JSON output.)
 - #138294 (Mark some std tests as requiring `panic = "unwind"`)
 - #138468 (rustdoc js: add nonnull helper and typecheck src-script.js)
 - #138675 (Add release notes for 1.85.1)
 - #138765 (Fix Thread::set_name on cygwin)
 - #138786 (Move some driver code around)
 - #138793 (target spec check: better error when llvm-floatabi is missing)
 - #138822 (De-Stabilize `file_lock`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-22 23:59:01 +00:00