about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2025-04-09Rollup merge of #138869 - ChrisDenton:command-curdir, r=tgross35Matthias Krüger-4/+83
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-09update cfgsBoxy-5/+4
2025-04-09replace version placeholderBoxy-52/+52
2025-04-09Avoid verbatim paths in Command::current_dirChris Denton-4/+83
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-08clarify std::fs::set_permissions symlink behaviorbinarycat-6/+8
nest under platform-specific behavior, factor rationale into its own section, and tweak language.
2025-04-08std(docs): clarify how std::fs::set_permisions works with symlinksbinarycat-0/+13
fixes https://github.com/rust-lang/rust/issues/75942 fixes https://github.com/rust-lang/rust/issues/124201
2025-04-06Rollup merge of #138876 - thaliaarchi:trusty-stdio, r=NoratriebGuillaume Gomez-38/+49
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-05std: Fix build for NuttX targetsThalia Archibald-0/+3
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-05Rollup merge of #139121 - thaliaarchi:rename-thread_local-statik, r=NoratriebMatthias Krüger-3/+3
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-05Rollup merge of #139092 - thaliaarchi:move-fd-pal, r=joboetMatthias Krüger-31/+53
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-04Rename internal module from statik to no_threadsThalia Archibald-3/+3
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-05std: Add performance warnings to HashMap::get_disjoint_mutxizheyin-0/+3
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-04-04Fix unsafe_op_in_unsafe_fn for Unix fd and weakThalia Archibald-10/+14
2025-04-04Move fd into sysThalia Archibald-23/+41
2025-04-05Rollup merge of #137897 - xTachyon:tls-fix, r=thomcc,jieyouxuStuart Cook-0/+1
fix pthread-based tls on apple targets Tries to fix #127773.
2025-04-05Rollup merge of #136457 - calder:master, r=tgross35Stuart Cook-0/+1
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-04Expose algebraic floating point intrinsicsCalder Coalson-0/+1
2025-04-04Rollup merge of #139366 - RalfJung:ToSocketAddrs, r=jieyouxuMatthias Krüger-1/+1
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-04Update windows-bindgen to 0.61.0Chris Denton-28/+285
2025-04-04ToSocketAddrs: fix typoRalf Jung-1/+1
2025-04-04Rollup merge of #139295 - JakeWharton:jw.duplicate-anon-pipe.2025-04-02, ↵Matthias Krüger-1/+0
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-03Rollup merge of #139068 - a1phyr:less_uninit, r=joboetMatthias Krüger-2/+4
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-03std: clarify RwLock::get_mut more clearlyxizheyin-1/+3
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-04-02Remove creation of duplicate AnonPipeJake Wharton-1/+0
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-01Auto merge of #138928 - ChrisDenton:fix-uwp, r=tgross35bors-1/+1
Fix UWP reparse point check Fixes #138921
2025-04-01std: use the address of `errno` to identify threads in `unique_thread_exit`joboet-24/+21
Getting the address of `errno` should be just as cheap as `pthread_self()` and avoids having to use the expensive `Mutex` logic because it always results in a pointer.
2025-04-01io: Avoid Avoid marking bytes as uninit in `BufReader::peek`Benoît du Garreau-1/+0
2025-04-01io: Avoid marking buffer as uninit when copying to `BufWriter`Benoît du Garreau-1/+4
2025-03-31std: clarify Mutex::get_mut more clearlyxizheyin-1/+5
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-03-29Auto merge of #139119 - matthiaskrgr:rollup-7l2ri0f, r=matthiaskrgrbors-115/+190
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-29Rollup merge of #139081 - joboet:errno_dedup, r=NoratriebMatthias Krüger-0/+9
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-29Rollup merge of #138832 - ChrisDenton:with_native_path, r=joboetMatthias Krüger-115/+181
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-29Auto merge of #133572 - frank-king:feature/unique_arc, r=Amanieubors-0/+2
Implement `alloc::sync::UniqueArc` This implements the `alloc::sync::UniqueArc` part of #112566.
2025-03-29Start using with_native_path in std::sys::fsChris Denton-115/+181
2025-03-29std: make `cmath` functions safejoboet-125/+125
2025-03-29Rollup merge of #138988 - madsmtm:internal-weak-macro-syntax, r=ibraheemdevMatthias Krüger-80/+144
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-29Rollup merge of #138757 - rust-wasi-web:wasi-thread-stack-size, r=alexcrichtonMatthias Krüger-2/+2
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](https://github.com/rust-lang/rust/blob/38cf49dde8a5b0b284bb6dffd423d223c9f8f7a3/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-28Rollup merge of #139069 - a1phyr:better_take, r=joboetMatthias Krüger-4/+4
`io::Take`: avoid new `BorrowedBuf` creation in some case If `self.limit == buf.capacity()`, doing the whole `BorrowedBuf` dance is not necessary.
2025-03-28std: deduplicate `errno` accessesjoboet-0/+9
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`io::Take`: avoid new `BorrowedBuf` creation in some caseBenoît du Garreau-4/+4
2025-03-28Fix formatting nit in process.rsRafael Bachmann-1/+1
2025-03-27Rollup merge of #139021 - joboet:pre-vista-fallback, r=ChrisDentonJacob Pratt-22/+6
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-27Trusty: Implement write_vectored for stdioThalia Archibald-38/+49
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-27Auto merge of #138702 - m-ou-se:spawn-in-atexit, r=Mark-Simulacrumbors-9/+14
Allow spawning threads after TLS destruction Fixes #138696
2025-03-27std: get rid of pre-Vista fallback codejoboet-22/+6
We haven't had any Windows XP targets for a long while now...
2025-03-26Change the syntax of the internal `weak!` macroMads Marquart-80/+144
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-25Fix typo in error messageThalia Archibald-1/+1
2025-03-26#[allow(dead_code)]наб-3/+5
2025-03-25Rollup merge of #138875 - thaliaarchi:trusty-build, r=randomPoison,saethlinJacob Pratt-6/+14
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-25Fix UWP reparse point checkChris Denton-1/+1