about summary refs log tree commit diff
path: root/library/alloc
AgeCommit message (Collapse)AuthorLines
2024-01-21Rollup merge of #120180 - Zalathar:vec-split-off-alternatives, r=dtolnayMatthias Krüger-0/+6
Document some alternatives to `Vec::split_off` One of the discussion points that came up in #119917 is that some people use `Vec::split_off` in cases where they probably shouldn't, because the alternatives (like `mem::take`) are hard to discover. This PR adds some suggestions to the documentation of `split_off` that should point people towards alternatives that might be more appropriate for their use-case. I've deliberately tried to keep these changes as simple and uncontroversial as possible, so that they don't depend on how the team decides to handle the concerns raised in #119917. That's why I haven't touched the existing documentation for `split_off`, and haven't added links to `split_off` to the documentation of other methods.
2024-01-21Rollup merge of #120145 - the8472:fix-inplace-dest-drop, r=cuviperMatthias Krüger-13/+25
fix: Drop guard was deallocating with the incorrect size InPlaceDstBufDrop holds onto the allocation before the shrinking happens which means it must deallocate the destination elements but the source allocation. Thanks `@cuviper` for spotting this.
2024-01-21Auto merge of #85528 - the8472:iter-markers, r=dtolnaybors-2/+6
Implement iterator specialization traits on more adapters This adds * `TrustedLen` to `Skip` and `StepBy` * `TrustedRandomAccess` to `Skip` * `InPlaceIterable` and `SourceIter` to `Copied` and `Cloned` The first two might improve performance in the compiler itself since `skip` is used in several places. Constellations that would exercise the last point are probably rare since it would require an owning iterator that has references as Items somewhere in its iterator pipeline. Improvements for `Skip`: ``` # old test iter::bench_skip_trusted_random_access ... bench: 8,335 ns/iter (+/- 90) # new test iter::bench_skip_trusted_random_access ... bench: 2,753 ns/iter (+/- 27) ```
2024-01-21Document some alternatives to `Vec::split_off`Zalathar-0/+6
2024-01-20Rollup merge of #120116 - the8472:only-same-alignments, r=cuviperGuillaume Gomez-12/+15
Remove alignment-changing in-place collect This removes the alignment-changing in-place collect optimization introduced in #110353 Currently stable users can't benefit from the optimization because GlobaAlloc doesn't support alignment-changing realloc and neither do most posix allocators. So in practice it has a negative impact on performance. Explanation from https://github.com/rust-lang/rust/issues/120091#issuecomment-1899071681: > > You mention that in case of alignment mismatch -- when the new alignment is less than the old -- the implementation calls `mremap`. > > I was trying to note that this isn't really the case in practice, due to the semantics of Rust's allocator APIs. The only use of the allocator within the `in_place_collect` implementation itself is [a call to `Allocator::shrink()`](https://github.com/rust-lang/rust/blob/db7125f008cfd72e8951c9a863178956e2cbacc3/library/alloc/src/vec/in_place_collect.rs#L299-L303), which per its documentation [allows decreasing the required alignment](https://doc.rust-lang.org/1.75.0/core/alloc/trait.Allocator.html). However, in stable Rust, the only available `Allocator` is [`Global`](https://doc.rust-lang.org/1.75.0/alloc/alloc/struct.Global.html), which delegates to the registered `GlobalAlloc`. Since `GlobalAlloc::realloc()` [cannot change the required alignment](https://doc.rust-lang.org/1.75.0/core/alloc/trait.GlobalAlloc.html#method.realloc), the implementation of [`<Global as Allocator>::shrink()`](https://github.com/rust-lang/rust/blob/db7125f008cfd72e8951c9a863178956e2cbacc3/library/alloc/src/alloc.rs#L280-L321) must fall back to creating a brand-new allocation, `memcpy`ing the data into it, and freeing the old allocation, whenever the alignment doesn't remain exactly the same. > > Therefore, the underlying allocator, provided by libc or some other source, has no opportunity to internally `mremap()` the data when the alignment is changed, since it has no way of knowing that the allocation is the same.
2024-01-20doc: fix some doctests after rebaseTomás Vallotton-2/+2
2024-01-20refactor: make waker mandatory.Tomás Vallotton-6/+10
This also removes * impl From<&Context> for ContextBuilder * Context::try_waker() The from implementation is removed because now that wakers are always supported, there are less incentives to override the current context. Before, the incentive was to add Waker support to a reactor that didn't have any.
2024-01-20fix: Apply suggestions from code reviewtvallotton-3/+3
Co-authored-by: Mark Rousskov <mark.simulacrum@gmail.com>
2024-01-20chore: fix ci failuresTomás Vallotton-1/+1
2024-01-20chore: add tracking issue number to local waker featureTomás Vallotton-10/+12
2024-01-20fix: make LocalWake available in targets that don't support atomics by ↵Tomás Vallotton-8/+12
removing a #[cfg(target_has_atomic = ptr)]
2024-01-20feat: add try_waker and From<&mut Context> for ContextBuilder to allow the ↵Tomás Vallotton-9/+11
extention of contexts by futures
2024-01-20feat: add LocalWaker type, ContextBuilder type, and LocalWake trait.Tomás Vallotton-1/+165
2024-01-19fix: 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.
2024-01-19Rollup merge of #120110 - invpt:patch-1, r=the8472Matthias Krüger-7/+12
Update documentation for Vec::into_boxed_slice to be more clear about excess capacity Currently, the documentation for Vec::into_boxed_slice says that "if the vector has excess capacity, its items will be moved into a newly-allocated buffer with exactly the right capacity." This is misleading, as copies do not necessarily occur, depending on if the allocator supports in-place shrinking. I copied some of the wording from shrink_to_fit, though it could potentially still be worded better than this.
2024-01-18Clarify docs for Vec::into_boxed_slice, Vec::shrink_to_fitinvpt-7/+12
2024-01-18remove 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.
2024-01-18update internal ASCII art comment for vec specializationsThe 8472-7/+7
2024-01-18Remove no-longer-needed `allow(dead_code)` from the standard libraryJake Goulding-1/+0
`repr(transparent)` now silences the lint.
2024-01-18Add `A: 'static` bound for `Arc/Rc::pin_in`zetanumbers-3/+12
2024-01-16Fix typo in comments (in_place_collect)Robert Grosse-1/+1
2024-01-13libs: use `assert_unchecked` instead of intrinsicjoboet-10/+12
2024-01-13Remove special-case handling of `vec.split_off(0)`Zalathar-14/+18
2024-01-11Rollup merge of #119853 - klensy:rustfmt-ignore, r=cuviperMatthias Krüger-13/+4
rustfmt.toml: don't ignore just any tests path, only root one Previously ignored any `tests` path, now only /tests at repo root. For reference, https://git-scm.com/docs/gitignore#_pattern_format
2024-01-11apply fmtklensy-13/+4
2024-01-11chore: remove unnecessary blank linehi-rustin-1/+0
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2024-01-10Implement in-place iteratation markers for iter::{Copied, Cloned}The8472-2/+6
2024-01-10Fix deallocation with wrong allocator in (A)Rc::from_box_inzachs18-2/+2
2024-01-08rc,sync: Do not create references to uninitialized valuesTaiki Endo-20/+25
2024-01-07mark vec::IntoIter pointers as `!nonnull`The 8472-49/+75
2024-01-07typo fixThe 8472-1/+1
2024-01-06Rollup merge of #118781 - RalfJung:core-panic-feature, r=the8472Matthias Krüger-1/+1
merge core_panic feature into panic_internals I don't know why those are two separate features, but it does not seem intentional. This merge is useful because with https://github.com/rust-lang/rust/pull/118123, panic_internals is recognized as an internal feature, but core_panic is not -- but core_panic definitely should be internal.
2024-01-05Auto merge of #118297 - shepmaster:warn-dead-tuple-fields, r=WaffleLapkinbors-7/+8
Merge `unused_tuple_struct_fields` into `dead_code` This implicitly upgrades the lint from `allow` to `warn` and places it into the `unused` lint group. [Discussion on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Moving.20.60unused_tuple_struct_fields.60.20from.20allow.20to.20warn)
2024-01-03Rollup merge of #119434 - taiki-e:rc-is-dangling, r=Mark-SimulacrumLeón Orell Valerian Liehr-3/+3
rc: Take *const T in is_dangling It is not important which one is used since `is_dangling` does not access memory, but `*const` removes the needs of `*const T` -> `*mut T` casts in `from_raw_in`.
2024-01-02Adjust library tests for unused_tuple_struct_fields -> dead_codeJake Goulding-7/+8
2023-12-30Rollup merge of #119158 - JohnTheCoolingFan:arc-weak-clone-pretty, r=cuviperMatthias Krüger-14/+11
Clean up alloc::sync::Weak Clone implementation Since both return points (tail and early return) return the same expression and the only difference is whether inner is available, the code that does the atomic operations and checks on inner was moved into the if body and the only return is at the tail. Original comments preserved.
2023-12-30rc: Take *const T in is_danglingTaiki Endo-3/+3
It is not important which one is used since `is_dangling` does not access memory, but `*const` removes the needs of `*const T` -> `*mut T` casts in `from_raw_in`.
2023-12-29Italicise "bytes" in the docs of some `Vec` methodsGurinder Singh-8/+8
because on a cursory read it's easy to miss that the limit is in terms of bytes not no. of elements. The italics should help with that.
2023-12-24Rollup merge of #119205 - mumbleskates:vecdeque-comment-fix, r=Mark-SimulacrumMatthias Krüger-4/+4
fix minor mistake in comments describing VecDeque resizing Avoiding confusion where one of the items in the deque seems to disappear in two of the three cases
2023-12-22update version placeholdersPietro Albini-2/+2
2023-12-21fix minor mistake in comments describing VecDeque resizingKent Ross-4/+4
2023-12-20Cleaned up alloc::sync::Weak Clone implementationJohnTheCoolingFan-14/+11
Since both return points (tail and early return) return the same expression and the only difference is whether inner is available, the code that does the atomic operations and checks on inner was moved into the if body and the only return is at the tail. Original comments preserved.
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-11Auto merge of #117758 - Urgau:lint_pointer_trait_comparisons, r=davidtwcobors-1/+1
Add lint against ambiguous wide pointer comparisons This PR is the resolution of https://github.com/rust-lang/rust/issues/106447 decided in https://github.com/rust-lang/rust/issues/117717 by T-lang. ## `ambiguous_wide_pointer_comparisons` *warn-by-default* The `ambiguous_wide_pointer_comparisons` lint checks comparison of `*const/*mut ?Sized` as the operands. ### Example ```rust let ab = (A, B); let a = &ab.0 as *const dyn T; let b = &ab.1 as *const dyn T; let _ = a == b; ``` ### Explanation The comparison includes metadata which may not be expected. ------- This PR also drops `clippy::vtable_address_comparisons` which is superseded by this one. ~~One thing: is the current naming right? `invalid` seems a bit too much.~~ Fixes https://github.com/rust-lang/rust/issues/117717
2023-12-10Auto merge of #118692 - surechen:remove_unused_imports, r=petrochenkovbors-39/+4
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-39/+4
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.