Commit graph

8576 commits

Author SHA1 Message Date
Amanieu d'Antras
4bc6d75592 Revert #148937 (Remove initialized-bytes tracking from BorrowedBuf and BorrowedCursor)
This caused several performance regressions because of existing code
which uses `Read::read` and therefore requires full buffer
initialization. This is particularly a problem when the same buffer is
re-used for multiple read calls since this means it needs to be fully
re-initialized each time.

There is still some benefit to landing the API changes, but we will have
to add private APIs so that the existing infrastructure can
track and avoid redundant initialization.

(cherry picked from commit 4b07875505)
2025-12-20 13:58:49 -08:00
Boxy Uwu
3c55c98ec8 replace version placeholder 2025-12-08 10:08:32 +00:00
bors
3e2dbcdd3a Auto merge of #149646 - matthiaskrgr:rollup-jbfeow8, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#147224 (Emscripten: Turn wasm-eh on by default)
 - rust-lang/rust#149405 (Recover on misspelled item keyword)
 - rust-lang/rust#149443 (Tidying up UI tests [6/N])
 - rust-lang/rust#149524 (Move attribute safety checking to attribute parsing)
 - rust-lang/rust#149593 (powf, powi: point out SNaN non-determinism)
 - rust-lang/rust#149605 (Use branch name instead of HEAD when unshallowing)
 - rust-lang/rust#149612 (Apply the `bors` environment also to the `outcome` job)
 - rust-lang/rust#149623 (Don't require a normal tool build of clippy/rustfmt when running their test steps)
 - rust-lang/rust#149627 (Point to the item that is incorrectly annotated with `#[diagnostic::on_const]`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-12-04 22:04:03 +00:00
Matthias Krüger
364b20e5f8
Rollup merge of #149593 - RalfJung:pow-nondet, r=Amanieu
powf, powi: point out SNaN non-determinism

The non-determinism has two sources:
- LLVM reserves the right to treat signaling NaNs as-if they were quiet, so it may fold `powf(x, 0)` to `1` even if `x` might be a signaling NaN.
- Some libm `pow` implementations (e.g. the one in musl) don't implement the signaling NaN special-case. See https://rust.godbolt.org/z/chsbv5v4d.

Cc `@tgross35` `@Amanieu`
2025-12-04 16:07:54 +01:00
bors
29e035e172 Auto merge of #149632 - matthiaskrgr:rollup-c5iqgtn, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - rust-lang/rust#149521 (Improve `io::Error::downcast`)
 - rust-lang/rust#149544 (Only apply `no_mangle_const_items`'s suggestion to plain const items)
 - rust-lang/rust#149545 (fix the check for which expressions read never type)
 - rust-lang/rust#149570 (rename cortex-ar references to unified aarch32)
 - rust-lang/rust#149574 (Batched compiletest Config fixups)
 - rust-lang/rust#149579 (Motor OS: fix compile error)
 - rust-lang/rust#149595 (Tidying up `tests/ui/issues` tests [2/N])
 - rust-lang/rust#149597 (Revert "implement and test `Iterator::{exactly_one, collect_array}`")
 - rust-lang/rust#149608 (Allow PowerPC spe_acc as clobber-only register)
 - rust-lang/rust#149610 (Implement benchmarks for uN::{gather,scatter}_bits)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-12-04 14:38:19 +00:00
Matthias Krüger
d709cd67e2
Rollup merge of #149579 - moturus:fix-thread-new, r=joboet
Motor OS: fix compile error

