Commit Graph

6180 Commits

Author SHA1 Message Date
Malobre
9ac73cbdc6
docs: add missing "the" to str::strip_prefix doc 2024-02-20 18:05:55 +01:00
bors
2b43e75c98 Auto merge of #120863 - saethlin:slice-get-checked, r=the8472
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-20 14:04:57 +00:00
Ben Kimock
4a12f82785 Add more inline(always) to fix opt-level=z test on wasm32 2024-02-19 20:38:11 -05:00
Ben Kimock
581e171773 Convert debug_assert_nounwind to intrinsics::debug_assertions 2024-02-19 20:38:09 -05:00
Nilstrieb
0b59748807 Make is_nonoverlapping #[inline]
It showed up with 3% execution time in a compiler profile.
2024-02-19 19:28:04 +01:00
Matthias Krüger
c2cc066761
Rollup merge of #121272 - pitaj:diag_items-legacy_numeric_constants, r=Nilstrieb
Add diagnostic items for legacy numeric constants

For rust-lang/rust-clippy#12312
2024-02-19 13:04:34 +01:00
Matthias Krüger
cf0b36a1c5
Rollup merge of #121041 - Nilstrieb:into-the-future-of-2024, r=Mark-Simulacrum
Add `Future` and `IntoFuture` to the 2024 prelude

Implements rust-lang/rfcs#3509.
2024-02-19 13:04:33 +01:00
Matthias Krüger
c5da0382c8
Rollup merge of #119808 - GnomedDev:encode-charsearcher-size-in-type, 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-19 13:04:32 +01:00
Nilstrieb
bd8a1a417a Add Future and IntoFuture to the 2024 prelude
Implements RFC 3509.
2024-02-18 23:20:05 +01:00
Peter Jaszkowiak
d9c1c73d2c diagnostic items for legacy numeric constants 2024-02-18 12:08:16 -07:00
bors
6672c16afc Auto merge of #121204 - cuviper:flatten-one-shot, r=the8472
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-17 20:18:54 +00:00
Guillaume Boisseau
936b666c4a
Rollup merge of #121192 - oli-obk:intrinsics2.0, r=WaffleLapkin
Give some intrinsics fallback bodies

cc #93145
2024-02-17 11:23:08 +01:00
Guillaume Boisseau
f3d9abc590
Rollup merge of #121187 - Takashiidobe:takashi/examples-for-quickselect, 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: dfa88b328f/library/core/tests/slice.rs (L1962)
2024-02-17 11:23:07 +01:00
bors
4316d0c625 Auto merge of #120563 - reitermarkus:generic-nonzero-get, r=dtolnay
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-17 02:30:53 +00:00
bors
405b22f1a3 Auto merge of #120741 - a1phyr:safe_buffer_advance, r=m-ou-se
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-17 00:23:15 +00:00
Josh Stone
c36ae932f9 Clarify the flatten specialization comment 2024-02-16 16:08:01 -08:00
Oli Scherer
dd40a80102 Give the (un)likely intrinsics fallback bodies 2024-02-16 22:26:01 +00:00
Oli Scherer
6a671bdbf1 Give the assume intrinsic a fallback body 2024-02-16 22:24:50 +00:00
Josh Stone
974bc455ee 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-16 13:49:29 -08:00
Takashiidobe
b49bd0bba0 Add examples to document the return type of select_nth_unstable, select_nth_unstable_by, and select_nth_unstable_by_key. 2024-02-16 09:20:51 -05:00
bors
ae9d7b0c64 Auto merge of #116385 - kornelski:maybe-rename, r=Amanieu
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-16 14:11:10 +00:00
bors
dfa88b328f Auto merge of #120500 - oli-obk:intrinsics2.0, r=WaffleLapkin
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-16 09:53:01 +00:00
bors
1be468815c Auto merge of #120486 - reitermarkus:use-generic-nonzero, r=dtolnay
Use generic `NonZero` internally.

Tracking issue: https://github.com/rust-lang/rust/issues/120257
2024-02-16 07:46:31 +00:00
Guillaume Gomez
2a216bb53b
Rollup merge of #121155 - tspiteri:strict-doc-overflow, r=Nilstrieb
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-16 00:27:35 +01:00
Guillaume Gomez
1630e04509
Rollup merge of #120971 - PizzasBear:patch-1, r=Nilstrieb
Fix comment in core/src/str/validations.rs

Fix minor issue in the comment
2024-02-16 00:27:31 +01:00
Guillaume Gomez
3803469473
Rollup merge of #120777 - Marcondiro:unicode15-1, r=Manishearth
Bump Unicode to version 15.1.0, regenerate tables

