about summary refs log tree commit diff
path: root/src/liballoc
AgeCommit message (Collapse)AuthorLines
2019-10-05Revert "Auto merge of #63649 - tlively:emscripten-upstream-upgrade, ↵Tyler Mandry-23/+9
r=alexcrichton" This reverts commit 7870050796e5904a0fc85ecbe6fa6dde1cfe0c91, reversing changes made to 2e7244807a7878f6eca3eb7d97ae9b413aa49014.
2019-10-04Fix ABI, run and fix more tests, re-enable CI for PRsThomas Lively-9/+23
2019-10-03Rollup merge of #64975 - crgl:clone-from-linked-list, r=blussMazdak Farrokhzad-0/+56
Implement Clone::clone_from for LinkedList See #28481. This represents a substantial speedup when the list sizes are comparable, and shouldn't ever be significantly worse. Technically split_off is doing an unnecessary search, but the code is hopefully cleaner as a result. I'm happy to rework anything that needs to be changed as well!
2019-10-02Add test for LinkedList clone_fromCharles Gleason-0/+43
2019-10-02Use zipped iterators in clone_from for LinkedListCharles Gleason-2/+2
2019-10-01Implement Clone::clone_from for LinkedListCharles Gleason-0/+13
2019-10-01Rollup merge of #64912 - lzutao:unneeded-main-doc, r=jonas-schievinkMazdak Farrokhzad-85/+54
Remove unneeded `fn main` blocks from docs ## [No whitespace diff](https://github.com/rust-lang/rust/pull/64912/files?w=1)
2019-10-01BTreeSet intersection, difference & is_subnet optimizationsStein Somers-93/+247
2019-10-01Remove unneeded `fn main` blocks from docsLzu Tao-85/+54
2019-09-30Rollup merge of #64893 - SimonSapin:vec-of-option-box, r=sfacklerTyler Mandry-0/+25
Zero-initialize `vec![None; n]` for `Option<&T>`, `Option<&mut T>` and `Option<Box<T>>`
2019-09-29Zero-initialize `vec![None; n]` for `Option<&T>`, `Option<&mut T>` and ↵Simon Sapin-0/+25
`Option<Box<T>>`
2019-09-29Fix `vec![x; n]` with null raw fat pointer zeroing the pointer metadataSimon Sapin-2/+50
https://github.com/rust-lang/rust/pull/49496 introduced specialization based on: ``` unsafe impl<T: ?Sized> IsZero for *mut T { fn is_zero(&self) -> bool { (*self).is_null() } } ``` … to call `RawVec::with_capacity_zeroed` for creating `Vec<*mut T>`, which is incorrect for fat pointers since `<*mut T>::is_null` only looks at the data component. That is, a fat pointer can be “null” without being made entirely of zero bits. This commit fixes it by removing the `?Sized` bound on this impl (and the corresponding `*const T` one). This regresses `vec![x; n]` with `x` a null raw slice of length zero, but that seems exceptionally uncommon. (Vtable pointers are never null, so raw trait objects would not take the fast path anyway. An alternative to keep the `?Sized` bound (or even generalize to `impl<U: Copy> IsZero for U`) would be to cast to `&[u8]` of length `size_of::<U>()`, but the optimizer seems not to be able to propagate alignment information and sticks with comparing one byte at a time: https://rust.godbolt.org/z/xQFkwL ---- Without the library change, the new test fails as follows: ``` ---- vec::vec_macro_repeating_null_raw_fat_pointer stdout ---- [src/liballoc/tests/vec.rs:1301] ptr_metadata(raw_dyn) = 0x00005596ef95f9a8 [src/liballoc/tests/vec.rs:1306] ptr_metadata(vec[0]) = 0x0000000000000000 thread 'vec::vec_macro_repeating_null_raw_fat_pointer' panicked at 'assertion failed: vec[0] == null_raw_dyn', src/liballoc/tests/vec.rs:1307:5 ```
2019-09-27Stabilize map_get_key_value featureLzu Tao-2/+1
2019-09-25Snap cfgs to new betaMark Rousskov-5/+1
2019-09-24fix several issues in String docsjordins-4/+4
- In some places &str was shown instead of String. - into_bytes is the reverse of from_utf8 Fixes #63797
2019-09-20Exempt extern "Rust" from improper_ctypesJosh Stone-1/+1
It should be fine for Rust ABIs to involve any Rust type.
2019-09-16Const-stabilize `String::new`.Mazdak Farrokhzad-1/+1
2019-09-16Const-stabilize `Vec::new`.Mazdak Farrokhzad-4/+29
2019-09-16Auto merge of #64383 - pcpthm:btreeset-size-hint, r=dtolnaybors-22/+33
Improve BTreeSet::Intersection::size_hint A comment on `IntersectionInner` mentions `small_iter` should be smaller than `other_iter` but this condition is broken while iterating because those two iterators can be consumed at a different rate. I added a test to demonstrate this situation. <del>I made `small_iter.len() < other_iter.len()` always true by swapping two iterators when that condition became false. This change affects the return value of `size_hint`. The previous result was also correct but this new version always returns smaller upper bound than the previous version.</del> I changed `size_hint` to taking minimum of both lengths of iterators and renamed fields to `a` and `b` to match `Union` iterator.
2019-09-16Improve BTreeSet::Intersection::size_hintpcpthm-22/+33
The commented invariant that an iterator is smaller than other iterator was violated after next is called and two iterators are consumed at different rates.
2019-09-14Rollup merge of #61797 - Thomasdezeeuw:stablise-weak_ptr_eq, r=RalfJungMazdak Farrokhzad-11/+8
Stabilise weak_ptr_eq Implemented in #55987. Closes #55981.
2019-09-14Rollup merge of #64375 - kornelski:vecdrop, r=rkruppeMazdak Farrokhzad-13/+17
Fast path for vec.clear/truncate For trivial types like `u8`, `vec.truncate()`/`vec.clear()` relies on the optimizer to remove the loop. This means more work in debug builds, and more work for the optimizer. Avoiding this busywork is exactly what `mem::needs_drop::<T>()` is for.
2019-09-14Rollup merge of #64203 - alexreg:rush-pr-2, r=centrilMazdak Farrokhzad-83/+81
A few cosmetic improvements to code & comments in liballoc and libcore Factored out from hacking on rustc for work on the REPL. r? @Centril
2019-09-14Update src/liballoc/raw_vec.rsAlexander Regueiro-1/+1
Co-Authored-By: Mazdak Farrokhzad <twingoow@gmail.com>
2019-09-11Guarantee vec.clear/truncate is O(1) for trivial typesKornel-13/+17
2019-09-07Improve hygiene of `alloc::format!`Vadim Petrochenkov-1/+7
2019-09-06A few cosmetic improvements to code & comments in liballoc and libcoreAlexander Regueiro-83/+81
2019-08-30Rollup merge of #63684 - GrayJack:const_list_new, r=CentrilMazdak Farrokhzad-1/+1
Constify LinkedList new function Change the `LinkedList::new()` function to become a const fn, allowing the use in constant context.
2019-08-30Add a "diagnostic item" schemeOliver Scherer-0/+1
This allows lints and other diagnostics to refer to items by a unique ID instead of relying on whacky path resolution schemes that may break when items are relocated.
2019-08-25Update {rc, sync}::Weak::ptr_eq doc about comparing Weak::newThomas de Zeeuw-5/+6
2019-08-25Stabilise weak_ptr_eqThomas de Zeeuw-6/+2
2019-08-22Fix formatting.Tomasz Różański-1/+1
2019-08-22Fix a typo.Tomasz Różański-1/+1
2019-08-19Rollup merge of #63252 - nrc:arc-doc, r=alexcrichtonMazdak Farrokhzad-4/+0
Remove recommendation about idiomatic syntax for Arc::clone I believe we should not make this recommendation. I don't want to argue that `Arc::clone` is less idiomatic than `arc.clone`, but that the choice is not clear cut and that we should not be making this kind of call in the docs. The `.clone()` form has advantages too: it is more succinct, it is more likely to be understood by beginners, and it is more uniform with other `clone` calls, indeed with most other method calls. Whichever approach is better, I think that this discussion belongs in a style guide or textbook, rather than the library docs. We don't talk much about idiomatic code in the docs, this place is pretty exceptional. The recommendation is also not followed in this repo. It is hard to figure out how many calls there are of the `.clone()` form, but there are 1550 uses of `Arc` and only 65 uses of `Arc::clone`. The recommendation has existed for over two years. The recommendation was added in https://github.com/rust-lang/rust/pull/42137, as a result of https://github.com/rust-lang/rfcs/pull/1954. However, note that that RFC was closed because it was not necessary to change the docs (the original RFC proposed a new function instead). So I don't think an RFC is necessary here (and I'm not trying to re-litigate the discussion on that RFC (which favoured `Arc::clone` as idiomatic) in any case). cc @nical (who added the docs in the first place; sorry :-) ) r? @alexcrichton (or someone else on @rust-lang/libs )
2019-08-18Auto merge of #63045 - Rosto75:master, r=jonas-schievinkbors-43/+43
Change the placement of two functions. Right now, the order is as follows: `pop_front()` `push_front()` `push_back()` `pop_back()` `swap_remove_back()` `swap_remove_front()` I believe it would be more natural, and easier to follow, if we place `pop_back()` right after the `pop_front()`, and `swap_remove_back()` after the `swap_remove_front()` like this: `pop_front()` `pop_back()` `push_front()` `push_back()` `swap_remove_front()` `swap_remove_back()` The rest of the documentation (at least in this module) adheres to the same logic, where the 'front' function always precedes its 'back' equivalent.
2019-08-18Constify LinkedList new functionGrayJack-1/+1
2019-08-17Rollup merge of #62451 - SimonSapin:new_uninit, r=RalfJungMazdak Farrokhzad-10/+497
Add APIs for uninitialized Box, Rc, and Arc. (Plus get_mut_unchecked) Assigning `MaybeUninit::<Foo>::uninit()` to a local variable is usually free, even when `size_of::<Foo>()` is large. However, passing it for example to `Arc::new` [causes at least one copy](https://youtu.be/F1AquroPfcI?t=4116) (from the stack to the newly allocated heap memory) even though there is no meaningful data. It is theoretically possible that a Sufficiently Advanced Compiler could optimize this copy away, but this is [reportedly unlikely to happen soon in LLVM](https://youtu.be/F1AquroPfcI?t=5431). This PR proposes two sets of features: * Constructors for containers (`Box`, `Rc`, `Arc`) of `MaybeUninit<T>` or `[MaybeUninit<T>]` that do not initialized the data, and unsafe conversions to the known-initialized types (without `MaybeUninit`). The constructors are guaranteed not to make unnecessary copies. * On `Rc` and `Arc`, an unsafe `get_mut_unchecked` method that provides `&mut T` access without checking the reference count. `Arc::get_mut` involves multiple atomic operations whose cost can be non-trivial. `Rc::get_mut` is less costly, but we add `Rc::get_mut_unchecked` anyway for symmetry with `Arc`. These can be useful independently, but they will presumably be typical when the new constructors of `Rc` and `Arc` are used. An alternative with a safe API would be to introduce `UniqueRc` and `UniqueArc` types that have the same memory layout as `Rc` and `Arc` (and so zero-cost conversion to them) but are guaranteed to have only one reference. But introducing entire new types feels “heavier” than new constructors on existing types, and initialization of `MaybeUninit<T>` typically requires unsafe code anyway. Summary of new APIs (all unstable in this PR): ```rust impl<T> Box<T> { pub fn new_uninit() -> Box<MaybeUninit<T>> {…} } impl<T> Box<MaybeUninit<T>> { pub unsafe fn assume_init(self) -> Box<T> {…} } impl<T> Box<[T]> { pub fn new_uninit_slice(len: usize) -> Box<[MaybeUninit<T>]> {…} } impl<T> Box<[MaybeUninit<T>]> { pub unsafe fn assume_init(self) -> Box<[T]> {…} } impl<T> Rc<T> { pub fn new_uninit() -> Rc<MaybeUninit<T>> {…} } impl<T> Rc<MaybeUninit<T>> { pub unsafe fn assume_init(self) -> Rc<T> {…} } impl<T> Rc<[T]> { pub fn new_uninit_slice(len: usize) -> Rc<[MaybeUninit<T>]> {…} } impl<T> Rc<[MaybeUninit<T>]> { pub unsafe fn assume_init(self) -> Rc<[T]> {…} } impl<T> Arc<T> { pub fn new_uninit() -> Arc<MaybeUninit<T>> {…} } impl<T> Arc<MaybeUninit<T>> { pub unsafe fn assume_init(self) -> Arc<T> {…} } impl<T> Arc<[T]> { pub fn new_uninit_slice(len: usize) -> Arc<[MaybeUninit<T>]> {…} } impl<T> Arc<[MaybeUninit<T>]> { pub unsafe fn assume_init(self) -> Arc<[T]> {…} } impl<T: ?Sized> Rc<T> { pub unsafe fn get_mut_unchecked(this: &mut Self) -> &mut T {…} } impl<T: ?Sized> Arc<T> { pub unsafe fn get_mut_unchecked(this: &mut Self) -> &mut T {…} } ```
2019-08-17Rename private helper method allocate_for_unsized to allocate_for_layoutSimon Sapin-10/+10
2019-08-17Doc nitsSimon Sapin-14/+14
Co-Authored-By: Ralf Jung <post@ralfj.de>
2019-08-16Rollup merge of #63613 - petrochenkov:stdhyg, r=alexcrichtonMazdak Farrokhzad-1/+1
Hygienize use of built-in macros in the standard library Same as https://github.com/rust-lang/rust/pull/61629, but for built-in macros. Closes https://github.com/rust-lang/rust/issues/48781 r? @alexcrichton
2019-08-16Add the Layout of the failed allocation to TryReserveError::AllocErrorSimon Sapin-40/+46
… and add a separately-unstable field to force non-exhaustive matching (`#[non_exhaustive]` is no implemented yet on enum variants) so that we have the option to later expose the allocator’s error value. CC https://github.com/rust-lang/wg-allocators/issues/23
2019-08-16Rename CollectionAllocError to TryReserveErrorSimon Sapin-36/+36
2019-08-16Relax the safety condition for get_mut_uncheckedSimon Sapin-4/+8
2019-08-16Reuse more internal Rc and Arc methodsSimon Sapin-70/+14
2019-08-16Add a comment on the usage of Layout::new::<RcBox<()>>()Simon Sapin-0/+4
2019-08-16Add tracking issue numbersSimon Sapin-14/+14
2019-08-16Use ManuallyDrop instead of mem::forgetSimon Sapin-12/+4
Per https://github.com/rust-lang/rust/pull/62451#discussion_r303197278
2019-08-16Use `alloc::Global` in `Box::new_uninit`Simon Sapin-4/+6
2019-08-16Fix intra-rustdoc linksSimon Sapin-2/+14
2019-08-16Move constructors of boxed/rc’ed slices to matching `impl` blocksSimon Sapin-100/+106