[PR 148765](https://github.com/rust-lang/rust/pull/148765) changed the expected signature of Thread::new(), which broke Motor OS target.

Also set thread name while at it.
2025-12-04 09:22:13 +01:00
Matthias Krüger
170fffd31d
Rollup merge of #149521 - a1phyr:improve_io_error, r=joboet
Improve `io::Error::downcast`

Rewrite this function to help to compiler understand what is going on here.
2025-12-04 09:22:10 +01:00
Matthias Krüger
08a5519924
Rollup merge of #149456 - joboet:async-safe-tid, r=Mark-Simulacrum
std: don't call `current_os_id` from signal handler

`current_os_id` is not always async-signal-safe depending on the platform, hence it may not be called from the SIGSEGV handler. Instead, store the thread ID along with the thread name during setup. With rust-lang/rust#144465 merged, this information is available even before the thread main function.
2025-12-04 08:46:19 +01:00
Ralf Jung
743d27794f powf, powi: point out SNaN non-determinism 2025-12-03 13:35:34 +01:00
Matthias Krüger
45b2a711b1
Rollup merge of #148937 - joshtriplett:borrowed-buf-no-init-tracking, r=Amanieu
Remove initialized-bytes tracking from `BorrowedBuf` and `BorrowedCursor`

As discussed extensively in libs-api, the initialized-bytes tracking primarily benefits calls to `read_buf` that end up initializing the buffer and calling `read`, at the expense of calls to `read_buf` that *don't* need to initialize the buffer. Essentially, this optimizes for the past at the expense of the future. If people observe performance issues using `read_buf` (or something that calls it) with a given `Read` impl, they can fix those performance issues by implementing `read_buf` for that `Read`.

Update the documentation to stop talking about initialized-but-unfilled bytes.

Remove all functions that just deal with those bytes and their tracking, and remove usage of those methods.

Remove `BorrowedCursor::advance` as there's no longer a safe case for advancing within initialized-but-unfilled bytes. Rename `BorrowedCursor::advance_unchecked` to `advance`.

Update tests.

r? ``@Amanieu``
2025-12-03 07:36:12 +01:00
U. Lasiotus
537a8d7962 Motor OS: fix compile error
[PR 148765](https://github.com/rust-lang/rust/pull/148765) changed
the expected signature of Thread::new(), which broke Motor OS target.

Also set thread name.
2025-12-03 04:54:04 +00:00
Ayush Singh
1331c35f02
std: sys: fs: uefi: Make time in FileAttr optional
At least on OVMF, some files copied over from linux file system seem
to have invalid time (year = 1980 and everything else 0). Since Rust
allows time to be optional and we can return error, that seems to be
the way to go for now.

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-12-02 22:34:47 +05:30
joboet
85b6c380d6
remember the main thread ID before performing platform initialisation 2025-12-02 18:03:33 +01:00
Josh Triplett
1ef636d61a Update other targets for BorrowedCursor unstable API changes 2025-12-02 08:03:10 -08:00
Josh Triplett
382509988b Remove initialized-bytes tracking from BorrowedBuf and BorrowedCursor
As discussed extensively in libs-api, the initialized-bytes tracking
primarily benefits calls to `read_buf` that end up initializing the
buffer and calling `read`, at the expense of calls to `read_buf` that
*don't* need to initialize the buffer. Essentially, this optimizes for
the past at the expense of the future. If people observe performance
issues using `read_buf` (or something that calls it) with a given `Read`
impl, they can fix those performance issues by implementing `read_buf`
for that `Read`.

Update the documentation to stop talking about initialized-but-unfilled
bytes.

Remove all functions that just deal with those bytes and their tracking,
and remove usage of those methods.

Remove `BorrowedCursor::advance` as there's no longer a safe case for
advancing within initialized-but-unfilled bytes. Rename
`BorrowedCursor::advance_unchecked` to `advance`.

Update tests.
2025-12-02 01:32:27 -08:00
Benoît du Garreau
7de190a64b io::Error::downcast: avoid reallocation in case of failure 2025-12-01 19:40:50 +01:00
Matthias Krüger
5f3dc5d89a
Rollup merge of #149102 - bend-n:maybe_uninit_slice, r=joboet
stabilize maybe_uninit_slice

Tracking issue: rust-lang/rust#63569
Closes: rust-lang/rust#63569
FCP completed: https://github.com/rust-lang/rust/issues/63569#issuecomment-3477510504

Removes:
```rs
pub const fn slice_as_ptr(this: &[MaybeUninit<T>]) -> *const T;
pub const fn slice_as_mut_ptr(this: &mut [MaybeUninit<T>]) -> *mut T;
```
2025-12-01 17:55:06 +01:00
bors
9b82a4fffe Auto merge of #149481 - RalfJung:threadid-fallback, r=joboet
ThreadId generation fallback path: avoid spurious yields

Fixes https://github.com/rust-lang/miri/issues/4737
Alternative to https://github.com/rust-lang/rust/pull/149476
Cc `@orlp` `@joboet`
2025-12-01 10:47:13 +00:00
Ralf Jung
14830bfd0c ThreadId generation fallback path: avoid spurious yields 2025-11-30 22:52:28 +01:00
Matthias Krüger
bc83bf21dd
Rollup merge of #149236 - tisonkun:patch-1, r=tgross35
Clarify edge cases for Barrier::new

... since n-1 is undefined when the usize n is 0.
2025-11-30 12:03:23 +01:00
tison
5d8f2b8ebe
Clarify edge cases for Barrier::new 2025-11-30 17:14:46 +08:00
Matthias Krüger
c93801cb20
Rollup merge of #148765 - joboet:split-up-thread, r=ChrisDenton
std: split up the `thread` module

Almost all functionality in `std::thread` is currently implemented in `thread/mod.rs`, resulting in a *huge* file with more than 2000 lines and multiple, interoperating `unsafe` sections. This PR splits the file up into multiple different private modules, each implementing mostly independent parts of the functionality. The only remaining `unsafe` interplay is that of the `lifecycle` and `scope` modules, the `spawn_scoped` implementation relies on the live thread count being updated correctly by the `lifecycle` module.

This PR contains no functional changes and only moves code around for the most part, with a few notable exceptions:
* `with_current_name` is moved to the already existing `current` module and now uses the `name` method instead of calculating the name from private fields. The old code was just a reimplementation of that method anyway.
* The private `JoinInner` type used to implement both join handles now has some more methods (`is_finished`, `thread` and the `AsInner`/`IntoInner` implementations) to avoid having to expose private fields and their invariants.
* The private `spawn_unchecked_` (note the underscore) method of `Builder` is now a freestanding function in `lifecycle`.

The rest of the changes are just visibility annotations.

I realise this PR ended up quite large – let me know if there is anyway I can aid the review process.

Edit: I've simplified the diff by adding an intermediate commit that creates all the new files by duplicating `mod.rs`. The actual changes in the second commit thus appear to delete the non-relevant parts from the respective file.
2025-11-29 20:54:06 +01:00
joboet
5009847d14
std: don't call current_os_id from signal handler 2025-11-29 16:16:51 +01:00
joboet
9c6e0f6f57
std: update broken links in thread module 2025-11-29 15:59:11 +01:00
joboet
8b08da218e
std: split up the thread module 2025-11-29 15:59:11 +01:00
joboet
e57df9220a
std: split up the thread module (preparation) 2025-11-29 15:12:28 +01:00
Ayush Singh
5b0fded2b3
std: sys: fs: uefi: Implement rmdir and unlink
- Implement remove_dir and remove_file.
- Tested on qemu ovmf.

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-11-29 14:14:02 +05:30
bors
3c5c55864f Auto merge of #149441 - jhpratt:rollup-4hmqc0z, r=jhpratt
Rollup of 5 pull requests

Successful merges:

 - rust-lang/rust#147362 (Avoid suggesting constrain the associated type with unknown type)
 - rust-lang/rust#149395 (float::minimum/maximum: say which exact IEEE operation this corresponds to)
 - rust-lang/rust#149396 (Remove outdated comment)
 - rust-lang/rust#149421 (Add a regression test for issue 129865)
 - rust-lang/rust#149424 (Update books)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-11-29 05:20:07 +00:00
Jacob Pratt
a3173c1e62
Rollup merge of #149396 - yotamofek:pr/library/outdated-comment, r=chenyukang
Remove outdated comment

The comment was added in rust-lang/rust#136897 , but wasn't removed when the feature gate was stabilized (again).

Also, `it's` -> `its` :)
2025-11-28 21:22:24 -05:00
bors
467250ddb2 Auto merge of #144465 - orlp:system-alloc-tls, r=Mark-Simulacrum
Allow the global allocator to use thread-local storage and std:🧵:current()

Fixes https://github.com/rust-lang/rust/issues/115209.

Currently the thread-local storage implementation uses the `Global` allocator if it needs to allocate memory in some places. This effectively means the global allocator can not use thread-local variables. This is a shame as an allocator is precisely one of the locations where you'd *really* want to use thread-locals. We also see that this lead to hacks such as https://github.com/rust-lang/rust/pull/116402, where we detect re-entrance and abort.

So I've made the places where I could find allocation happening in the TLS implementation use the `System` allocator instead. I also applied this change to the storage allocated for a `Thread` handle so that it may be used care-free in the global allocator as well, for e.g. registering it to a central place or parking primitives.

r? `@joboet`
2025-11-29 02:08:53 +00:00
bors
9050733395 Auto merge of #148020 - bjorn3:oom_backtrace, r=Mark-Simulacrum
Show backtrace on allocation failures when possible

And if an allocation while printing the backtrace fails, don't try to print another backtrace as that will never succeed.

Split out of https://github.com/rust-lang/rust/pull/147725 to allow landing this independently of a decision whether or not to remove `-Zoom=panic`.
2025-11-28 12:27:33 +00:00
Orson Peters
48fc0fd597 Add missing feature flag 2025-11-28 02:12:54 +01:00
Orson Peters
4ecf505eb7 Silence dead code warning for ThreadInit::init 2025-11-28 00:47:36 +01:00
Orson Peters
9b5bb75875 Add inline(never) to prevent reordering after TLS has been destroyed 2025-11-28 00:16:30 +01:00
Orson Peters
b717684f87 Fix SGX implementation 2025-11-28 00:16:30 +01:00
Orson Peters
85a49073c3 Use checked_add instead of manual overflow check 2025-11-28 00:16:30 +01:00
Orson Peters
0b7cdf2435 Address review comments 2025-11-28 00:16:30 +01:00
Orson Peters
58830def36 Ensure set_current is called early during thread init 2025-11-28 00:16:23 +01:00
Orson Peters
f9b0811d01 Add documentation guaranteeing global allocator use of TLS
Remove outdated part of comment claiming thread_local re-enters global allocator

Fix typo in doc comment

Add comments for guarantees given and footnote that System may still be called

Revise mention of using the global allocator

Allow for the possibility that the global allocator is the system allocator.

Co-authored-by: Mark Rousskov <mark.simulacrum@gmail.com>
2025-11-28 00:09:12 +01:00
Orson Peters
8481b827fb Use spinlock for ThreadId if 64-bit atomic unavailable 2025-11-28 00:09:12 +01:00
Orson Peters
750609c0a7 Use System allocator for thread-local storage 2025-11-28 00:09:12 +01:00
Yotam Ofek
f15e99b2f0 Remove outdated comment 2025-11-27 20:05:58 +02:00
bendn
d67f99af2e
fix 2025-11-27 17:55:34 +07:00
Stuart Cook
0dae3e0293
Rollup merge of #149301 - moturus:main, r=Mark-Simulacrum
Motor OS: make decode_error_kind more comprehensive

A minor refactoring of a Tier 3 target (Motor OS).
2025-11-27 12:36:53 +11:00
Stuart Cook
45c136b982
Rollup merge of #149074 - schneems:schneems/get_env_clear, r=Mark-Simulacrum
Add Command::get_env_clear

This addition allows an end-user to inspect whether the env clear value is set on a `Command` instance or not.

Discussed in:

- Tracking issue: https://github.com/rust-lang/rust/issues/149070 (partially closes)
- ACP: https://github.com/rust-lang/libs-team/issues/194
2025-11-27 12:36:49 +11:00
Stuart Cook
a32d3103d5
Rollup merge of #148048 - thaliaarchi:stabilize-maybeuninit-write-slice, r=Mark-Simulacrum
Stabilize `maybe_uninit_write_slice`

Stabilize feature `maybe_uninit_write_slice` (closes https://github.com/rust-lang/rust/issues/79995).

Note that this also const-stabilizes `<[MaybeUninit<_>]>::write_copy_of_slice`. That method depends on `<[_]>::copy_from_slice`, which is already const-stable, and `<[MaybeUninit<_>]>::assume_init_mut` which is now also stable.
2025-11-27 12:36:48 +11:00
bors
1be6b13be7 Auto merge of #149079 - zachs18:clone_from_ref, r=Mark-Simulacrum
Add `Box::clone_from_ref` and similar under `feature(clone_from_ref)`

Tracking issue: https://github.com/rust-lang/rust/issues/149075

Accepted ACP: https://github.com/rust-lang/libs-team/issues/483

This PR implements `clone_from_ref` (and `try_*` and `_*in` variants), to get a `Box<T>`, `Arc<T>`, or `Rc<T>` by cloning from a `&T` where `T: CloneToUninit`.

The "Implement..." commits replace some ad-hoc conversions with `clone_from_ref` variants, which can be split out to a separate PR if desired.

This PR will conflict with https://github.com/rust-lang/rust/pull/148769 due to usage of `Layout::dangling` (which that PR is renaming to `dangling_ptr`), so they should not be rolled up together, and the one which merges later will need to be amended.
2025-11-26 18:21:00 +00:00
bjorn3
4627bff6e6 Show backtrace on allocation failures when possible
And if an allocation while printing the backtrace fails, don't try to
print another backtrace as that will never succeed.
2025-11-26 14:02:37 +00:00
U. Lasiotus
e1a805a68e Motor OS: make decode_error_kind more comprehensive 2025-11-24 21:17:20 -08:00
Matthew Maurer
17230eb5bb rustc_target: aarch64: Remove deprecated FEAT_TME
ARM has withdrawn FEAT_TME

https://developer.arm.com/documentation/102105/lb-05/

LLVM has dropped support for it recently as a result.
2025-11-25 00:43:01 +00:00