summary refs log tree commit diff
path: root/library/alloc/src
AgeCommit message (Collapse)AuthorLines
2024-01-25fix: Drop guard was deallocating with the incorrect sizeThe 8472-13/+25
InPlaceDstBufDrop holds onto the allocation before the shrinking happens which means it must deallocate the destination elements but the source allocation. (cherry picked from commit 5796b3c16733f3d9cb2f3476ed1dc0fe05b14e25)
2024-01-25remove alignment-changing in-place collectThe 8472-5/+8
Currently stable users can't benefit from this because GlobaAlloc doesn't support alignment-changing realloc and neither do most posix allocators. So in practice it always results in an extra memcpy. (cherry picked from commit 85d17879623116be76a68c2170c4cb6ff58f4ceb)
2024-01-25update internal ASCII art comment for vec specializationsThe 8472-7/+7
(cherry picked from commit b28a95391b85e17b1d2f7edc1115291d8a86bcd2)
2023-12-21update version placeholdersPietro Albini-2/+2
2023-12-20Auto merge of #106790 - the8472:rawvec-niche, r=scottmcmbors-15/+50
add more niches to rawvec Previously RawVec only had a single niche in its `NonNull` pointer. With this change it now has `isize::MAX` niches since half the value-space of the capacity field is never needed, we can't have a capacity larger than isize::MAX.
2023-12-14Update c_str.rsDaniel Huang-3/+3
2023-12-11add comment to RawVec::cap fieldThe 8472-0/+5
2023-12-11add more niches to rawvecThe 8472-15/+45
2023-12-10Auto merge of #118692 - surechen:remove_unused_imports, r=petrochenkovbors-31/+3
remove redundant imports detects redundant imports that can be eliminated. for #117772 : In order to facilitate review and modification, split the checking code and removing redundant imports code into two PR. r? `@petrochenkov`
2023-12-10Auto merge of #116949 - hamza1311:stablize-arc_unwrap_or_clone, r=dtolnaybors-4/+2
Stablize arc_unwrap_or_clone Fixes: #93610 This likely needs FCP. I created this PR as it's stabilization is trivial and FCP can be just conducted here. Not sure how to ping the libs API team (last attempt didn't work apparently according to GH UI)
2023-12-10remove redundant importssurechen-31/+3
detects redundant imports that can be eliminated. for #117772 : In order to facilitate review and modification, split the checking code and removing redundant imports code into two PR.
2023-12-09Auto merge of #114136 - TennyZhuang:linked-list-retain, r=thomccbors-0/+93
add LinkedList::{retain,retain_mut} Implement #114135 The API is consistent with other collections.
2023-12-07Auto merge of #117960 - zhiqiangxu:dry, r=workingjubileebors-5/+3
chore: avoid duplicate code in `Weak::inner`
2023-12-06Rollup merge of #117563 - 0xalpharush:docs/into-raw, r=workingjubileeMatthias Krüger-3/+11
docs: clarify explicitly freeing heap allocated memory The documentation for `Box::into_raw` didn't mention `drop` and wondered if I was doing something wrong. Based off [this](https://stackoverflow.com/questions/75441199/rust-how-do-i-correctly-free-heap-allocated-memory), I think it's helpful to include the more concise yet explicit way to free heap allocated memory. This is my first rust PR and I went through https://std-dev-guide.rust-lang.org/development/, but let me know if I missed something :)
2023-12-06Auto merge of #118460 - the8472:fix-vec-realloc, r=saethlinbors-7/+27
Fix in-place collect not reallocating when necessary Regression introduced in https://github.com/rust-lang/rust/pull/110353. This was [caught by miri](https://rust-lang.zulipchat.com/#narrow/stream/269128-miri/topic/Cron.20Job.20Failure.20.28miri-test-libstd.2C.202023-11.29/near/404764617) r? `@saethlin`
2023-12-06Don't repeat yourselfzhiqiangxu-5/+3
2023-12-05Auto merge of #118273 - AngelicosPhosphoros:dedup_2_loops_version_77772_2, ↵bors-12/+45
r=the8472 Split `Vec::dedup_by` into 2 cycles First cycle runs until we found 2 same elements, second runs after if there any found in the first one. This allows to avoid any memory writes until we found an item which we want to remove. This leads to significant performance gains if all `Vec` items are kept: -40% on my benchmark with unique integers. Results of benchmarks before implementation (including new benchmark where nothing needs to be removed): * vec::bench_dedup_all_100 74.00ns/iter +/- 13.00ns * vec::bench_dedup_all_1000 572.00ns/iter +/- 272.00ns * vec::bench_dedup_all_100000 64.42µs/iter +/- 19.47µs * __vec::bench_dedup_none_100 67.00ns/iter +/- 17.00ns__ * __vec::bench_dedup_none_1000 662.00ns/iter +/- 86.00ns__ * __vec::bench_dedup_none_10000 9.16µs/iter +/- 2.71µs__ * __vec::bench_dedup_none_100000 91.25µs/iter +/- 1.82µs__ * vec::bench_dedup_random_100 105.00ns/iter +/- 11.00ns * vec::bench_dedup_random_1000 781.00ns/iter +/- 10.00ns * vec::bench_dedup_random_10000 9.00µs/iter +/- 5.62µs * vec::bench_dedup_random_100000 449.81µs/iter +/- 74.99µs * vec::bench_dedup_slice_truncate_100 105.00ns/iter +/- 16.00ns * vec::bench_dedup_slice_truncate_1000 2.65µs/iter +/- 481.00ns * vec::bench_dedup_slice_truncate_10000 18.33µs/iter +/- 5.23µs * vec::bench_dedup_slice_truncate_100000 501.12µs/iter +/- 46.97µs Results after implementation: * vec::bench_dedup_all_100 75.00ns/iter +/- 9.00ns * vec::bench_dedup_all_1000 494.00ns/iter +/- 117.00ns * vec::bench_dedup_all_100000 58.13µs/iter +/- 8.78µs * __vec::bench_dedup_none_100 52.00ns/iter +/- 22.00ns__ * __vec::bench_dedup_none_1000 417.00ns/iter +/- 116.00ns__ * __vec::bench_dedup_none_10000 4.11µs/iter +/- 546.00ns__ * __vec::bench_dedup_none_100000 40.47µs/iter +/- 5.36µs__ * vec::bench_dedup_random_100 77.00ns/iter +/- 15.00ns * vec::bench_dedup_random_1000 681.00ns/iter +/- 86.00ns * vec::bench_dedup_random_10000 11.66µs/iter +/- 2.22µs * vec::bench_dedup_random_100000 469.35µs/iter +/- 20.53µs * vec::bench_dedup_slice_truncate_100 100.00ns/iter +/- 5.00ns * vec::bench_dedup_slice_truncate_1000 2.55µs/iter +/- 224.00ns * vec::bench_dedup_slice_truncate_10000 18.95µs/iter +/- 2.59µs * vec::bench_dedup_slice_truncate_100000 492.85µs/iter +/- 72.84µs Resolves #77772 P.S. Note that this is same PR as #92104 I just missed review then forgot about it. Also, I cannot reopen that pull request so I am creating a new one. I responded to remaining questions directly by adding commentaries to my code.
2023-12-05Split `Vec::dedup_by` into 2 cyclesAngelicosPhosphoros-12/+45
First cycle runs until we found 2 same elements, second runs after if there any found in the first one. This allows to avoid any memory writes until we found an item which we want to remove. This leads to significant performance gains if all `Vec` items are kept: -40% on my benchmark with unique integers. Results of benchmarks before implementation (including new benchmark where nothing needs to be removed): * vec::bench_dedup_all_100 74.00ns/iter +/- 13.00ns * vec::bench_dedup_all_1000 572.00ns/iter +/- 272.00ns * vec::bench_dedup_all_100000 64.42µs/iter +/- 19.47µs * __vec::bench_dedup_none_100 67.00ns/iter +/- 17.00ns__ * __vec::bench_dedup_none_1000 662.00ns/iter +/- 86.00ns__ * __vec::bench_dedup_none_10000 9.16µs/iter +/- 2.71µs__ * __vec::bench_dedup_none_100000 91.25µs/iter +/- 1.82µs__ * vec::bench_dedup_random_100 105.00ns/iter +/- 11.00ns * vec::bench_dedup_random_1000 781.00ns/iter +/- 10.00ns * vec::bench_dedup_random_10000 9.00µs/iter +/- 5.62µs * vec::bench_dedup_random_100000 449.81µs/iter +/- 74.99µs * vec::bench_dedup_slice_truncate_100 105.00ns/iter +/- 16.00ns * vec::bench_dedup_slice_truncate_1000 2.65µs/iter +/- 481.00ns * vec::bench_dedup_slice_truncate_10000 18.33µs/iter +/- 5.23µs * vec::bench_dedup_slice_truncate_100000 501.12µs/iter +/- 46.97µs Results after implementation: * vec::bench_dedup_all_100 75.00ns/iter +/- 9.00ns * vec::bench_dedup_all_1000 494.00ns/iter +/- 117.00ns * vec::bench_dedup_all_100000 58.13µs/iter +/- 8.78µs * __vec::bench_dedup_none_100 52.00ns/iter +/- 22.00ns__ * __vec::bench_dedup_none_1000 417.00ns/iter +/- 116.00ns__ * __vec::bench_dedup_none_10000 4.11µs/iter +/- 546.00ns__ * __vec::bench_dedup_none_100000 40.47µs/iter +/- 5.36µs__ * vec::bench_dedup_random_100 77.00ns/iter +/- 15.00ns * vec::bench_dedup_random_1000 681.00ns/iter +/- 86.00ns * vec::bench_dedup_random_10000 11.66µs/iter +/- 2.22µs * vec::bench_dedup_random_100000 469.35µs/iter +/- 20.53µs * vec::bench_dedup_slice_truncate_100 100.00ns/iter +/- 5.00ns * vec::bench_dedup_slice_truncate_1000 2.55µs/iter +/- 224.00ns * vec::bench_dedup_slice_truncate_10000 18.95µs/iter +/- 2.59µs * vec::bench_dedup_slice_truncate_100000 492.85µs/iter +/- 72.84µs Resolves #77772
2023-12-05Fix in-place collect not reallocating when necessaryThe 8472-7/+27
2023-11-29Auto merge of #118433 - matthiaskrgr:rollup-fi9lrwg, r=matthiaskrgrbors-0/+11
Rollup of 7 pull requests Successful merges: - #116839 (Implement thread parking for xous) - #118265 (remove the memcpy-on-equal-ptrs assumption) - #118269 (Unify `TraitRefs` and `PolyTraitRefs` in `ValuePairs`) - #118394 (Remove HIR opkinds) - #118398 (Add proper cfgs in std) - #118419 (Eagerly return `ExprKind::Err` on `yield`/`await` in wrong coroutine context) - #118422 (Fix coroutine validation for mixed panic strategy) r? `@ghost` `@rustbot` modify labels: rollup
2023-11-29Rollup merge of #118383 - ↵Matthias Krüger-0/+1
shepmaster:unused-tuple-struct-field-cleanup-stdlib, r=m-ou-se Address unused tuple struct fields in the standard library
2023-11-29Rollup merge of #118398 - mu001999:std/add_cfgs, r=thomccMatthias Krüger-0/+11
Add proper cfgs in std Detected by #118257
2023-11-28Address unused tuple struct fields in the standard libraryJake Goulding-0/+1
2023-11-28Auto merge of #110353 - the8472:in-place-flatten-chunks, r=cuviperbors-29/+128
Expand in-place iteration specialization to Flatten, FlatMap and ArrayChunks This enables the following cases to collect in-place: ```rust let v = vec![[0u8; 4]; 1024] let v: Vec<_> = v.into_iter().flatten().collect(); let v: Vec<Option<NonZeroUsize>> = vec![NonZeroUsize::new(0); 1024]; let v: Vec<_> = v.into_iter().flatten().collect(); let v = vec![u8; 4096]; let v: Vec<_> = v.into_iter().array_chunks::<4>().collect(); ``` Especially the nicheful-option-flattening should be useful in real code.
2023-11-28Add proper cfgsr0cky-0/+11
2023-11-25Rollup merge of #117968 - Urgau:stabilize-ptr-addr-eq, r=dtolnayMichael Goulet-1/+0
Stabilize `ptr::addr_eq` This PR stabilize the `ptr_addr_eq` library feature, representing: ```rust // core::ptr pub fn addr_eq<T: ?Sized, U: ?Sized>(p: *const T, q: *const U) -> bool; ``` FCP has already started [on the tracking issue](https://github.com/rust-lang/rust/issues/116324#issuecomment-1813008697) and is waiting on the final period comment. Note: stabilizing this feature is somewhat of requirement for a new T-lang lint, cf. https://github.com/rust-lang/rust/pull/117758#issuecomment-1813183686.
2023-11-20docs(GH-118094): make docs a bit more explicitPetr Portnov-3/+3
Signed-off-by: Petr Portnov <me@progrm-jarvis.ru>
2023-11-20chore(GH-118094): explicitly mark `_elem` as unusedPetr Portnov-1/+1
Signed-off-by: Petr Portnov <me@progrm-jarvis.ru>
2023-11-20feat: specialize `SpecFromElem` for `()`Petr Portnov-4/+19
While a better approach would be to implement it for all ZSTs which are `Copy` and have trivial `Clone`, the last property cannot be detected for now. Signed-off-by: Petr Portnov <me@progrm-jarvis.ru>
2023-11-16Stabilize ptr_addr_eq library featureUrgau-1/+0
2023-11-15Re-format code with new rustfmtMark Rousskov-3/+1
2023-11-15Bump cfg(bootstrap)sMark Rousskov-2/+2
2023-11-11Auto merge of #115694 - clarfonthey:std-hash-private, r=dtolnaybors-2/+2
Add `std::hash::{DefaultHasher, RandomState}` exports (needs FCP) This implements rust-lang/libs-team#267 to move the libstd hasher types to `std::hash` where they belong, instead of `std::collections::hash_map`. <details><summary>The below no longer applies, but is kept for clarity.</summary> This is a small refactor for #27242, which moves the definitions of `RandomState` and `DefaultHasher` into `std::hash`, but in a way that won't be noticed in the public API. I've opened rust-lang/libs-team#267 as a formal ACP to move these directly into the root of `std::hash`, but for now, they're at least separated out from the collections code in a way that will make moving that around easier. I decided to simply copy the rustdoc for `std::hash` from `core::hash` since I think it would be ideal for the two to diverge longer-term, especially if the ACP is accepted. However, I would be willing to factor them out into a common markdown document if that's preferred. </details>
2023-11-10Closure-consuming helper functions for `fmt::Debug` helpersJohn Millikin-0/+2
2023-11-05Auto merge of #116218 - tgross35:const-maybe-uninit-zeroed, r=dtolnaybors-1/+0
Stabilize `const_maybe_uninit_zeroed` and `const_mem_zeroed` Make `MaybeUninit::zeroed` and `mem::zeroed` const stable. Newly stable API: ```rust // core::mem pub const unsafe fn zeroed<T>() ->; impl<T> MaybeUninit<T> { pub const fn zeroed() -> MaybeUninit<T>; } ``` This relies on features based around `const_mut_refs`. Per `@RalfJung,` this should be OK since we do not leak any `&mut` to the user. For this to be possible, intrinsics `assert_zero_valid` and `assert_mem_uninitialized_valid` were made const stable. Tracking issue: #91850 Zulip discussion: https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/topic/.60const_mut_refs.60.20dependents r? libs-api `@rustbot` label -T-libs +T-libs-api +A-const-eval cc `@RalfJung` `@oli-obk` `@rust-lang/wg-const-eval`
2023-11-05Auto merge of #117503 - kornelski:hint-try-reserved, r=workingjubileebors-4/+14
Hint optimizer about try-reserved capacity This is #116568, but limited only to the less-common `try_reserve` functions to reduce bloat in debug binaries from debug info, while still addressing the main use-case #116570
2023-11-04Stabilize `const_maybe_uninit_zeroed`Trevor Gross-1/+0
Make `MaybeUninit::zeroed` const stable. Newly stable API: // core::mem impl<T> MaybeUninit<T> { pub const fn zeroed() -> MaybeUninit<T>; } Use of `const_mut_refs` should be acceptable since we do not leak the mutability. Tracking issue: #91850
2023-11-04docs: clarify explicitly freeing heap allocated memoryalpharush-3/+11
2023-11-02Add insta-stable std::hash::{DefaultHasher, RandomState} exportsltdk-2/+2
2023-11-02Hint optimizer about reserved capacityKornel-4/+14
2023-10-31delegate box error provideBugen Zhao-0/+4
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
2023-10-30Auto merge of #117332 - saethlin:panic-immediate-abort, r=workingjubileebors-6/+16
Increase the reach of panic_immediate_abort I wanted to use/abuse this recently as part of another project, and I was surprised how many panic-related things were left in my binaries if I built a large crate with the feature enabled along with LTO. These changes get all the panic-related symbols that I could find out of my set of locally installed Rust utilities.
2023-10-29Increase the reach of panic_immediate_abortBen Kimock-6/+16
2023-10-28mark constructor of `BinaryHeap` as const fncoekjan-2/+4
2023-10-25Stabilize `[const_]pointer_byte_offsets`Maybe Waffle-1/+0
2023-10-21Update boxed.rsGimbles-1/+1
2023-10-20s/generator/coroutine/Oli Scherer-3/+3
2023-10-20s/Generator/Coroutine/Oli Scherer-5/+5
2023-10-19Stablize arc_unwrap_or_cloneMuhammad Hamza-4/+2
2023-10-17Automatically enable cross-crate inlining for small functionsBen Kimock-0/+1