about summary refs log tree commit diff
path: root/library/core/src
AgeCommit message (Collapse)AuthorLines
2024-08-08Stabilize `Ready::into_inner()`daxpedda-2/+1
2024-08-07Mark `{f32,f64}::{next_up,next_down,midpoint}` inlineTrevor Gross-0/+6
Most float functions are marked `#[inline]` so any float symbols used by these functions only need to be provided if the function itself is used. RFL recently noticed that `next_up`, `next_down`, and `midpoint` for `f32` and `f64` are not inline, which causes linker errors when building with certain configurations [1]. Add the missing attributes so the symbols should no longer be required. Cc: Gary Guo <gary@garyguo.net> Reported-by: Alice Ryhl <aliceryhl@google.com> Link: https://lore.kernel.org/all/20240806150619.192882-1-ojeda@kernel.org/ [1]
2024-08-06Rollup merge of #128417 - tgross35:f16-f128-math, r=dtolnayTrevor Gross-6/+645
Add `f16` and `f128` math functions This adds intrinsics and math functions for `f16` and `f128` floating point types. Support is quite limited and some things are broken so tests don't run on many platforms, but this provides a starting point.
2024-08-07Rollup merge of #125048 - dingxiangfei2009:stable-deref, r=amanieuMatthias Krüger-2/+75
PinCoerceUnsized trait into core cc ``@Darksonn`` ``@wedsonaf`` ``@ojeda`` This is a PR to introduce a `PinCoerceUnsized` trait in order to make trait impls generated by the proc-macro `#[derive(SmartPointer)]`, proposed by [RFC](https://github.com/rust-lang/rfcs/blob/e17e19ac7ad1c8ccad55d4babfaee1aa107d1da5/text/3621-derive-smart-pointer.md#pincoerceunsized-1), sound. There you may find explanation, justification and discussion about the alternatives. Note that we do not seek stabilization of this `PinCoerceUnsized` trait in the near future. The stabilisation of this trait does not block the eventual stabilization process of the `#[derive(SmartPointer)]` macro. Ideally, use of `DerefPure` is more preferrable except this will actually constitute a breaking change. `PinCoerceUnsized` emerges as a solution to the said soundness hole while avoiding the breaking change. More details on the `DerefPure` option have been described in this [section](https://github.com/rust-lang/rfcs/blob/e17e19ac7ad1c8ccad55d4babfaee1aa107d1da5/text/3621-derive-smart-pointer.md#derefpure) of the RFC linked above. Earlier discussion can be found in this [Zulip stream](https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/Pin.20and.20soundness.20of.20unsizing.20coercions) and [rust-for-linux thread](https://rust-lang.zulipchat.com/#narrow/stream/425075-rust-for-linux/topic/.23.5Bderive.28SmartPointer.29.5D.20and.20pin.20unsoundness.20rfc.233621). try-job: dist-various-2
2024-08-06Add a special case for CStr/CString in the improper_ctypes lintFlying-Toast-0/+1
Instead of saying to "consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct", we now tell users to "Use `*const ffi::c_char` instead, and pass the value from `CStr::as_ptr()`" when the type involved is a `CStr` or a `CString`. Co-authored-by: Jieyou Xu <jieyouxu@outlook.com>
2024-08-05custom MIR: add support for tail callsRalf Jung-0/+8
2024-08-05nontemporal_store: make sure that the intrinsic is truly just a hintRalf Jung-5/+5
2024-08-05Rollup merge of #128619 - glandium:last_chunk, r=scottmcmMatthias Krüger-1/+1
Correct the const stabilization of `<[T]>::last_chunk` `<[T]>::first_chunk` became const stable in 1.77, but `<[T]>::last_chunk` was left out. This was fixed in 3488679768d, which reached stable in 1.80, making `<[T]>::last_chunk` const stable as of that version, but it is documented as being const stable as 1.77. While this is what should have happened, the documentation should reflect what actually did happen.
2024-08-05Rollup merge of #128609 - swenson:smaller-faster-dragon, r=AmanieuMatthias Krüger-23/+26
Remove unnecessary constants from flt2dec dragon The "dragon" `flt2dec` algorithm uses multi-precision multiplication by (sometimes large) powers of 10. It has precomputed some values to help with these calculations. BUT: * There is no need to store powers of 10 and 2 * powers of 10: it is trivial to compute the second from the first. * We can save a chunk of memory by storing powers of 5 instead of powers of 10 for the large powers (and just shifting as appropriate). * This also slightly speeds up the routines (by ~1-3%) since the intermediate products are smaller and the shift is cheap. In this PR, we remove the unnecessary constants and do the necessary adjustments. Relevant benchmarks before (on my Threadripper 3970X, x86_64-unknown-linux-gnu): ``` num::flt2dec::bench_big_shortest 137.92/iter +/- 2.24 num::flt2dec::strategy::dragon::bench_big_exact_12 2135.28/iter +/- 38.90 num::flt2dec::strategy::dragon::bench_big_exact_3 904.95/iter +/- 10.58 num::flt2dec::strategy::dragon::bench_big_exact_inf 47230.33/iter +/- 320.84 num::flt2dec::strategy::dragon::bench_big_shortest 3915.05/iter +/- 51.37 ``` and after: ``` num::flt2dec::bench_big_shortest 137.40/iter +/- 2.03 num::flt2dec::strategy::dragon::bench_big_exact_12 2101.10/iter +/- 25.63 num::flt2dec::strategy::dragon::bench_big_exact_3 873.86/iter +/- 4.20 num::flt2dec::strategy::dragon::bench_big_exact_inf 47468.19/iter +/- 374.45 num::flt2dec::strategy::dragon::bench_big_shortest 3877.01/iter +/- 45.74 ```
2024-08-05Correct the const stabilization of `<[T]>::last_chunk`Mike Hommey-1/+1
`<[T]>::first_chunk` became const stable in 1.77, but `<[T]>::last_chunk` was left out. This was fixed in 3488679768d, which reached stable in 1.80, making `<[T]>::last_chunk` const stable as of that version, but it is documented as being const stable as 1.77. While this is what should have happened, the documentation should reflect what actually did happen.
2024-08-04refactor: standardize duplicate processes in parserKonippi-32/+24
2024-08-04Rollup merge of #128526 - tshepang:patch-1, r=AmanieuMatthias Krüger-10/+0
time.rs: remove "Basic usage text" Only one example is given (for each method)
2024-08-04Auto merge of #128466 - sayantn:stdarch-update, r=tgross35bors-0/+1
Update the stdarch submodule cc `@tgross35` `@Amanieu` r? `@tgross35` try-job: dist-various-2
2024-08-04Chore: add `x86_amx_intrinsics` feature flag to `core/lib.rs` and remove ↵sayantn-0/+1
`issue-120720-reduce-nan.rs`
2024-08-03Rollup merge of #128530 - scottmcm:repeat-n-unchecked, r=joboetMatthias Krüger-13/+20
Implement `UncheckedIterator` directly for `RepeatN` This just pulls the code out of `next` into `next_unchecked`, rather than making the `Some` and `unwrap_unchecked`ing it. And while I was touching it, I added a codegen test that `array::repeat` for something that's just `Clone`, not `Copy`, still ends up optimizing to the same thing as `[x; n]`: <https://rust.godbolt.org/z/YY3a5ajMW>.
2024-08-03Remove unnecessary constants from flt2dec dragonChristopher Swenson-23/+26
The "dragon" `flt2dec` algorithm uses multi-precision multiplication by (sometimes large) powers of 10. It has precomputed some values to help with these calculations. BUT: * There is no need to store powers of 10 and 2 * powers of 10: it is trivial to compute the second from the first. * We can save a chunk of memory by storing powers of 5 instead of powers of 10 for the large powers (and just shifting by 2 as appropriate). * This also slightly speeds up the routines (by ~1-3%) since the intermediate products are smaller and the shift is cheap. In this PR, we remove the unnecessary constants and do the necessary adjustments. Relevant benchmarks before (on my Threadripper 3970X, x86_64-unknown-linux-gnu): ``` num::flt2dec::bench_big_shortest 137.92/iter +/- 2.24 num::flt2dec::strategy::dragon::bench_big_exact_12 2135.28/iter +/- 38.90 num::flt2dec::strategy::dragon::bench_big_exact_3 904.95/iter +/- 10.58 num::flt2dec::strategy::dragon::bench_big_exact_inf 47230.33/iter +/- 320.84 num::flt2dec::strategy::dragon::bench_big_shortest 3915.05/iter +/- 51.37 ``` and after: ``` num::flt2dec::bench_big_shortest 137.40/iter +/- 2.03 num::flt2dec::strategy::dragon::bench_big_exact_12 2101.10/iter +/- 25.63 num::flt2dec::strategy::dragon::bench_big_exact_3 873.86/iter +/- 4.20 num::flt2dec::strategy::dragon::bench_big_exact_inf 47468.19/iter +/- 374.45 num::flt2dec::strategy::dragon::bench_big_shortest 3877.01/iter +/- 45.74 ```
2024-08-03Apply review comments to PartialOrd sectionLukas Bergdoll-7/+7
2024-08-03Auto merge of #128404 - compiler-errors:revert-dead-code-changes, r=pnkfelixbors-0/+1
Revert recent changes to dead code analysis This is a revert to recent changes to dead code analysis, namely: * efdf219 Rollup merge of #128104 - mu001999-contrib:fix/128053, r=petrochenkov * a70dc297a899b76793a14c5705f6ec78fd7a57a7 Rollup merge of #127017 - mu001999-contrib:dead/enhance, r=pnkfelix * 31fe9628cf830a08e7194a446f66c668aaea86e9 Rollup merge of #127107 - mu001999-contrib:dead/enhance-2, r=pnkfelix * 2724aeaaeb127a8073e39461caacbe21a128ce7b Rollup merge of #126618 - mu001999-contrib:dead/enhance, r=pnkfelix * 977c5fd419ade52467f7de79d5bfc25c0c893275 Rollup merge of #126315 - mu001999-contrib:fix/126289, r=petrochenkov * 13314df21b0bb0cdd02c6760581d1b9f1052fa7e Rollup merge of #125572 - mu001999-contrib:dead/enhance, r=pnkfelix There is an additional change stacked on top, which suppresses false-negatives that were masked by this work. I believe the functions that are touched in that code are legitimately unused functions and the types are not reachable since this `AnonPipe` type is not publically reachable -- please correct me if I'm wrong cc `@NobodyXu` who added these in ##127153. Some of these reverts (#126315 and #126618) are only included because it makes the revert apply cleanly, and I think these changes were only done to fix follow-ups from the other PRs? I apologize for the size of the PR and the churn that it has on the codebase (and for reverting `@mu001999's` work here), but I'm putting this PR up because I am concerned that we're making ad-hoc changes to fix bugs that are fallout of these PRs, and I'd like to see these changes reimplemented in a way that's more separable from the existing dead code pass. I am happy to review any code to reapply these changes in a more separable way. cc `@mu001999` r? `@pnkfelix` Fixes #128272 Fixes #126169
2024-08-03Revert "Rollup merge of #127107 - mu001999-contrib:dead/enhance-2, r=pnkfelix"Michael Goulet-0/+1
This reverts commit 31fe9628cf830a08e7194a446f66c668aaea86e9, reversing changes made to f20307851ead9fbbb9fa88bbffb3258a069230a6.
2024-08-03Rollup merge of #126704 - sayantn:sha, r=AmanieuMatthias Krüger-0/+10
Added SHA512, SM3, SM4 target-features and `sha512_sm_x86` feature gate This is an effort towards #126624. This adds support for these 3 target-features and introduces the feature flag `sha512_sm_x86`, which would gate these target-features and the yet-to-be-implemented detection and intrinsics in stdarch.
2024-08-02Auto merge of #128254 - Amanieu:orig-binary-search, r=tgross35bors-31/+44
Rewrite binary search implementation This PR builds on top of #128250, which should be merged first. This restores the original binary search implementation from #45333 which has the nice property of having a loop count that only depends on the size of the slice. This, along with explicit conditional moves from #128250, means that the entire binary search loop can be perfectly predicted by the branch predictor. Additionally, LLVM is able to unroll the loop when the slice length is known at compile-time. This results in a very compact code sequence of 3-4 instructions per binary search step and zero branches. Fixes #53823 Fixes #115271
2024-08-01Implement `UncheckedIterator` directly for `RepeatN`Scott McMurray-13/+20
2024-08-02Rollup merge of #128453 - RalfJung:raw_eq, r=saethlinMatthias Krüger-2/+4
raw_eq: using it on bytes with provenance is not UB (outside const-eval) The current behavior of raw_eq violates provenance monotonicity. See https://github.com/rust-lang/rust/pull/124921 for an explanation of provenance monotonicity. It is violated in raw_eq because comparing bytes without provenance is well-defined, but adding provenance makes the operation UB. So remove the no-provenance requirement from raw_eq. However, the requirement stays in-place for compile-time invocations of raw_eq, that indeed cannot deal with provenance. Cc `@rust-lang/opsem`
2024-08-02time.rs: remove "Basic usage text"Tshepang Mbambo-10/+0
Only one example is given (for each method)
2024-08-02Add the `sha512`, `sm3` and `sm4` target featuressayantn-0/+10
Add the feature in `core/lib.rs`
2024-08-01Add a disclaimer about x86 `f128` math functionsTrevor Gross-0/+3
Due to a LLVM bug, `f128` math functions link successfully but LLVM chooses the wrong symbols (`long double` symbols rather than those for binary128). Since this is a notable problem that may surprise a number of users, add a note about it. Link: https://github.com/llvm/llvm-project/issues/44744
2024-08-01Update comments for `{f16, f32, f64, f128}::midpoint`Trevor Gross-12/+12
Clarify what makes some operations not safe, and correct comment in the default branch ("not safe" -> "safe").
2024-08-01Add `core` functions for `f16` and `f128` that require math routinesTrevor Gross-0/+347
`min`, `max`, and similar functions require external math routines. Add these under the same gates as `std` math functions (`reliable_f16_math` and `reliable_f128_math`).
2024-08-01Add math intrinsics for `f16` and `f128`Trevor Gross-0/+289
These already exist in the compiler. Expose them in core so we can add their library functions.
2024-08-01Rollup merge of #128497 - Bryanskiy:fix-dropck-doc, r=lcnrMatthias Krüger-3/+4
fix dropck documentation for `[T;0]` special-case fixes https://github.com/rust-lang/rust/issues/110288. r? ``@lcnr``
2024-08-01Hide internal sort moduleLukas Bergdoll-0/+1
2024-08-01fix dropck documentation for `[T;0]` special-caseBryanskiy-3/+4
2024-08-01core: use `compare_bytes` for more slice element typesjoboet-6/+19
2024-07-31raw_eq: using it on bytes with provenance is not UB (outside const-eval)Ralf Jung-2/+4
2024-07-31Apply review commentsLukas Bergdoll-45/+50
- Use if the implementation of [`Ord`] for `T` language - Link to total order wiki page - Rework total order help and examples - Improve language to be more precise and less prone to misunderstandings. - Fix usage of `sort_unstable_by` in `sort_by` example - Fix missing author mention - Use more consistent example input for sort - Use more idiomatic assert_eq! in examples - Use more natural "comparison function" language instead of "comparator function"
2024-07-31PinCoerceUnsized trait into coreXiangfei Ding-2/+75
2024-07-30Auto merge of #128083 - Mark-Simulacrum:bump-bootstrap, r=albertlarsan68bors-120/+19
Bump bootstrap compiler to new beta https://forge.rust-lang.org/release/process.html#master-bootstrap-update-t-2-day-tuesday
2024-07-30Rewrite binary search implementationAmanieu d'Antras-31/+44
This restores the original binary search implementation from #45333 which has the nice property of having a loop count that only depends on the size of the slice. This, along with explicit conditional moves from #128250, means that the entire binary search loop can be perfectly predicted by the branch predictor. Additionally, LLVM is able to unroll the loop when the slice length is known at compile-time. This results in a very compact code sequence of 3-4 instructions per binary search step and zero branches. Fixes #53823
2024-07-30Auto merge of #128250 - Amanieu:select_unpredictable, r=nikicbors-0/+28
Add `select_unpredictable` to force LLVM to use CMOV Since https://reviews.llvm.org/D118118, LLVM will no longer turn CMOVs into branches if it comes from a `select` marked with an `unpredictable` metadata attribute. This PR introduces `core::intrinsics::select_unpredictable` which emits such a `select` and uses it in the implementation of `binary_search_by`.
2024-07-29CloneToUninit: use a private specialization traitPavel Grigorenko-117/+134
and move implementation details into a submodule
2024-07-29Sparkle some attributes over `CloneToUninit` stuffPavel Grigorenko-0/+7
2024-07-29impl CloneToUninit for str and CStrPavel Grigorenko-0/+21
2024-07-29Stabilize offset_of_nestedGeorge Bateman-2/+3
2024-07-29Rollup merge of #128307 - ojeda:unescaped_backticks, r=GuillaumeGomezMatthias Krüger-4/+5
Clean and enable `rustdoc::unescaped_backticks` for `core/alloc/std/test/proc_macro` I am not sure if the lint is supposed to be "ready enough" (since it is `allow` by default), but it does catch a couple issues in `core` (`alloc`, `std`, `test` and `proc_macro` are already clean), so I propose making it `warn` in all the crates rendered in the website. Cc: `@GuillaumeGomez`
2024-07-29Warn on `rustdoc::unescaped_backticks` for `core/alloc/std/test/proc_macro`Miguel Ojeda-0/+1
They are all clean now, so enable the lint to keep them clean going forward. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2024-07-29Remove spurious backticks detected by `rustdoc::unescaped_backticks`Miguel Ojeda-4/+4
There are only 3 cases across the crates rendered in the website (`core`, `alloc`, `std`, `proc_macro` and `test`), and they are all in `core`. Clean them up, so that the lint can be enabled in the next commit. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2024-07-29Reformat `use` declarations.Nicholas Nethercote-561/+318
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-28step cfg(bootstrap)Mark Rousskov-104/+3
2024-07-28Update CURRENT_RUSTC_VERSIONMark Rousskov-17/+17
2024-07-28Rollup merge of #128240 - mbrubeck:patch-3, r=joboetGuillaume Gomez-0/+18
Add links from `assert_eq!` docs to `debug_assert_eq!`, etc. This adds information and links from the docs for the following macros to their debug-only versions: * `assert_eq!` * `assert_ne!` * `assert_matches!` This matches the existing documentation for the `assert!` macro.