Commit graph

2149 commits

Author SHA1 Message Date
Stein Somers
be051adb57 Create benchmarks for BTreeMap::range 2020-02-07 00:57:54 +01:00
Dylan DPC
5e561c2135
Rollup merge of #68711 - hman523:fix-68593, r=Dylan-DPC
Added upper bound of what vecs and boxes can allocate

Fixed issue #68593
I added a line of documentation to these two files to reflect that vectors and boxes ensure that they never allocate more than `isize::MAX` bytes.
r? @steveklabnik
2020-02-03 18:58:27 +01:00
hman523
346920c3c8 Fixed issue 68593 2020-01-31 13:41:07 -06:00
Stein Somers
3cf724d0c1 Bundle and document 6 BTreeMap navigation algorithms 2020-01-31 17:37:17 +01:00
Dylan DPC
6c67466f73
Rollup merge of #68680 - ollie27:doc_alloc_playground, r=Centril
Add `#![doc(html_playground_url = ...)]` to alloc crate

This adds the Run button to code examples just like the core and std docs have.
2020-01-31 01:21:31 +01:00
Oliver Middleton
bfcfab630e Add #![doc(html_playground_url = ...)] to alloc crate
This adds the Run button to code examples just like the core and std docs have.
2020-01-30 21:14:39 +00:00
Dylan DPC
f837c730ca
Rollup merge of #68468 - ssomers:btreemap_prefer_middle, r=Mark-Simulacrum
BTreeMap: tag and explain unsafe internal functions or assert preconditions

#68418 concluded that it's not desirable to tag all internal functions with preconditions as being unsafe. This PR does it to some functions, documents why, and elsewhere enforces the preconditions with asserts.
2020-01-30 01:46:42 +01:00
Dylan DPC
12c9562486
Rollup merge of #66648 - crgl:btree-clone-from, r=Amanieu
Implement clone_from for BTreeMap and BTreeSet

See #28481. This results in up to 90% speedups on simple data types when `self` and `other` are the same size, and is generally comparable or faster. Some concerns:

1. This implementation requires an `Ord` bound on the `Clone` implementation for `BTreeMap` and `BTreeSet`. Since these structs can only be created externally for keys with `Ord` implemented, this should be fine? If not, there's certainly a less safe way to do this.
2. Changing `next_unchecked` on `RangeMut` to return mutable key references allows for replacing the entire overlapping portion of both maps without changing the external interface in any way. However, if `clone_from` fails it can leave the `BTreeMap` in an invalid state, which might be unacceptable.

~This probably needs an FCP since it changes a trait bound, but (as far as I know?) that change cannot break any external code.~
2020-01-30 01:46:38 +01:00
Stein Somers
ba87a50332 BTreeMap: tag and explain unsafe internal functions or assert preconditions
Co-Authored-By: Mark Rousskov <mark.simulacrum@gmail.com>
2020-01-29 11:52:21 +01:00
Yuki Okushi
8d3273cdba
Rollup merge of #68592 - pdbrito:master, r=jonas-schievink
fix: typo in vec.rs
2020-01-29 09:34:51 +09:00
Yuki Okushi
af0c280be6
Rollup merge of #68378 - billyrieger:btreemap-remove-entry, r=KodrAus
Add BTreeMap::remove_entry

Implements https://github.com/rust-lang/rust/issues/66714.
2020-01-29 09:34:45 +09:00
Charles Gleason
6c3e477d13 Reformat truncation section of clone_from 2020-01-28 13:00:06 -05:00
Charles Gleason
81b6f8c3fc Add private is_empty method to RangeMut 2020-01-28 11:46:49 -05:00
Charles Gleason
60a7c9421e Include empty BTreeMap in clone_from tests 2020-01-28 11:39:48 -05:00
Charles Gleason
3caa17b468
Format safety comment as per tidy
Co-Authored-By: Ashley Mannix <ashleymannix@live.com.au>
2020-01-28 11:27:31 -05:00
bors
b181835a6b Auto merge of #68529 - TimDiekmann:rename-alloc, r=Amanieu
Rename `Alloc` to `AllocRef`

The allocator-wg has decided to merge this change upstream in https://github.com/rust-lang/wg-allocators/issues/8#issuecomment-577122958.

This renames `Alloc` to `AllocRef` because types that implement `Alloc` are a reference, smart pointer, or ZSTs. It is not possible to have an allocator like `MyAlloc([u8; N])`, that owns the memory and also implements `Alloc`, since that would mean, that moving a `Vec<T, MyAlloc>` would need to correct the internal pointer, which is not possible as we don't have move constructors.

