about summary refs log tree commit diff
path: root/library/std/src/sys
AgeCommit message (Collapse)AuthorLines
2024-10-25Auto merge of #131349 - RalfJung:const-stability-checks, r=compiler-errorsbors-3/+3
Const stability checks v2 The const stability system has served us well ever since `const fn` were first stabilized. It's main feature is that it enforces *recursive* validity -- a stable const fn cannot internally make use of unstable const features without an explicit marker in the form of `#[rustc_allow_const_fn_unstable]`. This is done to make sure that we don't accidentally expose unstable const features on stable in a way that would be hard to take back. As part of this, it is enforced that a `#[rustc_const_stable]` can only call `#[rustc_const_stable]` functions. However, some problems have been coming up with increased usage: - It is baffling that we have to mark private or even unstable functions as `#[rustc_const_stable]` when they are used as helpers in regular stable `const fn`, and often people will rather add `#[rustc_allow_const_fn_unstable]` instead which was not our intention. - The system has several gaping holes: a private `const fn` without stability attributes whose inherited stability (walking up parent modules) is `#[stable]` is allowed to call *arbitrary* unstable const operations, but can itself be called from stable `const fn`. Similarly, `#[allow_internal_unstable]` on a macro completely bypasses the recursive nature of the check. Fundamentally, the problem is that we have *three* disjoint categories of functions, and not enough attributes to distinguish them: 1. const-stable functions 2. private/unstable functions that are meant to be callable from const-stable functions 3. functions that can make use of unstable const features Functions in the first two categories cannot use unstable const features and they can only call functions from the first two categories. This PR implements the following system: - `#[rustc_const_stable]` puts functions in the first category. It may only be applied to `#[stable]` functions. - `#[rustc_const_unstable]` by default puts functions in the third category. The new attribute `#[rustc_const_stable_indirect]` can be added to such a function to move it into the second category. - `const fn` without a const stability marker are in the second category if they are still unstable. They automatically inherit the feature gate for regular calls, it can now also be used for const-calls. Also, all the holes mentioned above have been closed. There's still one potential hole that is hard to avoid, which is when MIR building automatically inserts calls to a particular function in stable functions -- which happens in the panic machinery. Those need to be manually marked `#[rustc_const_stable_indirect]` to be sure they follow recursive const stability. But that's a fairly rare and special case so IMO it's fine. The net effect of this is that a `#[unstable]` or unmarked function can be constified simply by marking it as `const fn`, and it will then be const-callable from stable `const fn` and subject to recursive const stability requirements. If it is publicly reachable (which implies it cannot be unmarked), it will be const-unstable under the same feature gate. Only if the function ever becomes `#[stable]` does it need a `#[rustc_const_unstable]` or `#[rustc_const_stable]` marker to decide if this should also imply const-stability. Adding `#[rustc_const_unstable]` is only needed for (a) functions that need to use unstable const lang features (including intrinsics), or (b) `#[stable]` functions that are not yet intended to be const-stable. Adding `#[rustc_const_stable]` is only needed for functions that are actually meant to be directly callable from stable const code. `#[rustc_const_stable_indirect]` is used to mark intrinsics as const-callable and for `#[rustc_const_unstable]` functions that are actually called from other, exposed-on-stable `const fn`. No other attributes are required. Also see the updated dev-guide at https://github.com/rust-lang/rustc-dev-guide/pull/2098. I think in the future we may want to tweak this further, so that in the hopefully common case where a public function's const-stability just exactly mirrors its regular stability, we never have to add any attribute. But right now, once the function is stable this requires `#[rustc_const_stable]`. ### Open question There is one point I could see we might want to do differently, and that is putting `#[rustc_const_unstable]` functions (but not intrinsics) in category 2 by default, and requiring an extra attribute for `#[rustc_const_not_exposed_on_stable]` or so. This would require a bunch of extra annotations, but would have the advantage that turning a `#[rustc_const_unstable]` into `#[rustc_const_stable]` will never change the way the function is const-checked. Currently, we often discover in the const stabilization PR that a function needs some other unstable const things, and then we rush to quickly deal with that. In this alternative universe, we'd work towards getting rid of the `rustc_const_not_exposed_on_stable` before stabilization, and once that is done stabilization becomes a trivial matter. `#[rustc_const_stable_indirect]` would then only be used for intrinsics. I think I like this idea, but might want to do it in a follow-up PR, as it will need a whole bunch of annotations in the standard library. Also, we probably want to convert all const intrinsics to the "new" form (`#[rustc_intrinsic]` instead of an `extern` block) before doing this to avoid having to deal with two different ways of declaring intrinsics. Cc `@rust-lang/wg-const-eval` `@rust-lang/libs-api` Part of https://github.com/rust-lang/rust/issues/129815 (but not finished since this is not yet sufficient to safely let us expose `const fn` from hashbrown) Fixes https://github.com/rust-lang/rust/issues/131073 by making it so that const-stable functions are always stable try-job: test-various
2024-10-25Re-do recursive const stability checksRalf Jung-3/+3
Fundamentally, we have *three* disjoint categories of functions: 1. const-stable functions 2. private/unstable functions that are meant to be callable from const-stable functions 3. functions that can make use of unstable const features This PR implements the following system: - `#[rustc_const_stable]` puts functions in the first category. It may only be applied to `#[stable]` functions. - `#[rustc_const_unstable]` by default puts functions in the third category. The new attribute `#[rustc_const_stable_indirect]` can be added to such a function to move it into the second category. - `const fn` without a const stability marker are in the second category if they are still unstable. They automatically inherit the feature gate for regular calls, it can now also be used for const-calls. Also, several holes in recursive const stability checking are being closed. There's still one potential hole that is hard to avoid, which is when MIR building automatically inserts calls to a particular function in stable functions -- which happens in the panic machinery. Those need to *not* be `rustc_const_unstable` (or manually get a `rustc_const_stable_indirect`) to be sure they follow recursive const stability. But that's a fairly rare and special case so IMO it's fine. The net effect of this is that a `#[unstable]` or unmarked function can be constified simply by marking it as `const fn`, and it will then be const-callable from stable `const fn` and subject to recursive const stability requirements. If it is publicly reachable (which implies it cannot be unmarked), it will be const-unstable under the same feature gate. Only if the function ever becomes `#[stable]` does it need a `#[rustc_const_unstable]` or `#[rustc_const_stable]` marker to decide if this should also imply const-stability. Adding `#[rustc_const_unstable]` is only needed for (a) functions that need to use unstable const lang features (including intrinsics), or (b) `#[stable]` functions that are not yet intended to be const-stable. Adding `#[rustc_const_stable]` is only needed for functions that are actually meant to be directly callable from stable const code. `#[rustc_const_stable_indirect]` is used to mark intrinsics as const-callable and for `#[rustc_const_unstable]` functions that are actually called from other, exposed-on-stable `const fn`. No other attributes are required.
2024-10-25library: consistently use American spelling for 'behavior'Ralf Jung-21/+21
2024-10-24Rollup merge of #132101 - youknowone:thread_local-gyneiene, r=tgross35Jubilee-5/+4
Avoid using imports in thread_local_inner! in static Fixes #131863 for wasm targets All other macros were done in #131866, but this sub module is missed. r? `@jieyouxu`
2024-10-24Rollup merge of #132048 - mustartt:aix-random-impl, r=workingjubileeJubilee-0/+1
AIX: use /dev/urandom for random implementation On AIX, we can poll `/dev/urandom` for cryptographically secure random output to implement `fill_bytes` because we don't have equivalent syscalls like other platforms. https://www.ibm.com/docs/en/aix/7.3?topic=files-random-urandom-devices
2024-10-25Avoid use imports in thread_local_inner! in statikJeong YunWon-5/+4
Fixes #131863 for wasm targets All other macros were done in #131866, but this sub module is missed.
2024-10-23[musl] use posix_spawn if a directory change was requestedRain-11/+43
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-22AIX use /dev/urandom for implHenry Jiang-0/+1
2024-10-20fix docsklensy-6/+6
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/+49
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 #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-19replace STATX_ALL with (STATX_BASIC_STATS | STATX_BTIME) as former is deprecatedklensy-5/+5
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/+3
2024-10-18Rollup merge of #131654 - betrusted-io:xous-various-fixes, r=thomccMatthias Krüger-32/+510
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-17Win: Remove special casing of the win7 target for `std::fs::rename`George Tokmaji-14/+1
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-16relax a memory order in `once_box`Slanterns-2/+2
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-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 #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/+214
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-13net: fix dead code warningSean Cross-0/+3
Signed-off-by: Sean Cross <sean@xobs.io>
2024-10-13std: xous: add support for args and envSean Cross-32/+504
Process arguments and environment variables are both passed by way of Application Parameters. These are a TLV format that gets passed in as the second process argument. This patch combines both as they are very similar in their decode. Signed-off-by: Sean Cross <sean@osdyne.com>
2024-10-13sys/unix: add comments for some Miri fallbacksRalf Jung-1/+2
2024-10-13remove outdated comment now that Miri is on CIRalf Jung-1/+0
2024-10-13sys/windows: remove miri hack that is only needed for win7Ralf Jung-7/+3
2024-10-11Rollup merge of #130962 - nyurik:opts-libs, r=cuviperTrevor Gross-11/+11
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-10uefi: process: Add args supportAyush Singh-12/+56
- Wrap all args with quotes. - Escape ^ and " inside quotes using ^. Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2024-10-10Use with_capacity(0) because we're reading the capacity later onMads Marquart-1/+1
2024-10-10Prefer `target_vendor = "apple"` on confstrMads Marquart-3/+3
2024-10-10use `confstr(_CS_DARWIN_USER_TEMP_DIR, ...)` as a `TMPDIR` fallback on darwinThom Chiovoloni-4/+97
2024-10-09Decouple WASIp2 sockets from WasiFdNicola Krumschmidt-18/+56
2024-10-08Update library/std/src/sys/pal/unix/process/process_vxworks.rsYuri Astrakhan-1/+1
Co-authored-by: Josh Stone <cuviper@gmail.com>
2024-10-08fix ref in process_vxworks.rsYuri Astrakhan-1/+1