about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2024-10-24Auto merge of #123550 - GnomedDev:remove-initial-arc, r=Noratriebbors-54/+119
Remove the `Arc` rt::init allocation for thread info Removes an allocation pre-main by just not storing anything in std::thread::Thread for the main thread. - The thread name can just be a hard coded literal, as was done in #123433. - Storing ThreadId and Parker in a static that is initialized once at startup. This uses SyncUnsafeCell and MaybeUninit as this is quite performance critical and we don't need synchronization or to store a tag value and possibly leave in a panic.
2024-10-23[musl] use posix_spawn if a directory change was requestedRain-11/+57
Currently, not all libcs have the `posix_spawn_file_actions_addchdir_np` symbol available to them. So we attempt to do a weak symbol lookup for that function. But that only works if libc is a dynamic library -- with statically linked musl binaries the symbol lookup would never work, so we would never be able to use it even if the musl in use supported the symbol. Now that Rust has a minimum musl version of 1.2.3, all supported musl versions now include this symbol, so we can unconditionally expect it to be there. This symbol was added to libc in https://github.com/rust-lang/libc/pull/3949 -- use it here. I couldn't find any tests for whether the posix_spawn path is used, but I've verified with cargo-nextest that this change works. This is a substantial improvement to nextest's performance with musl. On my workstation with a Ryzen 7950x, against https://github.com/clap-rs/clap at 61f5ee514f8f60ed8f04c6494bdf36c19e7a8126: Before: ``` Summary [ 1.071s] 879 tests run: 879 passed, 0 skipped ``` After: ``` Summary [ 0.392s] 879 tests run: 879 passed, 0 skipped ``` Fixes #99740.
2024-10-23Specialize `read_exact` and `read_buf_exact` for `VecDeque`Benoît du Garreau-0/+46
2024-10-22AIX use /dev/urandom for implHenry Jiang-1/+2
2024-10-21Document PartialEq impl for OnceLockDavid Ross-0/+20
2024-10-21Rollup merge of #130350 - RalfJung:strict-provenance, r=dtolnayMatthias Krüger-2/+2
stabilize Strict Provenance and Exposed Provenance APIs Given that [RFC 3559](https://rust-lang.github.io/rfcs/3559-rust-has-provenance.html) has been accepted, t-lang has approved the concept of provenance to exist in the language. So I think it's time that we stabilize the strict provenance and exposed provenance APIs, and discuss provenance explicitly in the docs: ```rust // core::ptr pub const fn without_provenance<T>(addr: usize) -> *const T; pub const fn dangling<T>() -> *const T; pub const fn without_provenance_mut<T>(addr: usize) -> *mut T; pub const fn dangling_mut<T>() -> *mut T; pub fn with_exposed_provenance<T>(addr: usize) -> *const T; pub fn with_exposed_provenance_mut<T>(addr: usize) -> *mut T; impl<T: ?Sized> *const T { pub fn addr(self) -> usize; pub fn expose_provenance(self) -> usize; pub fn with_addr(self, addr: usize) -> Self; pub fn map_addr(self, f: impl FnOnce(usize) -> usize) -> Self; } impl<T: ?Sized> *mut T { pub fn addr(self) -> usize; pub fn expose_provenance(self) -> usize; pub fn with_addr(self, addr: usize) -> Self; pub fn map_addr(self, f: impl FnOnce(usize) -> usize) -> Self; } impl<T: ?Sized> NonNull<T> { pub fn addr(self) -> NonZero<usize>; pub fn with_addr(self, addr: NonZero<usize>) -> Self; pub fn map_addr(self, f: impl FnOnce(NonZero<usize>) -> NonZero<usize>) -> Self; } ``` I also did a pass over the docs to adjust them, because this is no longer an "experiment". The `ptr` docs now discuss the concept of provenance in general, and then they go into the two families of APIs for dealing with provenance: Strict Provenance and Exposed Provenance. I removed the discussion of how pointers also have an associated "address space" -- that is not actually tracked in the pointer value, it is tracked in the type, so IMO it just distracts from the core point of provenance. I also adjusted the docs for `with_exposed_provenance` to make it clear that we cannot guarantee much about this function, it's all best-effort. There are two unstable lints associated with the strict_provenance feature gate; I moved them to a new [strict_provenance_lints](https://github.com/rust-lang/rust/issues/130351) feature since I didn't want this PR to have an even bigger FCP. ;) `@rust-lang/opsem` Would be great to get some feedback on the docs here. :) Nominating for `@rust-lang/libs-api.` Part of https://github.com/rust-lang/rust/issues/95228. [FCP comment](https://github.com/rust-lang/rust/pull/130350#issuecomment-2395114536)
2024-10-21move strict provenance lints to new feature gate, remove old feature gatesRalf Jung-2/+2
2024-10-20fix docsklensy-7/+7
2024-10-20replace FindFirstFileW with FindFirstFileExW and apply optimizationklensy-4/+25
2024-10-20replace FindFirstFileW with FindFirstFileExW and regenerate bindingsklensy-3/+9
2024-10-19Support lock() and lock_shared() on async IO FilesChristopher Berner-13/+87
2024-10-19Rollup merge of #131921 - klensy:statx_all, r=ChrisDentonMatthias Krüger-5/+5
replace STATX_ALL with (STATX_BASIC_STATS | STATX_BTIME) as former is deprecated STATX_ALL was deprecated in https://github.com/torvalds/linux/commit/581701b7efd60ba13d8a7eed60cbdd7fefaf6696 and suggested to use equivalent (STATX_BASIC_STATS | STATX_BTIME) combination, to prevent future surprises.
2024-10-19Rollup merge of #131890 - printfn:precise-capturing-docs, r=traviscrossMatthias Krüger-7/+39
Update `use` keyword docs to describe precise capturing I noticed that the standard library keyword docs for the `use` keyword haven't been updated yet to describe the new precise capturing syntax.
2024-10-19Rollup merge of #127462 - Ayush1325:uefi-env, r=joboetMatthias Krüger-42/+125
std: uefi: Add basic Env variables - Implement environment variable functions - Using EFI Shell protocol.
2024-10-19Remove the Arc rt::init allocation for thread infoGnomedDev-54/+119
2024-10-19replace STATX_ALL with (STATX_BASIC_STATS | STATX_BTIME) as former is deprecatedklensy-5/+5
2024-10-18Update `use` keyword docs to describe precise capturingprintfn-7/+39
2024-10-18std: uefi: Use common function for UEFI shellAyush Singh-36/+2
- Since in almost all cases, there will only be 1 UEFI shell, share the shell handle between all functions that require it. Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2024-10-18std: uefi: Add basic Env variablesAyush Singh-15/+132
- Implement environment variable functions - Using EFI Shell protocol. Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2024-10-18Auto merge of #131895 - jieyouxu:rollup-jyt3pic, r=jieyouxubors-3/+1
Rollup of 3 pull requests Successful merges: - #126207 (std::unix::stack_overflow::drop_handler addressing todo through libc …) - #131864 (Never emit `vptr` for empty/auto traits) - #131870 (compiletest: Store test collection context/state in two structs) r? `@ghost` `@rustbot` modify labels: rollup
2024-10-18Rollup merge of #126207 - devnexen:stack_overflow_libc_upd, r=joboet许杰友 Jieyou Xu (Joe)-3/+1
std::unix::stack_overflow::drop_handler addressing todo through libc … …update
2024-10-18Auto merge of #131841 - paulmenage:futex-abstraction, r=joboetbors-66/+83
Abstract the state type for futexes In the same way that we expose `SmallAtomic` and `SmallPrimitive` to allow Windows to use a value other than an `AtomicU32` for its futex state, switch the primary futex state type from `AtomicU32` to `futex::Futex`. The `futex::Futex` type should be usable as an atomic value with underlying primitive type equal to `futex::Primitive`. (`SmallAtomic` is also renamed to `SmallFutex`). This allows supporting the futex API on systems where the underlying kernel futex implementation requires more user state than simply an `AtomicU32`. All in-tree futex implementations simply define {`Futex`,`Primitive`} directly as {`AtomicU32`,`u32`}.
2024-10-18Revert using `HEAP` static in Windows allocChris Denton-57/+12
2024-10-18Rollup merge of #131866 - jieyouxu:thread_local, r=jhpratt许杰友 Jieyou Xu (Joe)-22/+26
Avoid use imports in `thread_local_inner!` Previously, the use imports in `thread_local_inner!` can shadow user-provided types or type aliases of the names `Storage`, `EagerStorage`, `LocalStorage` and `LocalKey`. This PR fixes that by dropping the use imports and instead refer to the std-internal types via fully qualified paths. A basic test is added to ensure `thread_local!`s with static decls with type names that match the aforementioned std-internal type names can successfully compile. Fixes #131863.
2024-10-18Add entropy source for RTEMSJan Sommer-0/+4
2024-10-18Rollup merge of #131654 - betrusted-io:xous-various-fixes, r=thomccMatthias Krüger-33/+511
Various fixes for Xous This patchset includes several fixes for Xous that have crept in over the last few months: * The `adjust_process()` syscall was incorrect * Warnings have started appearing in `alloc` -- adopt the same approach as wasm, until wasm figures out a workaround * Dead code warnings have appeared in the networking code. Add `allow(dead_code)` as these structs are used as IPC values * Add support for `args` and `env`, which have been useful for running tests * Update `unwinding` to `0.2.3` which fixes the recent regression due to changes in `asm!()` code
2024-10-18Avoid shadowing user provided types or type aliases in `thread_local!`许杰友 Jieyou Xu (Joe)-22/+26
By using qualified imports, i.e. `$crate::...::LocalKey`.
2024-10-17std::unix::stack_overflow::drop_handler addressing todo through libc updateDavid Carlier-3/+1
2024-10-17Abstract the state type for futexesPaul Menage-66/+83
In the same way that we expose SmallAtomic and SmallPrimitive to allow Windows to use a value other than an AtomicU32 for its futex state, this patch switches the primary futex state type from AtomicU32 to futex::Atomic. The futex::Atomic type should be usable as an atomic value with underlying primitive type equal to futex::Primitive. This allows supporting the futex API on systems where the underlying kernel futex implementation requires more state than simply an AtomicU32. All in-tree futex implementations simply define {Atomic,Primitive} directly as {AtomicU32,u32}.
2024-10-17Add must_use to CommandExt::execCallum Ryan-0/+1
2024-10-17Win: Remove special casing of the win7 target for `std::fs::rename`George Tokmaji-14/+1
2024-10-16Auto merge of #131767 - cuviper:bump-stage0, r=Mark-Simulacrumbors-30/+29
Bump bootstrap compiler to 1.83.0-beta.1 https://forge.rust-lang.org/release/process.html#master-bootstrap-update-tuesday
2024-10-16Rollup merge of #131746 - slanterns:once_box_order, r=joboetUrgau-2/+2
Relax a memory order in `once_box` per https://github.com/rust-lang/rust/pull/131094#discussion_r1788536445. In the successful path we don't need `Acquire` since we don't care if the store in `f()` happened in other threads has become visible to the current thread. We'll use our own results instead and just using `Release` to ensure other threads can see our store to `Box` when they fail the `compare_exchange` will suffice. Also took https://marabos.nl/atomics/memory-ordering.html#example-lazy-initialization-with-indirection as a reference. `@rustbot` label: +T-libs r? `@ibraheemdev`
2024-10-15update bootstrap configsJosh Stone-1/+0
2024-10-15replace placeholder versionJosh Stone-29/+29
(cherry picked from commit 567fd9610cbfd220844443487059335d7e1ff021)
2024-10-16relax a memory order in `once_box`Slanterns-2/+2
2024-10-15Rollup merge of #130568 - eduardosm:const-float-methods, r=RalfJung,tgross35Michael Goulet-12/+25
Make some float methods unstable `const fn` Some float methods are now `const fn` under the `const_float_methods` feature gate. I also made some unstable methods `const fn`, keeping their constness under their respective feature gate. In order to support `min`, `max`, `abs` and `copysign`, the implementation of some intrinsics had to be moved from Miri to rustc_const_eval (cc `@RalfJung).` Tracking issue: https://github.com/rust-lang/rust/issues/130843 ```rust impl <float> { // #[feature(const_float_methods)] pub const fn recip(self) -> Self; pub const fn to_degrees(self) -> Self; pub const fn to_radians(self) -> Self; pub const fn max(self, other: Self) -> Self; pub const fn min(self, other: Self) -> Self; pub const fn clamp(self, min: Self, max: Self) -> Self; pub const fn abs(self) -> Self; pub const fn signum(self) -> Self; pub const fn copysign(self, sign: Self) -> Self; // #[feature(float_minimum_maximum)] pub const fn maximum(self, other: Self) -> Self; pub const fn minimum(self, other: Self) -> Self; // Only f16/f128 (f32/f64 already const) pub const fn is_sign_positive(self) -> bool; pub const fn is_sign_negative(self) -> bool; pub const fn next_up(self) -> Self; pub const fn next_down(self) -> Self; } ``` r? libs-api try-job: dist-s390x-linux
2024-10-15Rollup merge of #129794 - Ayush1325:uefi-os-expand, r=joboetMichael Goulet-14/+73
uefi: Implement getcwd and chdir - Using EFI Shell Protocol. These functions do not make much sense unless a shell is present. - Return the exe dir in case shell protocol is missing. r? `@joboet`
2024-10-15Make some float methods unstable `const fn`Eduardo Sánchez Muñoz-12/+25
Some float methods are now `const fn` under the `const_float_methods` feature gate. In order to support `min`, `max`, `abs` and `copysign`, the implementation of some intrinsics had to be moved from Miri to rustc_const_eval.
2024-10-15Auto merge of #131724 - matthiaskrgr:rollup-ntgkkk8, r=matthiaskrgrbors-15/+4
Rollup of 7 pull requests Successful merges: - #130608 (Implemented `FromStr` for `CString` and `TryFrom<CString>` for `String`) - #130635 (Add `&pin (mut|const) T` type position sugar) - #130747 (improve error messages for `C-cmse-nonsecure-entry` functions) - #131137 (Add 1.82 release notes) - #131328 (Remove unnecessary sorts in `rustc_hir_analysis`) - #131496 (Stabilise `const_make_ascii`.) - #131706 (Fix two const-hacks) r? `@ghost` `@rustbot` modify labels: rollup
2024-10-15Auto merge of #129458 - EnzymeAD:enzyme-frontend, r=jieyouxubors-1/+8
Autodiff Upstreaming - enzyme frontend This is an upstream PR for the `autodiff` rustc_builtin_macro that is part of the autodiff feature. For the full implementation, see: https://github.com/rust-lang/rust/pull/129175 **Content:** It contains a new `#[autodiff(<args>)]` rustc_builtin_macro, as well as a `#[rustc_autodiff]` builtin attribute. The autodiff macro is applied on function `f` and will expand to a second function `df` (name given by user). It will add a dummy body to `df` to make sure it type-checks. The body will later be replaced by enzyme on llvm-ir level, we therefore don't really care about the content. Most of the changes (700 from 1.2k) are in `compiler/rustc_builtin_macros/src/autodiff.rs`, which expand the macro. Nothing except expansion is implemented for now. I have a fallback implementation for relevant functions in case that rustc should be build without autodiff support. The default for now will be off, although we want to flip it later (once everything landed) to on for nightly. For the sake of CI, I have flipped the defaults, I'll revert this before merging. **Dummy function Body:** The first line is an `inline_asm` nop to make inlining less likely (I have additional checks to prevent this in the middle end of rustc. If `f` gets inlined too early, we can't pass it to enzyme and thus can't differentiate it. If `df` gets inlined too early, the call site will just compute this dummy code instead of the derivatives, a correctness issue. The following black_box lines make sure that none of the input arguments is getting optimized away before we replace the body. **Motivation:** The user facing autodiff macro can verify the user input. Then I write it as args to the rustc_attribute, so from here on I can know that these values should be sensible. A rustc_attribute also turned out to be quite nice to attach this information to the corresponding function and carry it till the backend. This is also just an experiment, I expect to adjust the user facing autodiff macro based on user feedback, to improve usability. As a simple example of what this will do, we can see this expansion: From: ``` #[autodiff(df, Reverse, Duplicated, Const, Active)] pub fn f1(x: &[f64], y: f64) -> f64 { unimplemented!() } ``` to ``` #[rustc_autodiff] #[inline(never)] pub fn f1(x: &[f64], y: f64) -> f64 { ::core::panicking::panic("not implemented") } #[rustc_autodiff(Reverse, Duplicated, Const, Active,)] #[inline(never)] pub fn df(x: &[f64], dx: &mut [f64], y: f64, dret: f64) -> f64 { unsafe { asm!("NOP"); }; ::core::hint::black_box(f1(x, y)); ::core::hint::black_box((dx, dret)); ::core::hint::black_box(f1(x, y)) } ``` I will add a few more tests once I figured out why rustc rebuilds every time I touch a test. Tracking: - https://github.com/rust-lang/rust/issues/124509 try-job: dist-x86_64-msvc
2024-10-14Fix two const-hacksGeorge Bateman-15/+4
2024-10-14uefi: Implement getcwd and chdirAyush Singh-14/+73
- Using EFI Shell Protocol. These functions do not make much sense unless a shell is present. - Return the exe dir in case shell protocol is missing. Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2024-10-14Rollup merge of #131616 - RalfJung:const_ip, r=tgross35Matthias Krüger-3/+0
merge const_ipv4 / const_ipv6 feature gate into 'ip' feature gate https://github.com/rust-lang/rust/issues/76205 has been closed a while ago, but there are still some functions that reference it. Those functions are all unstable *and* const-unstable. There's no good reason to use a separate feature gate for their const-stability, so this PR moves their const-stability under the same gate as their regular stability, and therefore removes the remaining references to https://github.com/rust-lang/rust/issues/76205.
2024-10-14Rollup merge of #128967 - devnexen:get_path_fbsd_upd, r=joboetMatthias Krüger-2/+2
std::fs::get_path freebsd update. what matters is we re doing the right things as doing sizeof, rather than passing KINFO_FILE_SIZE (only defined on intel architectures), the kernel making sure it matches the expectation in its side.
2024-10-13Implement file_lock featureChristopher Berner-0/+511
This adds lock(), lock_shared(), try_lock(), try_lock_shared(), and unlock() to File gated behind the file_lock feature flag
2024-10-13Rollup merge of #131646 - RalfJung:unix-miri-fallbacks, r=joboetMatthias Krüger-1/+2
sys/unix: add comments for some Miri fallbacks
2024-10-13library: xous: mark alloc as `FIXME(static_mut_refs)`Sean Cross-0/+3
The allocator on Xous is now throwing warnings because the allocator needs to be mutable, and allocators hand out mutable pointers, which the `static_mut_refs` lint now catches. Give the same treatment to Xous as wasm, at least until a solution is devised for fixing the warning on wasm. Signed-off-by: Sean Cross <sean@xobs.io>
2024-10-13xous: ffi: correct syscall number for adjust_processSean Cross-1/+1
The AdjustProcessLimit syscall was using the correct call number. Signed-off-by: Sean Cross <sean@xobs.io>
2024-10-13net: fix dead code warningSean Cross-0/+3
Signed-off-by: Sean Cross <sean@xobs.io>