about summary refs log tree commit diff
path: root/library/core/src
AgeCommit message (Collapse)AuthorLines
2023-01-23Document missing unsafe blocksLukas Bergdoll-4/+12
2023-01-22Flip scanning direction of stable sortLukas Bergdoll-45/+67
Memory pre-fetching prefers forward scanning vs backwards scanning, and the code-gen is usually better. For the most sensitive types such as integers, these are planned to be merged bidirectionally at once. So there is no benefit in scanning backwards. The largest perf gains are seen for full ascending and descending inputs, which see 1.5x speedups. Random inputs benefit too, and some patterns can loose out, but these losses are minimal.
2023-01-22Unify insertion sort implementationsLukas Bergdoll-171/+188
Avoid duplicate insertion sort implementations. Optimize implementations.
2023-01-22Rollup merge of #107180 - nvzqz:rm-fmt-ref, r=joshtriplettMatthias Krüger-30/+30
Remove unnecessary `&format!` These were likely from before the `PartialEq<str>` impl for `&String`.
2023-01-21Rollup merge of #106144 - tgross35:patch-1, r=Mark-SimulacrumMichael Goulet-0/+69
Improve the documentation of `black_box` There don't seem to be many great resources on how `black_box` should be used, so I added some information here
2023-01-21Remove unnecessary `&format!`Nikolai Vazquez-30/+30
These were likely from before the `PartialEq<str>` impl for `&String`.
2023-01-21debug assertions for `slice::split_at_unchecked`, `str::get_unchecked`Peter Jaszkowiak-35/+44
2023-01-21Use NonNull in merge_sortLukas Bergdoll-15/+19
This is more clear about the intent of the pointer and avoids problems if the allocation returns a null pointer.
2023-01-20Rollup merge of #104672 - Voultapher:unify-sort-modules, r=thomccMichael Goulet-1/+521
Unify stable and unstable sort implementations in same core module This moves the stable sort implementation to the core::slice::sort module. By virtue of being in core it can't access `Vec`. The two `Vec` used by merge sort, `buf` and `runs`, are modelled as custom types that implement the very limited required `Vec` interface with the help of provided allocation and free functions. This is done to allow future re-use of functions and logic between stable and unstable sort. Such as `insert_head`. This is in preparation of #100856 and #104116. It only moves code, it *doesn't* change any of the sort related logic. This unlocks the ability to share `insert_head`, `insert_tail`, `swap_if_less` `merge` and more. Tagging ````@Mark-Simulacrum```` I hope this allows progress on #100856, by moving `merge_sort` here I hope future changes will be easier to review.
2023-01-20Rollup merge of #107067 - tmiasko:custom-mir-storage-statements, r=oli-obkMatthias Krüger-0/+2
Custom MIR: Support storage statements r? `@oli-obk` `@JakobDegen`
2023-01-19Add `rustc_on_unimplemented` on `Sync` for cell typesNilstrieb-0/+56
Suggest using a lock instead.
2023-01-19Add `OnceCell<T>: !Sync` impl for diagnosticsNilstrieb-0/+4
2023-01-19Custom MIR: Support storage statementsTomasz Miąsko-0/+2
2023-01-19Transform async ResumeTy in generator transformArpad Borsos-0/+5
- Eliminates all the `get_context` calls that async lowering created. - Replace all `Local` `ResumeTy` types with `&mut Context<'_>`. The `Local`s that have their types replaced are: - The `resume` argument itself. - The argument to `get_context`. - The yielded value of a `yield`. The `ResumeTy` hides a `&mut Context<'_>` behind an unsafe raw pointer, and the `get_context` function is being used to convert that back to a `&mut Context<'_>`. Ideally the async lowering would not use the `ResumeTy`/`get_context` indirection, but rather directly use `&mut Context<'_>`, however that would currently lead to higher-kinded lifetime errors. See <https://github.com/rust-lang/rust/issues/105501>. The async lowering step and the type / lifetime inference / checking are still using the `ResumeTy` indirection for the time being, and that indirection is removed here. After this transform, the generator body only knows about `&mut Context<'_>`.
2023-01-18Implement `SpecOptionPartialEq` for `cmp::Ordering`Scott McMurray-1/+9
2023-01-18Rollup merge of #103702 - ↵Dylan DPC-48/+15
WaffleLapkin:lift-sized-bounds-from-pointer-methods-where-applicable, r=m-ou-se Lift `T: Sized` bounds from some `strict_provenance` pointer methods This PR removes requirement for `T` (pointee type) to be `Sized` to call `pointer::{addr, expose_addr, with_addr, map_addr}`. These functions don't use `T`'s size, so there is no reason for them to require this. Updated public API: cc ``@Gankra,`` #95228 r? libs-api
2023-01-18Rollup merge of #106997 - Sp00ph:introselect, r=scottmcmMatthias Krüger-0/+22
Add heapsort fallback in `select_nth_unstable` Addresses #102451 and #106933. `slice::select_nth_unstable` uses a quick select implementation based on the same pattern defeating quicksort algorithm that `slice::sort_unstable` uses. `slice::sort_unstable` uses a recursion limit and falls back to heapsort if there were too many bad pivot choices, to ensure O(n log n) worst case running time (known as introsort). However, `slice::select_nth_unstable` does not have such a fallback strategy, which leads to it having a worst case running time of O(n²) instead. #102451 links to a playground which generates pathological inputs that show this quadratic behavior. On my machine, a randomly generated slice of length `1 << 19` takes ~200µs to calculate its median, whereas a pathological input of the same length takes over 2.5s. This PR adds an iteration limit to `select_nth_unstable`, falling back to heapsort, which ensures an O(n log n) worst case running time (introselect). With this change, there was no noticable slowdown for the random input, but the same pathological input now takes only ~1.2ms. In the future it might be worth implementing something like Median of Medians or Fast Deterministic Selection instead, which guarantee O(n) running time for all possible inputs. I've left this as a `FIXME` for now and only implemented the heapsort fallback to minimize the needed code changes. I still think we should clarify in the `select_nth_unstable` docs that the worst case running time isn't currently O(n) (the original reason that #102451 was opened), but I think it's a lot better to be able to guarantee O(n log n) instead of O(n²) for the worst case.
2023-01-17Rollup merge of #106889 - scottmcm:windows-mut, r=cuviperMatthias Krüger-0/+16
Mention the lack of `windows_mut` in `windows` This is a common request, going back to at least 2015 (#23783), so mention in the docs that it can't be done and offer a workaround using <https://doc.rust-lang.org/std/cell/struct.Cell.html#method.as_slice_of_cells>. (See also URLO threads like <https://internals.rust-lang.org/t/a-windows-mut-method-on-slice/16941/10?u=scottmcm>.)
2023-01-17Add heapsort fallback in `select_nth_unstable`Markus Everling-0/+22
2023-01-16Constify `TypeId` ordering implsonestacked-1/+2
2023-01-16Implement DoubleEnded and ExactSize for Take<Repeat> and Take<RepeatWith>Michal Nazarewicz-0/+57
Repeat iterator always returns the same element and behaves the same way backwards and forwards. Take iterator can trivially implement backwards iteration over Repeat inner iterator by simply doing forwards iteration. DoubleEndedIterator is not currently implemented for Take<Repeat<T>> because Repeat doesn’t implement ExactSizeIterator which is a required bound on DEI implementation for Take. Similarly, since Repeat is an infinite iterator which never stops, Take can trivially know how many elements it’s going to return. This allows implementing ExactSizeIterator on Take<Repeat<T>>. While at it, observe that ExactSizeIterator can also be implemented for Take<RepeatWhile<F>> so add that implementation too. Since in contrast to Repeat, RepeatWhile doesn’t guarante to always return the same value, DoubleEndedIterator isn’t implemented. Those changes render core::iter::repeat_n somewhat redundant. Issue: https://github.com/rust-lang/rust/issues/104434 Issue: https://github.com/rust-lang/rust/issues/104729
2023-01-15replace manual ptr arithmetic with ptr_subThe 8472-23/+7
2023-01-15Rollup merge of #106880 - tspiteri:borrowing-sub-typo, r=cuviperMatthias Krüger-1/+1
doc: fix typo
2023-01-14Mention the lack of `windows_mut` in `windows`Scott McMurray-0/+16
2023-01-14doc: fix typoTrevor Spiteri-1/+1
2023-01-14Rollup merge of #106860 - anden3:doc-double-spaces, r=Dylan-DPCMatthias Krüger-19/+19
Remove various double spaces in the libraries. I was just pretty bothered by this when reading the source for a function, and was suggested to check if this happened elsewhere.
2023-01-14Rollup merge of #105526 - Xiretza:iter-from-generator-derive, r=scottmcmMatthias Krüger-4/+19
libcore: make result of iter::from_generator Clone `@rustbot` label +A-generators
2023-01-14Fix some missed double spaces.André Vennberg-4/+4
2023-01-14Remove various double spaces in source comments.André Vennberg-15/+15
2023-01-14Use associated items of `char` instead of freestanding items in `core::char`Lukas Markeffsky-31/+12
2023-01-14Rollup merge of #106762 - WaffleLapkin:atomicptr+as_mut_ptr, r=m-ou-seYuki Okushi-2/+38
Add `AtomicPtr::as_mut_ptr` See https://github.com/rust-lang/rust/issues/66893#issuecomment-720125447 r? thomcc
2023-01-14Rollup merge of #105172 - alexs-sh:issue-98861-fix-next, r=scottmcmYuki Okushi-0/+5
Added error documentation for write_fmt This continuation of work at rust-lang#98861
2023-01-14Rollup merge of #104965 - zacklukem:p-option-as_ref-docs, r=scottmcmYuki Okushi-6/+7
reword Option::as_ref and Option::map examples The description for the examples of `Option::as_ref` and `Option::map` imply that the example is only doing type conversion, when it is actually finding the length of a string. Changes the wording to imply that some operation is being run on the value contained in the `Option` closes #104476
2023-01-13Allow fmt::Arguments::as_str() to return more Some(_).Mara Bos-3/+20
2023-01-12Implement `signum` with `Ord`Scott McMurray-5/+6
2023-01-13Auto merge of #106004 - fee1-dead-contrib:const-closures, r=oli-obkbors-10/+17
Const closures cc https://github.com/rust-lang/rust/issues/106003
2023-01-13Rollup merge of #106740 - petar-dambovaliev:float-iterator-hint, r=NilstriebYuki Okushi-0/+5
Adding a hint on iterator type errors Issue reference https://github.com/rust-lang/rust/issues/106728 - [x] add a case in the attribute - [x] add a test closes #106728
2023-01-12add note for float iteratorPetar Dambovaliev-0/+5
2023-01-12Make `// SAFETY` comment part of the doctest, and not surrounding codeMaybe Waffle-1/+1
2023-01-12Remove unused `mut` from a doctestMaybe Waffle-1/+1
2023-01-12Add `AtomicPtr::as_mut_ptr`Maybe Waffle-0/+36
2023-01-11Rollup merge of #106323 - starkat99:stabilize-f16c_target_feature, ↵Michael Goulet-1/+1
r=petrochenkov Stabilize f16c_target_feature Resolves https://github.com/rust-lang/stdarch/issues/1234 Library PR for stabilizing corresponding intrinsics: https://github.com/rust-lang/stdarch/pull/1366 See also #44839 tracking issue for target_feature
2023-01-11Rollup merge of #103800 - danielhenrymantilla:stabilize-pin-macro, r=dtolnayMichael Goulet-7/+3
Stabilize `::{core,std}::pin::pin!` As discussed [over here](https://github.com/rust-lang/rust/issues/93178#issuecomment-1295843548), it looks like a decent time to stabilize the `pin!` macro. ### Public API ```rust // in module `core::pin` /// API: `fn pin<T>($value: T) -> Pin<&'local mut T>` pub macro pin($value:expr $(,)?) { … } ``` - Tracking issue: #93178 (now all this needs is an FCP by the proper team?)
2023-01-11Rollup merge of #103236 - tspiteri:redoc-int-adc-sbb, r=m-ou-seMichael Goulet-36/+75
doc: rewrite doc for signed int::{carrying_add,borrowing_sub} Reword the documentation for bigint helper methods, signed `int::{carrying_add,borrowing_sub}` (#85532). This change is a follow-up to #101889, which was for the unsigned methods.
2023-01-12test use in libcoreDeadbeef-10/+17
2023-01-12Make core::fmt::rt::v1::Argument::new const+inline.Mara Bos-1/+2
2023-01-11Stabilize `::{core,std}::pin::pin!`Daniel Henry-Mantilla-7/+3
2023-01-11Add new fn to core::fmt::rt::v1::Argument.Mara Bos-0/+13
2023-01-11Turn format arguments types into lang items.Mara Bos-1/+7
2023-01-10Rollup merge of #105034 - HintringerFabian:improve_iterator_flatten_doc, ↵Yuki Okushi-0/+12
r=cuviper Add example for iterator_flatten Adds an Example to iterator_flatten Fixes #82687