about summary refs log tree commit diff
path: root/library/core/src
AgeCommit message (Collapse)AuthorLines
2024-02-20Rollup merge of #121241 - reitermarkus:generic-nonzero-traits, r=dtolnayNilstrieb-179/+211
Implement `NonZero` traits generically. Tracking issue: https://github.com/rust-lang/rust/issues/120257 r? ````@dtolnay````
2024-02-20Rollup merge of #121196 - Nilstrieb:the-clever-solution, r=saethlinNilstrieb-1/+8
Always inline check in `assert_unsafe_precondition` with cfg(debug_assertions) The current complexities in `assert_unsafe_precondition` are delicately balancing several concerns, among them compile times for the cases where there are no debug assertions. This comes at a large runtime cost when the assertions are enabled, making the debug assertion compiler a lot slower, which is very annoying. To avoid this, we always inline the check when building with debug assertions. Numbers (compiling stage1 library after touching core): - master: 80s - just adding `#[inline(always)]` to the `cfg(bootstrap)` `debug_assertions` (equivalent to a bootstrap bump (uhh, i just realized that i was on a slightly outdated master so this bump might have happened already), (#121112)): 67s - this: 54s So this seems like a good solution. I think we can still get the same run-time perf improvements for other users too by massaging this code further (see my other PR about adding `#[rustc_no_mir_inline]` #121114) but this is a simpler step that solves the imminent problem of "holy shit my rustc is sooo slow". Funny consequence: This now means compiling the standard library with dbeug assertions makes it faster (than without, when using debug assertions downstream)! r? ```@saethlin``` (or anyone else if someone wants to review this) fixes #121110, supposedly
2024-02-20Auto merge of #120863 - saethlin:slice-get-checked, r=the8472bors-26/+42
Use intrinsics::debug_assertions in debug_assert_nounwind This is the first item in https://github.com/rust-lang/rust/issues/120848. Based on the benchmarking in this PR, it looks like, for the programs in our benchmark suite, enabling all these additional checks does not introduce significant compile-time overhead, with the single exception of `Alignment::new_unchecked`. Therefore, I've added `#[cfg(debug_assertions)]` to that one call site, so that it remains compiled out in the distributed standard library. The trailing commas in the previous calls to `debug_assert_nounwind!` were causing the macro to expand to `panic_nouwnind_fmt`, which requires more work to set up its arguments, and that overhead alone is measured between this perf run and the next: https://github.com/rust-lang/rust/pull/120863#issuecomment-1937423502
2024-02-20fix doc linkYuri Astrakhan-1/+1
2024-02-20A much simpler version of writeYuri Astrakhan-28/+10
2024-02-20remove constYuri Astrakhan-1/+1
2024-02-20add safety textYuri Astrakhan-0/+1
2024-02-20Fix inlining issue for non-const caseYuri Astrakhan-12/+20
2024-02-20Use intrinsicYuri Astrakhan-0/+13
2024-02-20perf: improve write_fmt to handle simple stringsYuri Astrakhan-4/+6
Per @dtolnay suggestion in https://github.com/serde-rs/serde/pull/2697#issuecomment-1940376414 - attempt to speed up performance in the cases of a simple string format without arguments: ```rust write!(f, "text") -> f.write_str("text") ```
2024-02-19Add more inline(always) to fix opt-level=z test on wasm32Ben Kimock-2/+2
2024-02-19Convert debug_assert_nounwind to intrinsics::debug_assertionsBen Kimock-24/+40
2024-02-19Make `is_nonoverlapping` `#[inline]`Nilstrieb-0/+1
It showed up with 3% execution time in a compiler profile.
2024-02-19Make intrinsic fallback bodies cross-crate inlineableNilstrieb-0/+6
This change was prompted by the stage1 compiler spending 4% of its time when compiling the polymorphic-recursion MIR opt test in `unlikely`. Intrinsic fallback bodies like `unlikely` should always be inlined, it's very silly if they are not. To do this, we enable the fallback bodies to be cross-crate inlineable. Not that this matters for our workloads since the compiler never actually _uses_ the "fallback bodies", it just uses whatever was cfg(bootstrap)ped, so I've also added `#[inline]` to those.
2024-02-19Always inline check in `assert_unsafe_precondition` with cfg(debug_assertions)Nilstrieb-1/+8
The current complexities in `assert_unsafe_precondition` are delicately balancing several concerns, among them compile times for the cases where there are no debug assertions. This comes at a large runtime cost when the assertions are enabled, making the debug assertion compiler a lot slower, which is very annoying. To avoid this, we always inline the check when building with debug assertions. Numbers (compiling stage1 library after touching core): - master: 80s - just adding `#[inline(always)]` to the `cfg(bootstrap)` `debug_assertions`: 67s - this: 54s So this seems like a good solution. I think we can still get the same run-time perf improvements for other users too by massaging this code further (see my other PR about adding `#[rustc_no_mir_inline]`) but this is a simpler step that solves the imminent problem of "holy shit my rustc is sooo slow". Funny consequence: This now means compiling the standard library with dbeug assertions makes it faster (than without, when using debug assertions downstream)!
2024-02-19Rollup merge of #121272 - pitaj:diag_items-legacy_numeric_constants, r=NilstriebMatthias Krüger-0/+32
Add diagnostic items for legacy numeric constants For rust-lang/rust-clippy#12312
2024-02-19Rollup merge of #121041 - Nilstrieb:into-the-future-of-2024, r=Mark-SimulacrumMatthias Krüger-2/+6
Add `Future` and `IntoFuture` to the 2024 prelude Implements rust-lang/rfcs#3509.
2024-02-19Rollup merge of #119808 - GnomedDev:encode-charsearcher-size-in-type, ↵Matthias Krüger-11/+23
r=Mark-Simulacrum Store core::str::CharSearcher::utf8_size as u8 This is already relied on being smaller than u8 due to the `safety invariant: utf8_size must be less than 5`, so this helps LLVM optimize and maybe improve copies due to padding instead of unused bytes.
2024-02-19Refactor trait implementations in `core::convert::num`.Markus Reiter-367/+325
2024-02-18Add `Future` and `IntoFuture` to the 2024 preludeNilstrieb-2/+6
Implements RFC 3509.
2024-02-18diagnostic items for legacy numeric constantsPeter Jaszkowiak-0/+32
2024-02-17Implement `NonZero` traits generically.Markus Reiter-179/+211
2024-02-17Auto merge of #121204 - cuviper:flatten-one-shot, r=the8472bors-12/+209
Specialize flattening iterators with only one inner item For iterators like `Once` and `option::IntoIter` that only ever have a single item at most, the front and back iterator states in `FlatMap` and `Flatten` are a waste, as they're always consumed already. We can use specialization for these types to simplify the iterator methods. It's a somewhat common pattern to use `flatten()` for options and results, even recommended by [multiple][1] [clippy][2] [lints][3]. The implementation is more efficient with `filter_map`, as mentioned in [clippy#9377], but this new specialization should close some of that gap for existing code that flattens. [1]: https://rust-lang.github.io/rust-clippy/master/#filter_map_identity [2]: https://rust-lang.github.io/rust-clippy/master/#option_filter_map [3]: https://rust-lang.github.io/rust-clippy/master/#result_filter_map [clippy#9377]: https://github.com/rust-lang/rust-clippy/issues/9377
2024-02-17Allow newly added non_local_definitions in stdUrgau-0/+2
2024-02-17Rollup merge of #121192 - oli-obk:intrinsics2.0, r=WaffleLapkinGuillaume Boisseau-43/+59
Give some intrinsics fallback bodies cc #93145
2024-02-17Rollup merge of #121187 - Takashiidobe:takashi/examples-for-quickselect, ↵Guillaume Boisseau-6/+21
r=Nilstrieb Add examples to document the return type of quickselect functions Currently, `select_nth_unstable`, `select_nth_unstable_by`, and `select_nth_unstable_by_key`'s examples do not show how to use the return values of the functions in an example, so this PR adds that in. Note: I didn't know what to call the parameters, so I settled on lesser, median, greater because the example is used for median finding so I retained that naming for the pivot, but lesser and greater are poor names for the example that sorts in descending order, because lesser and greater are then flipped. I think it's common to say "lo" and "hi" for low and high respectively, but that's also not great when the comparator flips the elements. Otherwise, "left" and "right" are also commonly used but I think that's poor naming because some languages read right to left so those names are also unintuitive. Lesser and greater are also not that great but I found a test that used `less`, `equal`, `greater` so I took that: https://github.com/rust-lang/rust/blob/dfa88b328f969871d12dba3b2c0257ab3ea6703a/library/core/tests/slice.rs#L1962
2024-02-17Auto merge of #120563 - reitermarkus:generic-nonzero-get, r=dtolnaybors-20/+21
Make `NonZero::get` generic. Tracking issue: https://github.com/rust-lang/rust/issues/120257 Depends on https://github.com/rust-lang/rust/pull/120521. r? `@dtolnay`
2024-02-17Auto merge of #120741 - a1phyr:safe_buffer_advance, r=m-ou-sebors-1/+21
Make `io::BorrowedCursor::advance` safe This also keeps the old `advance` method under `advance_unchecked` name. This makes pattern like `std::io::default_read_buf` safe to write.
2024-02-16Clarify the flatten specialization commentJosh Stone-2/+2
2024-02-16Give the (`un`)`likely` intrinsics fallback bodiesOli Scherer-31/+37
2024-02-16Give the `assume` intrinsic a fallback bodyOli Scherer-13/+23
2024-02-16Specialize flattening iterators with only one inner itemJosh Stone-12/+209
For iterators like `Once` and `option::IntoIter` that only ever have a single item at most, the front and back iterator states in `FlatMap` and `Flatten` are a waste, as they're always consumed already. We can use specialization for these types to simplify the iterator methods. It's a somewhat common pattern to use `flatten()` for options and results, even recommended by [multiple][1] [clippy][2] [lints][3]. The implementation is more efficient with `filter_map`, as mentioned in [clippy#9377], but this new specialization should close some of that gap for existing code that flattens. [1]: https://rust-lang.github.io/rust-clippy/master/#filter_map_identity [2]: https://rust-lang.github.io/rust-clippy/master/#option_filter_map [3]: https://rust-lang.github.io/rust-clippy/master/#result_filter_map [clippy#9377]: https://github.com/rust-lang/rust-clippy/issues/9377
2024-02-16Add examples to document the return type of `select_nth_unstable`, ↵Takashiidobe-6/+21
`select_nth_unstable_by`, and `select_nth_unstable_by_key`.
2024-02-16Auto merge of #116385 - kornelski:maybe-rename, r=Amanieubors-13/+13
Rename MaybeUninit::write_slice A step to push #79995 forward. https://github.com/rust-lang/libs-team/issues/122 also suggested to make them inherent methods, but they can't be — they'd conflict with slice's regular methods.
2024-02-16Auto merge of #120500 - oli-obk:intrinsics2.0, r=WaffleLapkinbors-95/+98
Implement intrinsics with fallback bodies fixes #93145 (though we can port many more intrinsics) cc #63585 The way this works is that the backend logic for generating custom code for intrinsics has been made fallible. The only failure path is "this intrinsic is unknown". The `Instance` (that was `InstanceDef::Intrinsic`) then gets converted to `InstanceDef::Item`, which represents the fallback body. A regular function call to that body is then codegenned. This is currently implemented for * codegen_ssa (so llvm and gcc) * codegen_cranelift other backends will need to adjust, but they can just keep doing what they were doing if they prefer (though adding new intrinsics to the compiler will then require them to implement them, instead of getting the fallback body). cc `@scottmcm` `@WaffleLapkin` ### todo * [ ] miri support * [x] default intrinsic name to name of function instead of requiring it to be specified in attribute * [x] make sure that the bodies are always available (must be collected for metadata)
2024-02-16Auto merge of #120486 - reitermarkus:use-generic-nonzero, r=dtolnaybors-168/+168
Use generic `NonZero` internally. Tracking issue: https://github.com/rust-lang/rust/issues/120257
2024-02-16Rollup merge of #121155 - tspiteri:strict-doc-overflow, r=NilstriebGuillaume Gomez-0/+79
doc: add note about panicking examples for strict_overflow_ops The first commit adds a note before the panicking examples for strict_overflow_ops to make it clearer that the following examples should panic and why, without needing the reader to hover the mouse over the information icon. The second commit adds panicking examples for division by zero operations for strict division operations on unsigned numbers. The signed numbers already have two panicking examples each: one for division by zero and one for overflowing division (`MIN/-1`); this commit includes the division by zero examples for the unsigned numbers.
2024-02-16Rollup merge of #120971 - PizzasBear:patch-1, r=NilstriebGuillaume Gomez-1/+1
Fix comment in core/src/str/validations.rs Fix minor issue in the comment
2024-02-16Rollup merge of #120777 - Marcondiro:unicode15-1, r=ManishearthGuillaume Gomez-6/+6
Bump Unicode to version 15.1.0, regenerate tables r? ```@Manishearth```
2024-02-15doc: panicking division by zero examples for unsigned strict div opsTrevor Spiteri-0/+27
2024-02-15doc: add note before panicking examples for strict_overflow_opsTrevor Spiteri-0/+52
2024-02-15Add slice::try_rangeltdk-5/+56
2024-02-15Auto merge of #119863 - tmiasko:will-wake, r=m-ou-sebors-1/+3
Waker::will_wake: Compare vtable address instead of its content Optimize will_wake implementation by comparing vtable address instead of its content. The existing best practice to avoid false negatives from will_wake is to define a waker vtable as a static item. That approach continues to works with the new implementation. While this potentially changes the observable behaviour, the function is documented to work on a best-effort basis. The PartialEq impl for RawWaker remains as it was.
2024-02-15Add ASCII fast-path for `char::is_grapheme_extended`Arpad Borsos-1/+1
I discovered that `impl Debug for str` is quite slow because it ends up doing a `unicode_data::grapheme_extend::lookup` for each char, which ends up doing a binary search. This introduces a fast-path for ASCII chars which do not have this property. The `lookup` is thus completely gone from profiles.
2024-02-15Rollup merge of #121082 - peterjoel:atomic-docs, r=cuviperMatthias Krüger-2/+3
Clarified docs on non-atomic oprations on owned/mut refs to atomics I originally misinterpreted the documentation to mean that the compiler can/will automatically optimise away atomic operations whenever the data is owned or mutably referenced. On re-reading I think it is not technically incorrect, but specifically mentioning _how_ the atomic operations can be avoided also prevents this misunderstanding.
2024-02-15Rollup merge of #111106 - Stargateur:doc/format_args, r=m-ou-seMatthias Krüger-0/+8
Add known issue of let binding to format_args doc Simply add doc about https://github.com/rust-lang/rust/issues/92698. `@rustbot` label +T-rustdoc -T-libs r? `@GuillaumeGomez`
2024-02-15Replace `NonZero::<_>::new` with `NonZero::new`.Markus Reiter-35/+31
2024-02-15Use generic `NonZero` internally.Markus Reiter-168/+172
2024-02-14Clarified docs on non-atomic oprations on owned/mut refs to atomicsPeter Hall-2/+3
2024-02-14Rollup merge of #121024 - joseluis:feat-asciichar-default, r=scottmcmOli Scherer-1/+4
implement `Default` for `AsciiChar` This implements `Default` for `AsciiChar` in order to match `char`'s implementation. From all the different possible ways to do this I think the clearest one is to have both `char` and `AsciiChar` impls together. I've also updated the doc-comment of the default variant since rustdoc doesn't seem to indicate it otherwise. Probably the text could be improved, though. I couldn't find any similar examples in the codebase and suggestions are welcomed. r? `@scottmcm`