Commit Graph

6735 Commits

Author SHA1 Message Date
Matthias Krüger
b9651d00d4
Rollup merge of #131646 - RalfJung:unix-miri-fallbacks, r=joboet
sys/unix: add comments for some Miri fallbacks
2024-10-13 18:27:21 +02:00
Ralf Jung
a87f5ca917 sys/unix: add comments for some Miri fallbacks 2024-10-13 12:35:06 +02:00
Ralf Jung
8d0a0b000c remove outdated comment now that Miri is on CI 2024-10-13 12:30:23 +02:00
Ralf Jung
2ae3b1b09a sys/windows: remove miri hack that is only needed for win7 2024-10-13 12:30:23 +02:00
Matthias Krüger
c0f16828a1
Rollup merge of #131503 - theemathas:stdin_read_line_docs, r=Mark-Simulacrum
More clearly document Stdin::read_line

These are common pitfalls for beginners, so I think it's worth making the subtleties more visible.
2024-10-12 23:00:57 +02:00
Trevor Gross
ca3c822068
Rollup merge of #131233 - joboet:stdout-before-main, r=tgross35
std: fix stdout-before-main

Fixes #130210.

Since #124881, `ReentrantLock` uses `ThreadId` to identify threads. This has the unfortunate consequence of breaking uses of `Stdout` before main: Locking the `ReentrantLock` that synchronizes the output will initialize the thread ID before the handle for the main thread is set in `rt::init`. But since that would overwrite the current thread ID, `thread::set_current` triggers an abort.

This PR fixes the problem by using the already initialized thread ID for constructing the main thread handle and allowing `set_current` calls that do not change the thread's ID.
2024-10-12 11:08:43 -05:00
joboet
9f91c5099f
std: fix stdout-before-main
Fixes #130210.

Since #124881, `ReentrantLock` uses `ThreadId` to identify threads. This has the unfortunate consequence of breaking uses of `Stdout` before main: Locking the `ReentrantLock` that synchronizes the output will initialize the thread ID before the handle for the main thread is set in `rt::init`. But since that would overwrite the current thread ID, `thread::set_current` triggers an abort.

This PR fixes the problem by using the already initialized thread ID for constructing the main thread handle and allowing `set_current` calls that do not change the thread's ID.
2024-10-12 13:01:36 +02:00
Trevor Gross
02cf62c596
Rollup merge of #130962 - nyurik:opts-libs, r=cuviper
Migrate lib's `&Option<T>` into `Option<&T>`

Trying out my new lint https://github.com/rust-lang/rust-clippy/pull/13336 - according to the [video](https://www.youtube.com/watch?v=6c7pZYP_iIE), this could lead to some performance and memory optimizations.

Basic thoughts expressed in the video that seem to make sense:
* `&Option<T>` in an API breaks encapsulation:
  * caller must own T and move it into an Option to call with it
  * if returned, the owner must store it as Option<T> internally in order to return it
* Performance is subject to compiler optimization, but at the basics, `&Option<T>` points to memory that has `presence` flag + value, whereas `Option<&T>` by specification is always optimized to a single pointer.
2024-10-11 23:57:44 -04:00
Tim (Theemathas) Chirananthavat
203573701a More clearly document Stdin::read_line
These are common pitfalls for beginners, so I think it's worth
making the subtleties more visible.
2024-10-10 23:12:03 +07:00
Kajetan Puchalski
335f67b652 rustc_target: Add sme-b16b16 as an explicit aarch64 target feature
LLVM 20 split out what used to be called b16b16 and correspond to aarch64
FEAT_SVE_B16B16 into sve-b16b16 and sme-b16b16.
Add sme-b16b16 as an explicit feature and update the codegen accordingly.
2024-10-10 10:24:57 +00:00
Matthias Krüger
7a76489454
Rollup merge of #131462 - cuviper:open_buffered-error, r=RalfJung
Mention allocation errors for `open_buffered`

This documents that `File::open_buffered` may return an error on allocation failure.
2024-10-09 23:03:50 +02:00
Matthias Krüger
866869bbbd
Rollup merge of #131449 - nickrum:wasip2-net-decouple-fd, r=alexcrichton
Decouple WASIp2 sockets from WasiFd

This is a follow up to #129638, decoupling WASIp2's socket implementation from WASIp1's `WasiFd` as discussed with `@alexcrichton.`