r? ```@Manishearth```
2024-02-16 00:27:31 +01:00
Trevor Spiteri
675d092e3e doc: panicking division by zero examples for unsigned strict div ops 2024-02-15 18:41:30 +01:00
Trevor Spiteri
fdc56b6886 doc: add note before panicking examples for strict_overflow_ops 2024-02-15 18:38:36 +01:00
bors
62fb0db9a5 Auto merge of #119863 - tmiasko:will-wake, r=m-ou-se
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-15 14:43:29 +00:00
Matthias Krüger
e5186aaf4d
Rollup merge of #121082 - peterjoel:atomic-docs, r=cuviper
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-15 09:20:19 +01:00
Matthias Krüger
0238d2619f
Rollup merge of #111106 - Stargateur:doc/format_args, r=m-ou-se
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-15 09:20:16 +01:00
Markus Reiter
a90cc05233
Replace NonZero::<_>::new with NonZero::new. 2024-02-15 08:09:42 +01:00
Markus Reiter
746a58d435
Use generic NonZero internally. 2024-02-15 08:09:42 +01:00
Peter Hall
9cccf20899 Clarified docs on non-atomic oprations on owned/mut refs to atomics 2024-02-14 20:14:45 +00:00
Oli Scherer
c1a80211f5
Rollup merge of #121024 - joseluis:feat-asciichar-default, r=scottmcm
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`
2024-02-14 11:53:40 +01:00
Oli Scherer
407de0ee33
Rollup merge of #118890 - Amanieu:allocator-lifetime, r=Mark-Simulacrum
Clarify the lifetimes of allocations returned by the `Allocator` trait

The previous definition (accidentally) disallowed the implementation of stack-based allocators whose memory would become invalid once the lifetime of the allocator type ended.

This also ensures the validity of the following blanket implementation:
```rust
impl<A: Allocator> Allocator for &'_ A {}
```
2024-02-14 11:53:38 +01:00
Oli Scherer
5d114f3c99
Rollup merge of #116387 - kpreid:wake-doc, r=cuviper
Additional doc links and explanation of `Wake`.

This is intended to clarify:

* That `Wake` exists and can be used instead of `RawWaker`.
* How to construct a `Waker` when you are looking at `Wake` (which was previously only documented in the example).
2024-02-14 11:53:37 +01:00
GnomedDev
601f2d192e
Store core::str::CharSearcher::utf8_size as u8 2024-02-13 18:28:48 +00:00
Amanieu d'Antras
8e9c8dd10a Add information about allocation lifetime to Allocator::allocate 2024-02-13 14:12:51 +00:00
joseLuís
1c7ea307cf implement Default for AsciiChar 2024-02-13 12:04:44 +01:00
Tshepang Mbambo
142ab9e882 iterator.rs: remove "Basic usage" text
Only one example is given (for each method)
2024-02-12 22:22:14 +02:00
Oli Scherer
f35a2bd401 Support safe intrinsics with fallback bodies
Turn `is_val_statically_known` into such an intrinsic to demonstrate. It is perfectly safe to call after all.
2024-02-12 17:55:36 +00:00
Oli Scherer
6b73fe2d09 Give const_deallocate a default body 2024-02-12 17:52:05 +00:00
Oli Scherer
9a0743747f Teach llvm backend how to fall back to default bodies 2024-02-12 17:50:39 +00:00
Oli Scherer
531505f182 Check signature of intrinsics with fallback bodies 2024-02-12 17:44:53 +00:00
Amanieu d'Antras
fb5ed2986e Clarify the lifetimes of allocations returned by the Allocator trait
The previous definition (accidentally) disallowed the implementation of
stack-based allocators whose memory would become invalid once the
lifetime of the allocator type ended.

This also ensures the validity of the following blanket implementation:
```rust
impl<A: Allocator> Allocator for &'_ A {}
```
2024-02-12 14:02:30 +00:00
PizzasBear
fffcb4c877
Fix comment in core/src/str/validations.rs 2024-02-12 16:00:15 +02:00
Oli Scherer
92281c7e81 Implement intrinsics with fallback bodies 2024-02-12 09:44:22 +00:00
Matthias Krüger
d71154f80f
Rollup merge of #120888 - saethlin:unsafe-precondition-cleanup, r=RalfJung
assert_unsafe_precondition cleanup

I moved the polymorphic `is_nonoverlapping` into the `Cell` function that uses it and renamed `intrinsics::is_nonoverlapping_mono` to just `intrinsics::is_nonoverlapping`.

We now also have some docs for `intrinsics::debug_assertions`.

r? RalfJung
2024-02-11 23:19:10 +01:00
Matthias Krüger
3d7d709925
Rollup merge of #120880 - RalfJung:vtable-fnptr-partialeq, r=cuviper
add note on comparing vtables / function pointers

Fixes https://github.com/rust-lang/rust/issues/99388
Fixes https://github.com/rust-lang/rust/issues/117047
2024-02-11 23:19:09 +01:00