For further explanation please see https://github.com/rust-lang/wg-allocators/issues/8#issuecomment-489464843 and the comments after that one.

Additionally it clarifies the semantics of `Clone` on an allocator. In the case of `AllocRef`, it is clear that the cloned handle still points to the same allocator instance, and that you can free data allocated from one handle with another handle.

The initial proposal was to rename `Alloc` to `AllocHandle`, but `Ref` expresses the semantics better than `Handle`. Also, the only appearance of `Handle` in `std` are for windows specific resources, which might be confusing.

Blocked on https://github.com/rust-lang/miri/pull/1160
2020-01-28 08:44:20 +00:00
Pedro de Brito
074cfcbf2d fix: typo in vec.rs 2020-01-28 07:59:07 +01:00
Billy Rieger
5654305a7b Add BTreeMap::remove_entry
Mainly for API parity with HashMap.

- Add BTreeMap::remove_entry
- Rewrite BTreeMap::remove to use remove_entry
- Use btreemap_remove_entry feature in doc comment
2020-01-28 00:43:18 -05:00
bors
82018665a5 Auto merge of #68234 - CAD97:slice-from-raw-parts, r=KodrAus
Stabilize ptr::slice_from_raw_parts[_mut]

Closes #36925, the tracking issue.
Initial impl: #60667

r? @rust-lang/libs

In addition to stabilizing, I've adjusted the example of `ptr::slice_from_raw_parts` to use `slice_from_raw_parts` instead of `slice_from_raw_parts_mut`, which was unnecessary for the example as written.
2020-01-28 05:31:34 +00:00
Tim Diekmann
7ca25db816
Rename Alloc to AllocRef 2020-01-27 21:39:51 +01:00
Mazdak Farrokhzad
d532a04a1c
Rollup merge of #67686 - ssomers:keys_start_slasher, r=Mark-Simulacrum
Simplify NodeHeader by avoiding slices in BTreeMaps with shared roots

Simplify a complicated piece of code that creates slices of keys in node leaves.
2020-01-21 19:42:17 +01:00
Stein Somers
3e947ef031 Declare unsafe functions that can no longer handle shared roots 2020-01-21 16:12:19 +01:00
Stein Somers
1b800a5671 trade in outdated comments for correct ones 2020-01-21 10:30:14 +01:00
bors
8c73fa70f3 Auto merge of #68154 - ssomers:btreemap_navigation_benches, r=Mark-Simulacrum
Add more BTreeMap/BTreeSet benchmarks regarding iteration

Serving #67073 or other developments
2020-01-21 03:07:01 +00:00
bors
6250d56355 Auto merge of #67758 - ssomers:testing_range, r=Mark-Simulacrum
More thorough testing of BTreeMap::range

Test more of the paths in the `range_search` function in map.rs
2020-01-19 04:40:21 +00:00
Stein Somers
4dbae1e8ba Allow added string.insert benchmarks to compile 2020-01-17 01:05:49 +01:00
bors
e02c475da5 Auto merge of #67339 - CAD97:rc-provenance, r=sfackler
Use pointer offset instead of deref for A/Rc::into_raw

Internals thread: https://internals.rust-lang.org/t/rc-and-internal-mutability/11463/2?u=cad97

The current implementation of (`A`)`Rc::into_raw` uses the `Deref::deref` implementation to get the pointer-to-data that is returned. This is problematic in the proposed Stacked Borrow rules, as this only gets shared provenance over the data location. (Note that the strong/weak counts are `UnsafeCell` (`Cell`/`Atomic`) so shared provenance can still mutate them, but the data itself is not.) When promoted back to a real reference counted pointer, the restored pointer can be used for mutation through `::get_mut` (if it is the only surviving reference). However, this mutates through a pointer ultimately derived from a `&T` borrow, violating the Stacked Borrow rules.

There are three known potential solutions to this issue:

- Stacked Borrows is wrong, liballoc is correct.
- Fully admit (`A`)`Rc` as an "internal mutability" type and store the data payload in an `UnsafeCell` like the strong/weak counts are. (Note: this is not needed generally since the `RcBox`/`ArcInner` is stored behind a shared `NonNull` which maintains shared write provenance as a raw pointer.)
- Adjust `into_raw` to do direct manipulation of the pointer (like `from_raw`) so that it maintains write provenance and doesn't derive the pointer from a reference.