Quite a few trait implementations in `std::os::fd` rely on the fact that there is an additional layer of abstraction between `Socket` and `OwnedFd`. I thus had to add a thin `WasiSocket` wrapper struct that just "forwards" to `OwnedFd`. Alternatively, I could have added a lot of conditional compilation to `std::os::fd`, which feels even worse.

Since `WasiFd::sock_accept` is no longer accessible from `TcpListener` and since WASIp2 has proper support for accepting sockets through `Socket::accept`, the `std::os::wasi::net` module has been removed from WASIp2, which only contains a single `TcpListenerExt` trait with a `sock_accept` method as well as an implementation for `TcpListener`. Let me know if this is an acceptable solution.
2024-10-09 23:03:50 +02:00
Matthias Krüger
627d0b4067
Rollup merge of #130827 - fmease:library-mv-obj-save-dyn-compat, r=ibraheemdev
Library: Rename "object safe" to "dyn compatible"

Completed T-lang FCP: https://github.com/rust-lang/lang-team/issues/286#issuecomment-2338905118.
Tracking issue: https://github.com/rust-lang/rust/issues/130852

Regarding https://github.com/rust-lang/rust/labels/relnotes, I guess I will manually open a https://github.com/rust-lang/rust/labels/relnotes-tracking-issue since this change affects everything (compiler, library, tools, docs, books, everyday language).

r? ghost
2024-10-09 23:03:47 +02:00
Josh Stone
7b52e6bc47 Mention allocation errors for open_buffered 2024-10-09 12:43:23 -07:00
León Orell Valerian Liehr
e08dc0491a
Library: Rename "object safe" to "dyn compatible" 2024-10-09 18:48:29 +02:00
Nicola Krumschmidt
01e248ff97
Decouple WASIp2 sockets from WasiFd 2024-10-09 14:39:28 +02:00
Yuri Astrakhan
a278f15724 Update library/std/src/sys/pal/unix/process/process_vxworks.rs
Co-authored-by: Josh Stone <cuviper@gmail.com>
2024-10-08 23:26:30 -04:00
Yuri Astrakhan
442d766cc1 fix ref in process_vxworks.rs 2024-10-08 23:26:30 -04:00
Yuri Astrakhan
d2f93c9707 Update library/std/src/sys/pal/unix/process/process_unix.rs
Co-authored-by: Josh Stone <cuviper@gmail.com>
2024-10-08 23:26:30 -04:00
Yuri Astrakhan
f2d1edfea5 Change a few &Option<T> into Option<&T> 2024-10-08 23:26:29 -04:00
Stuart Cook
5c1c49a0c4
Rollup merge of #131308 - mati865:gnullvm-f16-f128, r=tgross35
enable f16 and f128 on windows-gnullvm targets

Continuation of https://github.com/rust-lang/rust/pull/130959
2024-10-07 15:37:07 +11:00
Matthias Krüger
9e8c03018f
Rollup merge of #131307 - YohDeadfall:prctl-set-name-dbg-assert, r=workingjubilee
Android: Debug assertion after setting thread name

While `prctl` cannot fail if it points to a valid buffer, it's still better to assert the result as it's done for other places.
2024-10-06 20:43:40 +02:00
Trevor Gross
7c0c511933 Update compiler-builtins to 0.1.133
This includes [1], which should help resolve an infinite recusion issue
on WASM and SPARC (possibly other platforms). See [2] and [3] for
further details.

[1]: https://github.com/rust-lang/compiler-builtins/pull/708
[2]: https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/sparc-unknown-none-elf.20regresssion.20between.20compiler-built.2E.2E.2E
[3]: https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/.5Bwasm32.5D.20Infinite.20recursion.20.60compiler-builtins.60.20.60__multi3.60
2024-10-05 21:34:51 -05:00
Mateusz Mikuła
9d2495db60 enable f16 and f128 on windows-gnullvm targets 2024-10-05 23:55:39 +02:00
Yoh Deadfall
2223328d16 Android: Debug assertion after setting thread name 2024-10-05 21:29:40 +03:00
bors
2b21f90d5e Auto merge of #131221 - XrXr:bump-compiler-builtins, r=tgross35
Update compiler-builtins to 0.1.132

This commit updates compiler-builtins from 0.1.130 to 0.1.132.

