about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2024-03-11Auto merge of #122331 - jhpratt:rollup-cbl8xsy, r=jhprattbors-21/+45
Rollup of 9 pull requests Successful merges: - #121148 (Add slice::try_range) - #121633 (Win10: Use `GetSystemTimePreciseAsFileTime` directly) - #121840 (Expose the Freeze trait again (unstably) and forbid implementing it manually) - #121907 (skip sanity check for non-host targets in `check` builds) - #122002 (std::threads: revisit stack address calculation on netbsd.) - #122108 (Add `target.*.runner` configuration for targets) - #122298 (RawVec::into_box: avoid unnecessary intermediate reference) - #122315 (Allow multiple `impl Into<{D,Subd}iagMessage>` parameters in a function.) - #122326 (Optimize `process_heap_alloc`) r? `@ghost` `@rustbot` modify labels: rollup
2024-03-11Rollup merge of #122326 - Zoxc:win-alloc-tweak, r=ChrisDentonJacob Pratt-19/+36
Optimize `process_heap_alloc` This optimizes `process_heap_alloc` introduced in https://github.com/rust-lang/rust/pull/120205. From: ``` .text:0000000180027ED0 ; std::sys::pal::windows::alloc::process_heap_alloc::h703a613b3e25ff93 .text:0000000180027ED0 public _ZN3std3sys3pal7windows5alloc18process_heap_alloc17h703a613b3e25ff93E .text:0000000180027ED0 _ZN3std3sys3pal7windows5alloc18process_heap_alloc17h703a613b3e25ff93E proc near .text:0000000180027ED0 ; CODE XREF: std::sys::pal::common::alloc::realloc_fallback::hc4c96b4c24d03e77+23↑p .text:0000000180027ED0 ; std::sys::pal::common::alloc::realloc_fallback::hc4c96b4c24d03e77+55↑p ... .text:0000000180027ED0 push rsi .text:0000000180027ED1 push rdi .text:0000000180027ED2 sub rsp, 28h .text:0000000180027ED6 mov rsi, rdx .text:0000000180027ED9 mov edi, ecx .text:0000000180027EDB mov rcx, cs:_ZN3std3sys3pal7windows5alloc4HEAP17hb53ca4010cc29b62E ; std::sys::pal::windows::alloc::HEAP::hb53ca4010cc29b62 .text:0000000180027EE2 test rcx, rcx .text:0000000180027EE5 jnz short loc_180027EFC .text:0000000180027EE7 call cs:__imp_GetProcessHeap .text:0000000180027EED test rax, rax .text:0000000180027EF0 jz short loc_180027F0E .text:0000000180027EF2 mov rcx, rax .text:0000000180027EF5 mov cs:_ZN3std3sys3pal7windows5alloc4HEAP17hb53ca4010cc29b62E, rax ; std::sys::pal::windows::alloc::HEAP::hb53ca4010cc29b62 .text:0000000180027EFC .text:0000000180027EFC loc_180027EFC: ; CODE XREF: std::sys::pal::windows::alloc::process_heap_alloc::h703a613b3e25ff93+15↑j .text:0000000180027EFC mov edx, edi .text:0000000180027EFE mov r8, rsi .text:0000000180027F01 add rsp, 28h .text:0000000180027F05 pop rdi .text:0000000180027F06 pop rsi .text:0000000180027F07 jmp cs:__imp_HeapAlloc .text:0000000180027F0E ; --------------------------------------------------------------------------- .text:0000000180027F0E .text:0000000180027F0E loc_180027F0E: ; CODE XREF: std::sys::pal::windows::alloc::process_heap_alloc::h703a613b3e25ff93+20↑j .text:0000000180027F0E xor eax, eax .text:0000000180027F10 add rsp, 28h .text:0000000180027F14 pop rdi .text:0000000180027F15 pop rsi .text:0000000180027F16 retn .text:0000000180027F16 _ZN3std3sys3pal7windows5alloc18process_heap_alloc17h703a613b3e25ff93E endp ``` to ``` .text:0000000180027EE0 ; std::sys::pal::windows::alloc::process_heap_alloc::h70f9d61a631e5c16 .text:0000000180027EE0 public _ZN3std3sys3pal7windows5alloc18process_heap_alloc17h70f9d61a631e5c16E .text:0000000180027EE0 _ZN3std3sys3pal7windows5alloc18process_heap_alloc17h70f9d61a631e5c16E proc near .text:0000000180027EE0 ; CODE XREF: std::sys::pal::common::alloc::realloc_fallback::hc4c96b4c24d03e77+23↑p .text:0000000180027EE0 ; std::sys::pal::common::alloc::realloc_fallback::hc4c96b4c24d03e77+54↑p ... .text:0000000180027EE0 mov rcx, cs:_ZN3std3sys3pal7windows5alloc4HEAP17hb53ca4010cc29b62E ; std::sys::pal::windows::alloc::HEAP::hb53ca4010cc29b62 .text:0000000180027EE7 test rcx, rcx .text:0000000180027EEA jz short loc_180027EF3 .text:0000000180027EEC jmp cs:__imp_HeapAlloc .text:0000000180027EF3 ; --------------------------------------------------------------------------- .text:0000000180027EF3 .text:0000000180027EF3 loc_180027EF3: ; CODE XREF: std::sys::pal::windows::alloc::process_heap_alloc::h70f9d61a631e5c16+A↑j .text:0000000180027EF3 mov ecx, edx .text:0000000180027EF5 mov rdx, r8 .text:0000000180027EF8 jmp std__sys__pal__windows__alloc__process_heap_init_and_alloc .text:0000000180027EF8 _ZN3std3sys3pal7windows5alloc18process_heap_alloc17h70f9d61a631e5c16E endp ``` r? `@ChrisDenton`
2024-03-11Rollup merge of #122002 - devnexen:thread_stack_netbsd_fix, ↵Jacob Pratt-2/+3
r=workingjubilee,riastradh std::threads: revisit stack address calculation on netbsd. like older linux glibc versions, we need to get the guard size and increasing the stack's bottom address accordingly.
2024-03-11Rollup merge of #121633 - ChrisDenton:precise, r=NilstriebJacob Pratt-0/+6
Win10: Use `GetSystemTimePreciseAsFileTime` directly On Windows 10 we can use `GetSystemTimePreciseAsFileTime` directly instead of lazy loading it (with a fallback).
2024-03-11Auto merge of #117156 - jmillikin:os-unix-socket-ext, r=Amanieu,dtolnaybors-138/+246
Convert `Unix{Datagram,Stream}::{set_}passcred()` to per-OS traits These methods are the pre-stabilized API for obtaining peer credentials from an `AF_UNIX` socket, part of the `unix_socket_ancillary_data` feature. Their current behavior is to get/set one of the `SO_PASSCRED` (Linux), `LOCAL_CREDS_PERSISTENT` (FreeBSD), or `LOCAL_CREDS` (NetBSD) socket options. On other targets the `{set_}passcred()` methods do not exist. There are two problems with this approach: 1. Having public methods only exist for certain targets isn't permitted in a stable `std` API. 2. These options have generally similar purposes, but they are non-POSIX and their details can differ in subtle and surprising ways (such as whether they continue to be set after the next call to `recvmsg()`). Splitting into OS-specific extension traits is the preferred solution to both problems.
2024-03-11Optimize `process_heap_alloc`John Kåre Alsaker-19/+36
2024-03-10Rollup merge of #122276 - RalfJung:io-read, r=NilstriebMatthias Krüger-10/+7
io::Read trait: make it more clear when we are adressing implementations vs callers Inspired by [this](https://github.com/rust-lang/rust/issues/72186#issuecomment-1987076295) comment. For some reason we only have that `buf` warning in `read` and `read_exact`, even though it affects a bunch of other functions of this trait as well. It doesn't seem worth copy-pasting the same text everywhere though so I did not change this.
2024-03-10Rollup merge of #122275 - RalfJung:std-oom, r=workingjubileeMatthias Krüger-0/+2
disable OOM test in Miri Needed for https://github.com/rust-lang/miri-test-libstd
2024-03-10Rollup merge of #121942 - devnexen:getrandom_for_dfbsd, r=joboetMatthias Krüger-1/+9
std::rand: enable getrandom for dragonflybsd too.
2024-03-10Rollup merge of #113525 - workingjubilee:handle-dynamic-minsigstksz, r=m-ou-seMatthias Krüger-11/+39
Dynamically size sigaltstk in std On modern Linux with Intel AMX and 1KiB matrices, Arm SVE with potentially 2KiB vectors, and RISCV Vectors with up to 16KiB vectors, we must handle dynamic signal stack sizes. We can do so unconditionally by using getauxval, but assuming it may return 0 as an answer, thus falling back to the old constant if needed. Fixes https://github.com/rust-lang/rust/issues/107795
2024-03-10Rollup merge of #112136 - clarfonthey:ffi-c_str, r=cuviperMatthias Krüger-6/+46
Add std::ffi::c_str module ACP: rust-lang/libs-team#134 `std::ffi` docs before change: ![Structs: VaList, VaListImpl, CStr, CString, FromBytesWithNulError, FromVecWithNulError, IntoStringError, NulError, OsStr, OsString](https://github.com/rust-lang/rust/assets/15850505/b2cf3534-30f9-4ef0-a655-bacdc3a19e17) `std::ffi` docs after change: ![Re-exports: self::c_str::{FromBytesWithNulError, FromBytesUntilNulError, FromVecWithNulError, NulError, IntoStringError} ; Modules: c_str ; Structs: VaList, VaListImpl, CStr, CString, OsStr, OsString](https://github.com/rust-lang/rust/assets/15850505/23aa6964-da7a-4942-bbf7-42bde2146f9e) (note: I'm omitting the `c_int`, etc. stuff from the screenshots since it's the same in both. this doesn't just delete those types)
2024-03-10io::Read trait: make it more clear when we are adressing implementations vs ↵Ralf Jung-10/+7
callers
2024-03-10disable OOM test in MiriRalf Jung-0/+2
2024-03-09Rollup merge of #121711 - ChrisDenton:junction, r=Mark-SimulacrumGuillaume Boisseau-81/+86
Implement junction_point Implements https://github.com/rust-lang/rust/issues/121709 We already had a private implementation that we use for tests so we could just make that public. Except it was very hacky as it was only ever intended for use in testing. I've made an improved version that at least handles path conversion correctly and has less need for things like the `Align8` hack. There's still room for further improvement though.
2024-03-09Rollup merge of #121403 - kornelski:io-oom, r=dtolnayGuillaume Boisseau-9/+31
impl From<TryReserveError> for io::Error There's an obvious mapping between these two errors, and it makes I/O code less noisy. I've chosen to use simple `ErrorKind::OutOfMemory` `io::Error`, without keeping `TryReserveError` for the `source()`, because: * It matches current uses in libstd, * `ErrorData::Custom` allocates, which is a risky proposition for handling OOM errors specifically. * Currently `TryReserveError` has no public fields/methods, so it's usefulness is limited. How allocators should report errors, especially custom and verbose ones is still an open question. Just in case I've added note in the doccomment that this may change. The compiler forced me to declare stability of this impl. I think this implementation is simple enough that it doesn't need full-blown stabilization period, and I've marked it for the next release, but of course I can adjust the attribute if needed.
2024-03-09Rollup merge of #114655 - nbdd0121:io-safety, r=dtolnayGuillaume Boisseau-10/+10
Make `impl<Fd: AsFd>` impl take `?Sized` `@rustbot` labels: +T-libs-api +needs-fcp
2024-03-09Rollup merge of #99153 - Dajamante:issue/95622, r=dtolnayGuillaume Boisseau-0/+26
Add Read Impl for &Stdin r? `@oli-obk` fixes #95622
2024-03-09Avoid closing invalid handlesdylni-21/+47
2024-03-09Auto merge of #122095 - lukas-code:windows-shutdown-test, r=ChrisDentonbors-15/+18
fix `close_read_wakes_up` test On windows, `shutdown` does not interrupt `read`, even though we document that it does (see https://github.com/rust-lang/rust/issues/121594). The `close_read_wakes_up` test has a race condition and only passes on windows if the `shutdown` happens before the `read`. This PR ignores the test on windows adds a sleep to make it more likely that the `read` happens before the `shutdown` and the test actually tests what it is supposed to test on other platforms. I'm submitting this before any docs changes, so that we can find out on what platforms `shutdown` actually works as documented. r? `@ChrisDenton`
2024-03-08further changes from feedbackDavid Carlier-19/+1
2024-03-08Document overrides of `clone_from()`Noa-2/+14
Specifically, when an override doesn't just forward to an inner type, document the behavior and that it's preferred over simply assigning a clone of source. Also, change instances where the second parameter is "other" to "source".
2024-03-08Rollup merge of #121938 - blyxxyz:quadratic-vectored-write, r=AmanieuMatthias Krüger-31/+50
Fix quadratic behavior of repeated vectored writes Some implementations of `Write::write_vectored` in the standard library (`BufWriter`, `LineWriter`, `Stdout`, `Stderr`) check all buffers to calculate the total length. This is O(n) over the number of buffers. It's common that only a limited number of buffers is written at a time (e.g. 1024 for `writev(2)`). `write_vectored_all` will then call `write_vectored` repeatedly, leading to a runtime of O(n²) over the number of buffers. This fix is to only calculate as much as needed if it's needed. Here's a test program: ```rust #![feature(write_all_vectored)] use std::fs::File; use std::io::{BufWriter, IoSlice, Write}; use std::time::Instant; fn main() { let buf = vec![b'\0'; 100_000_000]; let mut slices: Vec<IoSlice<'_>> = buf.chunks(100).map(IoSlice::new).collect(); let mut writer = BufWriter::new(File::create("/dev/null").unwrap()); let start = Instant::now(); write_smart(&slices, &mut writer); println!("write_smart(): {:?}", start.elapsed()); let start = Instant::now(); writer.write_all_vectored(&mut slices).unwrap(); println!("write_all_vectored(): {:?}", start.elapsed()); } fn write_smart(mut slices: &[IoSlice<'_>], writer: &mut impl Write) { while !slices.is_empty() { // Only try to write as many slices as can be written let res = writer .write_vectored(slices.get(..1024).unwrap_or(slices)) .unwrap(); slices = &slices[(res / 100)..]; } } ``` Before this change: ``` write_smart(): 6.666952ms write_all_vectored(): 498.437092ms ``` After this change: ``` write_smart(): 6.377158ms write_all_vectored(): 6.923412ms ``` `LineWriter` (and by extension `Stdout`) isn't fully repaired by this because it looks for newlines. I could open an issue for that after this is merged, I think it's fixable but not trivially.
2024-03-08Rollup merge of #118623 - haydonryan:master, r=workingjubileeMatthias Krüger-4/+4
Improve std::fs::read_to_string example Resolves [#118621](https://github.com/rust-lang/rust/issues/118621) For the original code to succeed it requires address.txt to contain a socketaddress, however it is much easier to follow if this is just any strong - eg address could be a street address or just text. Also changed the variable name from "foo" to something more meaningful as cargo clippy warns you against using foo as a placeholder. ``` $ cat main.rs use std::fs; use std::error::Error; fn main() -> Result<(), Box<dyn Error>> { let addr: String = fs::read_to_string("address.txt")?.parse()?; println!("{}", addr); Ok(()) } $ cat address.txt 123 rusty lane san francisco 94999 $ cargo run Finished dev [unoptimized + debuginfo] target(s) in 0.00s Running `/home/haydon/workspace/rust-test-pr/tester/target/debug/tester` 123 rusty lane san francisco 94999 ```
2024-03-07Rollup merge of #122147 - kadiwa4:private_impl_mods, r=workingjubileeGuillaume Gomez-48/+44
Make `std::os::unix::ucred` module private Tracking issue: #42839 Currently, this unstable module exists: [`std::os::unix::ucred`](https://doc.rust-lang.org/stable/std/os/unix/ucred/index.html). All it does is provide `UCred` (which is also available from `std::os::unix::net`), `impl_*` (which is probably a mishap and should be private) and `peer_cred` (which is undocumented but has a documented counterpart at `std::os::unix::net::UnixStream::peer_cred`). This PR makes the entire `ucred` module private and moves it into `net`, because that's where it is used. I hope it's fine to simply remove it without a deprecation phase. Otherwise, I can add back a deprecated reexport module `std::os::unix::ucred`. `@rustbot` label: -T-libs +T-libs-api
2024-03-07make `std::os::unix::ucred` module privateKalle Wachsmuth-48/+44
2024-03-07Rust is a proper name: rust → RustRalf Jung-11/+11
2024-03-07Auto merge of #122113 - matthiaskrgr:rollup-5d1jnwi, r=matthiaskrgrbors-0/+1
Rollup of 9 pull requests Successful merges: - #121958 (Fix redundant import errors for preload extern crate) - #121976 (Add an option to have an external download/bootstrap cache) - #122022 (loongarch: add frecipe and relax target feature) - #122026 (Do not try to format removed files) - #122027 (Uplift some feeding out of `associated_type_for_impl_trait_in_impl` and into queries) - #122063 (Make the lowering of `thir::ExprKind::If` easier to follow) - #122074 (Add missing PartialOrd trait implementation doc for array) - #122082 (remove outdated fixme comment) - #122091 (Note why we're using a new thread in `test_get_os_named_thread`) r? `@ghost` `@rustbot` modify labels: rollup
2024-03-06Document and test minimal stack size on WindowsChris Denton-0/+15
2024-03-06Dynamically size sigaltstk in stdJubilee Young-11/+39
On modern Linux with Intel AMX and 1KiB matrices, Arm SVE with potentially 2KiB vectors, and RISCV Vectors with up to 16KiB vectors, we must handle dynamic signal stack sizes. We can do so unconditionally by using getauxval, but assuming it may return 0 as an answer, thus falling back to the old constant if needed.
2024-03-06fix `close_read_wakes_up` testLukas Markeffsky-15/+18
2024-03-06Note why we're using a new thread in a testChris Denton-0/+1
2024-03-06Remove unnecessary fixmeChris Denton-5/+0
As the FIXME itself notes, there's nothing to fix here.
2024-03-06Be stricter with `copy_file_range` probe resultsTobias Bucher-33/+35
2024-03-06Auto merge of #121956 - ChrisDenton:srwlock, r=joboetbors-30/+136
Windows: Implement condvar, mutex and rwlock using futex Well, the Windows equivalent: [`WaitOnAddress`,](https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-waitonaddress) [`WakeByAddressSingle`](https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-wakebyaddresssingle) and [`WakeByAddressAll`](https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-wakebyaddressall). Note that Windows flavoured futexes can be different sizes (1, 2, 4 or 8 bytes). I took advantage of that in the `Mutex` implementation. I also edited the Mutex implementation a bit more than necessary. I was having trouble keeping in my head what 0, 1 and 2 meant so I replaced them with consts. I *think* we're maybe spinning a bit much. `WaitOnAddress` seems to be looping quite a bit too. But for now I've keep the implementations the same. I do wonder if it'd be worth reducing or removing our spinning on Windows. This also adds a new shim to miri, because of course it does. Fixes #121949
2024-03-06Less syscalls for the `copy_file_range` probeTobias Bucher-23/+48
If it's obvious from the actual syscall results themselves that the syscall is supported or unsupported, don't do an extra syscall with an invalid file descriptor. CC #122052
2024-03-06unix time module now return resultAntoine PLASKOWSKI-51/+35
2024-03-05Add `Waitable` traitChris Denton-10/+43
2024-03-05Windows: Implement mutex using futexChris Denton-30/+103
Well, the Windows equivalent: `WaitOnAddress`, `WakeByAddressSingle` and `WakeByAddressAll`.
2024-03-04std::threads: revisit stack address calculation on netbsd.David Carlier-2/+21
like older linux glibc versions, we need to get the guard size and increasing the stack's bottom address accordingly.
2024-03-04Don't run test_get_os_named_thread on win7roblabla-1/+1
This test won't work on windows 7, as the Thread::set_name function is not implemented there (win7 does not provide a documented mechanism to set thread names).
2024-03-03std::rand: enable getrandom for dragonflybsd too.David Carlier-1/+9
2024-03-03Fix quadratic behavior of repeated vectored writesJan Verbeek-31/+50
Some implementations of `Write::write_vectored` in the standard library (`BufWriter`, `LineWriter`, `Stdout`, `Stderr`) check all buffers to calculate the total length. This is O(n) over the number of buffers. It's common that only a limited number of buffers is written at a time (e.g. 1024 for `writev(2)`). `write_vectored_all` will then call `write_vectored` repeatedly, leading to a runtime of O(n²) over the number of buffers. The fix is to only calculate as much as needed if it's needed.
2024-03-03Add missing get_name for wasm::thread.Ian Neumann-0/+4
2024-03-03Auto merge of #121856 - ChrisDenton:abort, r=joboetbors-10/+13
Cleanup windows `abort_internal` As the comments on the functions say, we define abort in both in panic_abort and in libstd. This PR makes the two implementation (mostly) the same. Additionally it: * uses `options(noreturn)` on the asm instead of using `core::intrinsics::unreachable`. * removed unnecessary allow lints * added `FAST_FAIL_FATAL_APP_EXIT` to our generated Windows API bindings instead of defining it manually (std only)
2024-03-02Cleanup windows abort_internalChris Denton-10/+13
2024-03-02Rollup merge of #121758 - joboet:move_pal_thread_local, r=ChrisDentonMatthias Krüger-3/+4
Move thread local implementation to `sys` Part of #117276.
2024-03-02Rollup merge of #121666 - ChrisDenton:thread-name, r=cuviperMatthias Krüger-11/+137
Use the OS thread name by default if `THREAD_INFO` has not been initialized Currently if `THREAD_INFO` hasn't been initialized then the name will be set to `None`. This PR changes it to use the OS thread name by default. This mostly affects foreign threads at the moment but we could expand this to make more use of the OS thread name in the future. Note: I've only implemented `Thread::get_name` for windows, linux and macos (and macos adjacent) targets. The rest just return `None`.
2024-03-02Rollup merge of #121861 - tbu-:pr_floating_point_exact_examples, ↵Matthias Krüger-22/+26
r=workingjubilee Use the guaranteed precision of a couple of float functions in docs
2024-03-02Rollup merge of #109263 - squell:master, r=cuviperMatthias Krüger-5/+4
fix typo in documentation for std::fs::Permissions Please check and re-check this PR carefully to see if I got this right. But by my logic, if the `read_only` function returns `true`, I would not expect be able to write to the file (it being read only); so this text is meant to clarify that `read_only` being `false` doesn't mean *you* can actually write to the file, just that "in general" someone is able to.
2024-03-01Add `get_name` placeholder to other targetsChris Denton-8/+40