This PR implements the third option, as recommended by @RalfJung.

Potential future work: provide `as_raw` and `clone_raw` associated functions to allow the [`&T` -> (`A`)`Rc<T>` pattern](https://internals.rust-lang.org/t/rc-and-internal-mutability/11463/2?u=cad97) to be used soundly without creating (`A`)`Rc` from references.
2020-01-16 00:47:45 +00:00
Dylan DPC
1b7b8cbed3
Rollup merge of #68123 - crlf0710:linked_list_cursor, r=Amanieu
Implement Cursor for linked lists. (RFC 2570).

cc. #58533 cc. @Gankra

r? @Amanieu
2020-01-15 22:49:24 +05:30
CAD97
f76177ce43 Stabilize ptr::slice_from_raw_parts[_mut] 2020-01-14 20:15:39 -05:00
Charles Lew
06b9a73cfa Update APIs according to RFC change suggestions. 2020-01-14 20:11:52 +08:00
Stein Somers
3ada8aeed4 Add more BTreeMap/BTreeSet benchmarks regarding iteration 2020-01-12 15:05:09 +01:00
Charles Lew
d2c509a3c6 Address review comments. 2020-01-12 18:34:35 +08:00
Charles Lew
091ba6daa0 Address review comments. 2020-01-12 13:15:00 +08:00
Charles Lew
d59e9b40a3 Implement Cursor for linked lists. (RFC 2570). 2020-01-12 01:51:04 +08:00
Lzu Tao
7ba25acd7a Revert "Rollup merge of #67727 - Dylan-DPC:stabilise/remove_item, r=alexcrichton"
This reverts commit 4ed415b547, reversing
changes made to 3cce950743.
2020-01-11 03:04:39 +00:00
Stein Somers
9e90840a6a Simplify NodeHeader by avoiding slices in BTreeMaps with shared roots 2020-01-10 17:19:50 +01:00
Stein Somers
9b92bf8315
Apply suggestions from code review
Co-Authored-By: Ralf Jung <post@ralfj.de>
2020-01-09 12:03:49 +01:00
Stein Somers
37b5cca3d5 Simplify into_key_slice_mut and document bits and bobs 2020-01-09 11:45:32 +01:00
bors
8597644255 Auto merge of #67312 - cuviper:clone-box-slice, r=SimonSapin
Simplify Clone for Box<[T]>

The bespoke `BoxBuilder` was basically a very simple `Vec`. Instead,
let's clone to a real `Vec`, with all of its specialization for the
task, then convert back to `Box<[T]>`.
2020-01-07 18:10:56 +00:00
Yuki Okushi
2c25ad5d28
Rollup merge of #67929 - mgrachev:patch-1, r=jonas-schievink
Formatting an example for method Vec.retain
2020-01-07 13:46:10 +09:00
dylan_DPC
503d06b90d oh the one that was left behind 2020-01-06 23:28:47 +05:30
dylan_DPC
6bec8e9972 stabilise it 2020-01-06 20:37:49 +05:30
dylan_DPC
24c6cd80c3 stabilise remove_item 2020-01-06 19:36:46 +05:30
Grachev Mikhail
e6d95ce0b8
Formatting an example for method Vec.retain 2020-01-06 15:18:03 +03:00
Dylan DPC
005d9d5b6e
Rollup merge of #67873 - Dylan-DPC:feature/change-remove-to-partial, r=Amanieu
change remove to have a PartialEq bound

Addresses [comment](https://github.com/rust-lang/rust/pull/67727#issuecomment-570660301).

References #40062

r? @Amanieu
2020-01-06 12:00:17 +05:30
dylan_DPC
e03d1c4204 add feature gate 2020-01-05 15:42:35 +05:30
dylan_DPC
358b8983f2 removed blank line 2020-01-05 00:00:40 +05:30
dylan_DPC
f744ea03b4 ef em ti ... :P 2020-01-04 23:57:34 +05:30
Dylan DPC
0bbe11089c
Rollup merge of #67812 - ssomers:btreemap_internal_doc, r=rkruppe
Tweak and extend internal BTreeMap documentation, including debug asserts.

Gathered from work on various other pull requests (e.g. #67725, #67686).
2020-01-04 23:52:51 +05:30
dylan_DPC
eb36688a01 add tests 2020-01-04 23:41:17 +05:30