PRs in the delta:
 - rust-lang/compiler-builtins#698
 - rust-lang/compiler-builtins#699
 - rust-lang/compiler-builtins#701
 - rust-lang/compiler-builtins#704
 - rust-lang/compiler-builtins#627
 - rust-lang/compiler-builtins#706
2024-10-05 17:07:21 +00:00
Matthias Krüger
92beb42f64
Rollup merge of #131094 - joboet:lazy_once_box, r=ibraheemdev
std: replace `LazyBox` with `OnceBox`

This PR replaces the `LazyBox` wrapper used to allocate the pthread primitives with `OnceBox`, which has a more familiar API mirroring that of `OnceLock`. This cleans up the code in preparation for larger changes like #128184 (from which this PR was split) and allows some neat optimizations, like avoid an acquire-load of the allocation pointer in `Mutex::unlock`, where the initialization of the allocation must have already been observed.

Additionally, I've gotten rid of the TEEOS `Condvar` code, it's just a duplicate of the pthread one anyway and I didn't want to repeat myself.
2024-10-05 13:15:57 +02:00
Alan Wu
b955480d05 Update compiler-builtins to 0.1.132
This commit updates compiler-builtins from 0.1.130 to 0.1.132.

PRs in the delta:
 - rust-lang/compiler-builtins#698
 - rust-lang/compiler-builtins#699
 - rust-lang/compiler-builtins#701
 - rust-lang/compiler-builtins#704
 - rust-lang/compiler-builtins#627
 - rust-lang/compiler-builtins#706
2024-10-04 18:50:30 -04:00
okaneco
e08002f6d0 Stabilize BufRead::skip_until 2024-10-04 14:56:15 -04:00
Matthias Krüger
aedf14bb0c
Rollup merge of #131163 - JakenHerman:master, r=Nadrieril
Add `get_line` confusable to `Stdin::read_line()`

This pull request resolves https://github.com/rust-lang/rust/issues/131091

---

I've updated tests for `tests/ui/attributes/rustc_confusables_std_cases` in order to verify this change is working as intended.

Before I submitted this pull request, I had a pull request to my local fork. If you're interested in seeing the conversation on that PR, go to https://github.com/JakenHerman/rust/pull/1.

---

**Testing**:
Run `./x.py test tests/ui/attributes/rustc_confusables_std_cases.rs`
2024-10-03 13:47:59 +02:00
bors
f7c8928f03 Auto merge of #128711 - clarfonthey:default-iters-hash, r=dtolnay
impl `Default` for `HashMap`/`HashSet` iterators that don't already have it

This is a follow-up to #128261 that isn't included in that PR because it depends on:

* [x] rust-lang/hashbrown#542 (`Default`)
* [x] `hashbrown` release containing above

It also wasn't included in #128261 initially and should have its own FCP, since these are also insta-stable.

Changes added:

* `Default for hash_map::{Iter, IterMut, IntoIter, IntoKeys, IntoValues, Keys, Values, ValuesMut}`
* `Default for hash_set::{Iter, IntoIter}`

Changes that were added before FCP, but are being deferred to later:

* `Clone for hash_map::{IntoIter, IntoKeys, IntoValues} where K: Clone, V: Clone`
* `Clone for hash_set::IntoIter where K: Clone`
2024-10-03 08:44:51 +00:00
Jaken Herman
4b48d72eaa Add get_line confusable to Stdin::read_line()
Add tests for addition of `#[rustc_confusables("get_line")]`
2024-10-02 23:19:26 -05:00
ltdk
11f738fcb2 impl Default for Hash{Map,Set} iterators that don't already have it 2024-10-02 23:43:48 -04:00
bors
fd1f8aa05d Auto merge of #127912 - joboet:tls_dtor_thread_current, r=cuviper
std: make `thread::current` available in all `thread_local!` destructors

... and thereby allow the panic runtime to always print the right thread name.

This works by modifying the TLS destructor system to schedule a runtime cleanup function after all other TLS destructors registered by `std` have run. Unfortunately, this doesn't affect foreign TLS destructors, `thread::current` will still panic there.

Additionally, the thread ID returned by `current_id` will now always be available, even inside the global allocator, and will not change during the lifetime of one thread (this was previously the case with key-based TLS).

The mechanisms I added for this (`local_pointer` and `thread_cleanup`) will also allow finally fixing #111272 by moving the signal stack to a similar runtime-cleanup TLS variable.
2024-10-03 03:31:47 +00:00
bors
ad9c494835 Auto merge of #131148 - Urgau:hashbrown-0.15, r=Amanieu
Update hashbrown to 0.15 and adjust some methods

This PR updates `hashbrown` to 0.15 in the standard library and adjust some methods as well as removing some as they no longer exists in Hashbrown it-self.

 - `HashMap::get_many_mut` change API to return array-of-Option
 - `HashMap::{replace_entry, replace_key}` are removed, FCP close [already finished](https://github.com/rust-lang/rust/issues/44286#issuecomment-2293825619)
 - `HashSet::get_or_insert_owned` is removed as it no longer exists in hashbrown

Closes https://github.com/rust-lang/rust/issues/44286
r? `@Amanieu`
2024-10-03 00:44:26 +00:00
joboet
d868fdce6b
std: make thread::current available in all thread_local! destructors 2024-10-02 18:04:21 +02:00
Urgau
8760a401bd Update hashbrown to 0.15 and adjust some methods
as well as removing some from std as they no longer
exists in Hashbrown it-self.
2024-10-02 09:44:51 +02:00
Ralf Jung
9fa120593e mpmc doctest: make sure main thread waits for child threads 2024-10-02 08:00:17 +02:00
joboet
c1acccdf17
std: replace LazyBox with OnceBox
This PR replaces the `LazyBox` wrapper used to allocate the pthread primitives with `OnceBox`, which has a more familiar API mirroring that of `OnceLock`. This cleans up the code in preparation for larger changes like #128184 (from which this PR was split) and allows some neat optimizations, like avoid an acquire-load of the allocation pointer in `Mutex::unlock`, where the initialization of the allocation must have already been observed.

Additionally, I've gotten rid of the TEEOS `Condvar` code, it's just a duplicate of the pthread one anyway and I didn't want to repeat myself.
2024-10-01 22:05:35 +02:00
bors
c817d5dc20 Auto merge of #131098 - GuillaumeGomez:rollup-kk74was, r=GuillaumeGomez
Rollup of 5 pull requests

Successful merges:

 - #130630 (Support clobber_abi and vector/access registers (clobber-only) in s390x inline assembly)
 - #131042 (Instantiate binders in `supertrait_vtable_slot`)
 - #131079 (Update wasm-component-ld to 0.5.9)
 - #131085 (make test_lots_of_insertions test take less long in Miri)
 - #131088 (add fixme to remove LLVM_ENABLE_TERMINFO when minimal llvm version is 19)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-10-01 16:32:19 +00:00
Guillaume Gomez
b9263c6b9f
Rollup merge of #131085 - RalfJung:miri-slow-test, r=tgross35
make test_lots_of_insertions test take less long in Miri

This is by far the slowest `std` test in Miri, taking >2min in https://github.com/rust-lang/miri-test-libstd CI. So let's make this `count` smaller. The runtime should be quadratic in `count` so reducing it to around 2/3 of it's previous value should cut the total time down to less than half -- making it still the slowest test, but by less of a margin. (And this way we still insert >64 elements into the HashMap, in case that power of 2 matters.)
2024-10-01 17:32:09 +02:00
bors
8dd5cd0bc1 Auto merge of #126839 - obeis:mpmc, r=Amanieu
Add multi-producer, multi-consumer channel (mpmc)

Closes #125712

Tracking issue: #126840

r? m-ou-se
2024-10-01 13:35:16 +00:00
Ralf Jung
4529b86196 make test_lots_of_insertions test take less long in Miri 2024-10-01 11:03:05 +02:00
Trevor Gross
6b09a93566 Enable f16 tests on non-GNU Windows
There is a MinGW ABI bug that prevents `f16` and `f128` from being
usable on `windows-gnu` targets. This does not affect MSVC; however, we
have `f16` and `f128` tests disabled on all Windows targets.

Update the gating to only affect `windows-gnu`, which means `f16` tests
will be enabled. There is no effect for `f128` since the default
fallback is `false`.
2024-09-30 22:41:19 -04:00
Trevor Gross
40d0ada909
Rollup merge of #130961 - tgross35:f16-x86-apple, r=thomcc
Enable `f16` tests on x86 Apple platforms

These were disabled because Apple uses a special ABI for `f16`. `compiler-builtins` merged a fix for this in [1], which has since propagated to rust-lang/rust. Enable tests since there should be no remaining issues on these platforms.

[1]: https://github.com/rust-lang/compiler-builtins/pull/675

try-job: x86_64-apple-1
try-job: x86_64-apple-2
2024-09-30 19:18:50 -04:00
Trevor Gross
2fe41869c9
Rollup merge of #130914 - compiler-errors:insignificant-dtor, r=Amanieu
Mark some more types as having insignificant dtor

These were caught by https://github.com/rust-lang/rust/pull/129864#issuecomment-2376658407, which is implementing a lint for some changes in drop order for temporaries in tail expressions.

Specifically, the destructors of `CString` and the bitpacked repr for `std::io::Error` are insignificant insofar as they don't have side-effects on things like locking or synchronization; they just free memory.

See some discussion on #89144 for what makes a drop impl "significant"
2024-09-30 19:18:50 -04:00
Trevor Gross
b70654199a
Rollup merge of #129638 - nickrum:wasip2-net, r=alexcrichton
Hook up std::net to wasi-libc on wasm32-wasip2 target

One of the improvements of the `wasm32-wasip2` target over `wasm32-wasip1` is better support for networking. Right now, p2 is just re-using the `std::net` implementation from p1. This PR adds a new net module for p2 that makes use of net from `sys_common` and calls wasi-libc functions directly.

There are currently a few limitations:

- Duplicating a socket is not supported by WASIp2 (directly returns an error)
- Peeking is not yet implemented in wasi-libc (we could let wasi-libc handle this, but I opted to directly return an error instead)
- Vectored reads/writes are not supported by WASIp2 (the necessary functions are available in wasi-libc, but they call WASIp1 functions which do not support sockets, so I opted to directly return an error instead)
- Getting/setting `TCP_NODELAY` is faked in wasi-libc (uses the fake implementation instead of returning an error)
- Getting/setting `SO_LINGER` is not supported by WASIp2 (directly returns an error)
- Setting `SO_REUSEADDR` is faked in wasi-libc (since this is done from `sys_common`, the fake implementation is used instead of returning an error)
- Getting/setting `IPV6_V6ONLY` is not supported by WASIp2 and will always be set for IPv6 sockets (since this is done from `sys_common`, wasi-libc will return an error)
- UDP broadcast/multicast is not supported by WASIp2 (since this is configured from `sys_common`, wasi-libc will return appropriate errors)
- The `MSG_NOSIGNAL` send flag is a no-op because there are no signals in WASIp2 (since explicitly setting this flag would require a change to `sys_common` and the result would be exactly the same, I opted to not set it)

Do those decisions make sense?

While working on this PR, I noticed that there is a `std::os::wasi::net::TcpListenerExt` trait that adds a `sock_accept()` method to `std::net::TcpListener`. Now that WASIp2 supports standard accept, would it make sense to remove this?

cc `@alexcrichton`
2024-09-30 19:18:49 -04:00
Obei Sideg
041e76b7cd
Add multi-producer, multi-consumer channel (mpmc) 2024-09-30 20:43:51 +03:00
Guillaume Gomez
ee8ca3aa6c
Rollup merge of #130743 - YohDeadfall:net-nonblocking-doc, r=Mark-Simulacrum
Clarifications for set_nonblocking methods

Closes #129903.

The issue mentions that `send`, `recv` and other operations are interpreted by some users as methods of `TcpSocket` which led to confusion since it hasn't them. To fix it I added "system" into the documentation as being more precise for two reasons:
* it's makes it clear that these names are system operations;
* it doesn't point to the location of these methods like `libc` because not every system is POSIX compatible.
2024-09-29 12:37:52 +02:00
bors
9903b256a2 Auto merge of #128321 - BatmanAoD:catch-unwind-doc-update, r=Mark-Simulacrum
Update `catch_unwind` doc comments for `c_unwind`

Updates `catch_unwind` doc comments to indicate that catching a foreign exception _will no longer_ be UB. Instead, there are two possible behaviors, though it is not specified which one an implementation will choose.

Nominated for t-lang to confirm that they are okay with making such a promise based on t-opsem FCP, or whether they would like to be included in the FCP.

Related: https://github.com/rust-lang/rust/issues/74990, https://github.com/rust-lang/rust/issues/115285, https://github.com/rust-lang/reference/pull/1226
2024-09-29 05:54:47 +00:00