Skip to content

Commit

Permalink
Auto merge of #70816 - Dylan-DPC:rollup-kzcs8px, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 5 pull requests

Successful merges:

 - #67797 (Query-ify Instance::resolve)
 - #70777 (Don't import integer and float modules, use assoc consts)
 - #70795 (Keep track of position when deleting from a BTreeMap)
 - #70812 (Do not use "nil" to refer to `()`)
 - #70815 (Enable layout debugging for `impl Trait` type aliases)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Apr 5, 2020
2 parents 6387b09 + 8c081f6 commit b543afc
Show file tree
Hide file tree
Showing 55 changed files with 164 additions and 158 deletions.
1 change: 0 additions & 1 deletion src/etc/test-float-parse/u64-pow2.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
mod _common;

use _common::validate;
use std::u64;

fn main() {
for exp in 19..64 {
Expand Down
1 change: 0 additions & 1 deletion src/liballoc/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use core::intrinsics::{self, min_align_of_val, size_of_val};
use core::ptr::{NonNull, Unique};
use core::usize;

#[stable(feature = "alloc_module", since = "1.28.0")]
#[doc(inline)]
Expand Down
1 change: 0 additions & 1 deletion src/liballoc/collections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
//! ```
//! use std::cmp::Ordering;
//! use std::collections::BinaryHeap;
//! use std::usize;
//!
//! #[derive(Copy, Clone, Eq, PartialEq)]
//! struct State {
Expand Down
108 changes: 59 additions & 49 deletions src/liballoc/collections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1780,18 +1780,12 @@ where
where
F: FnMut(&K, &mut V) -> bool,
{
while let Some(kv) = unsafe { self.next_kv() } {
let (k, v) = unsafe { ptr::read(&kv) }.into_kv_mut();
while let Some(mut kv) = unsafe { self.next_kv() } {
let (k, v) = kv.kv_mut();
if pred(k, v) {
*self.length -= 1;
let (k, v, leaf_edge_location) = kv.remove_kv_tracking();
// `remove_kv_tracking` has either preserved or invalidated `self.cur_leaf_edge`
if let Some(node) = leaf_edge_location {
match search::search_tree(node, &k) {
search::SearchResult::Found(_) => unreachable!(),
search::SearchResult::GoDown(leaf) => self.cur_leaf_edge = Some(leaf),
}
};
self.cur_leaf_edge = Some(leaf_edge_location);
return Some((k, v));
}
self.cur_leaf_edge = Some(kv.next_leaf_edge());
Expand Down Expand Up @@ -2698,108 +2692,124 @@ impl<'a, K: Ord, V> OccupiedEntry<'a, K, V> {

impl<'a, K: 'a, V: 'a> Handle<NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal>, marker::KV> {
/// Removes a key/value-pair from the map, and returns that pair, as well as
/// the whereabouts of the leaf edge corresponding to that former pair:
/// if None is returned, the leaf edge is still the left leaf edge of the KV handle;
/// if a node is returned, it heads the subtree where the leaf edge may be found.
/// the leaf edge corresponding to that former pair.
fn remove_kv_tracking(
self,
) -> (K, V, Option<NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal>>) {
let mut levels_down_handled: isize;
let (small_leaf, old_key, old_val) = match self.force() {
) -> (K, V, Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, marker::Edge>) {
let (mut pos, old_key, old_val, was_internal) = match self.force() {
Leaf(leaf) => {
levels_down_handled = 1; // handled at same level, but affects only the right side
let (hole, old_key, old_val) = leaf.remove();
(hole.into_node(), old_key, old_val)
(hole, old_key, old_val, false)
}
Internal(mut internal) => {
// Replace the location freed in the internal node with the next KV,
// and remove that next KV from its leaf.
levels_down_handled = unsafe { ptr::read(&internal).into_node().height() } as isize;

let key_loc = internal.kv_mut().0 as *mut K;
let val_loc = internal.kv_mut().1 as *mut V;

let to_remove = internal.right_edge().descend().first_leaf_edge().right_kv().ok();
// Deleting from the left side is typically faster since we can
// just pop an element from the end of the KV array without
// needing to shift the other values.
let to_remove = internal.left_edge().descend().last_leaf_edge().left_kv().ok();
let to_remove = unsafe { unwrap_unchecked(to_remove) };

let (hole, key, val) = to_remove.remove();

let old_key = unsafe { mem::replace(&mut *key_loc, key) };
let old_val = unsafe { mem::replace(&mut *val_loc, val) };

(hole.into_node(), old_key, old_val)
(hole, old_key, old_val, true)
}
};

// Handle underflow
let mut cur_node = small_leaf.forget_type();
let mut cur_node = unsafe { ptr::read(&pos).into_node().forget_type() };
let mut at_leaf = true;
while cur_node.len() < node::MIN_LEN {
match handle_underfull_node(cur_node) {
AtRoot(root) => {
cur_node = root;
break;
}
EmptyParent(_) => unreachable!(),
Merged(parent) => {
levels_down_handled -= 1;
AtRoot => break,
Merged(edge, merged_with_left, offset) => {
// If we merged with our right sibling then our tracked
// position has not changed. However if we merged with our
// left sibling then our tracked position is now dangling.
if at_leaf && merged_with_left {
let idx = pos.idx() + offset;
let node = match unsafe { ptr::read(&edge).descend().force() } {
Leaf(leaf) => leaf,
Internal(_) => unreachable!(),
};
pos = unsafe { Handle::new_edge(node, idx) };
}

let parent = edge.into_node();
if parent.len() == 0 {
// We must be at the root
let root = parent.into_root_mut();
root.pop_level();
cur_node = root.as_mut();
parent.into_root_mut().pop_level();
break;
} else {
cur_node = parent.forget_type();
at_leaf = false;
}
}
Stole(internal_node) => {
levels_down_handled -= 1;
cur_node = internal_node.forget_type();
Stole(stole_from_left) => {
// Adjust the tracked position if we stole from a left sibling
if stole_from_left && at_leaf {
// SAFETY: This is safe since we just added an element to our node.
unsafe {
pos.next_unchecked();
}
}

// This internal node might be underfull, but only if it's the root.
break;
}
}
}

let leaf_edge_location = if levels_down_handled > 0 { None } else { Some(cur_node) };
(old_key, old_val, leaf_edge_location)
// If we deleted from an internal node then we need to compensate for
// the earlier swap and adjust the tracked position to point to the
// next element.
if was_internal {
pos = unsafe { unwrap_unchecked(pos.next_kv().ok()).next_leaf_edge() };
}

(old_key, old_val, pos)
}
}

enum UnderflowResult<'a, K, V> {
AtRoot(NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal>),
EmptyParent(NodeRef<marker::Mut<'a>, K, V, marker::Internal>),
Merged(NodeRef<marker::Mut<'a>, K, V, marker::Internal>),
Stole(NodeRef<marker::Mut<'a>, K, V, marker::Internal>),
AtRoot,
Merged(Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker::Edge>, bool, usize),
Stole(bool),
}

fn handle_underfull_node<K, V>(
node: NodeRef<marker::Mut<'_>, K, V, marker::LeafOrInternal>,
) -> UnderflowResult<'_, K, V> {
let parent = match node.ascend() {
Ok(parent) => parent,
Err(root) => return AtRoot(root),
Err(_) => return AtRoot,
};

let (is_left, mut handle) = match parent.left_kv() {
Ok(left) => (true, left),
Err(parent) => match parent.right_kv() {
Ok(right) => (false, right),
Err(parent) => {
return EmptyParent(parent.into_node());
}
},
Err(parent) => {
let right = unsafe { unwrap_unchecked(parent.right_kv().ok()) };
(false, right)
}
};

if handle.can_merge() {
Merged(handle.merge().into_node())
let offset = if is_left { handle.reborrow().left_edge().descend().len() + 1 } else { 0 };
Merged(handle.merge(), is_left, offset)
} else {
if is_left {
handle.steal_left();
} else {
handle.steal_right();
}
Stole(handle.into_node())
Stole(is_left)
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/liballoc/collections/btree/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,11 @@ impl<Node, Type> Handle<Node, Type> {
pub fn into_node(self) -> Node {
self.node
}

/// Returns the position of this handle in the node.
pub fn idx(&self) -> usize {
self.idx
}
}

impl<BorrowType, K, V, NodeType> Handle<NodeRef<BorrowType, K, V, NodeType>, marker::KV> {
Expand Down
1 change: 0 additions & 1 deletion src/liballoc/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ use core::ops::{CoerceUnsized, Deref, DispatchFromDyn, Receiver};
use core::pin::Pin;
use core::ptr::{self, NonNull};
use core::slice::{self, from_raw_parts_mut};
use core::usize;

use crate::alloc::{box_free, handle_alloc_error, AllocInit, AllocRef, Global, Layout};
use crate::string::String;
Expand Down
1 change: 0 additions & 1 deletion src/liballoc/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ use core::borrow::{Borrow, BorrowMut};
use core::cmp::Ordering::{self, Less};
use core::mem::{self, size_of};
use core::ptr;
use core::{u16, u32, u8};

use crate::borrow::ToOwned;
use crate::boxed::Box;
Expand Down
1 change: 0 additions & 1 deletion src/liballoc/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use core::ptr::{self, NonNull};
use core::slice::{self, from_raw_parts_mut};
use core::sync::atomic;
use core::sync::atomic::Ordering::{Acquire, Relaxed, Release, SeqCst};
use core::{isize, usize};

use crate::alloc::{box_free, handle_alloc_error, AllocInit, AllocRef, Global, Layout};
use crate::boxed::Box;
Expand Down
2 changes: 0 additions & 2 deletions src/liballoc/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
use core::any::Any;
use core::clone::Clone;
use core::convert::TryInto;
use core::f64;
use core::i64;
use core::ops::Deref;
use core::result::Result::{Err, Ok};

Expand Down
1 change: 0 additions & 1 deletion src/liballoc/tests/string.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::borrow::Cow;
use std::collections::TryReserveError::*;
use std::mem::size_of;
use std::{isize, usize};

pub trait IntoCow<'a, B: ?Sized>
where
Expand Down
1 change: 0 additions & 1 deletion src/liballoc/tests/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::collections::TryReserveError::*;
use std::mem::size_of;
use std::panic::{catch_unwind, AssertUnwindSafe};
use std::vec::{Drain, IntoIter};
use std::{isize, usize};

struct DropCounter<'a> {
count: &'a mut u32,
Expand Down
1 change: 0 additions & 1 deletion src/liballoc/tests/vec_deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::collections::{vec_deque::Drain, VecDeque};
use std::fmt::Debug;
use std::mem::size_of;
use std::panic::{catch_unwind, AssertUnwindSafe};
use std::{isize, usize};

use crate::hash;

Expand Down
1 change: 0 additions & 1 deletion src/libcore/benches/num/flt2dec/strategy/dragon.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use super::super::*;
use core::num::flt2dec::strategy::dragon::*;
use std::{f64, i16};
use test::Bencher;

#[bench]
Expand Down
1 change: 0 additions & 1 deletion src/libcore/benches/num/flt2dec/strategy/grisu.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use super::super::*;
use core::num::flt2dec::strategy::grisu::*;
use std::{f64, i16};
use test::Bencher;

pub fn decode_finite<T: DecodableFloat>(v: T) -> Decoded {
Expand Down
4 changes: 0 additions & 4 deletions src/libcore/tests/fmt/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ fn test_format_int() {

#[test]
fn test_format_int_exp_limits() {
use core::{i128, i16, i32, i64, i8, u128, u16, u32, u64, u8};
assert_eq!(format!("{:e}", i8::MIN), "-1.28e2");
assert_eq!(format!("{:e}", i8::MAX), "1.27e2");
assert_eq!(format!("{:e}", i16::MIN), "-3.2768e4");
Expand All @@ -125,8 +124,6 @@ fn test_format_int_exp_limits() {

#[test]
fn test_format_int_exp_precision() {
use core::{i128, i16, i32, i64, i8};

//test that float and integer match
let big_int: u32 = 314_159_265;
assert_eq!(format!("{:.1e}", big_int), format!("{:.1e}", f64::from(big_int)));
Expand Down Expand Up @@ -214,7 +211,6 @@ fn test_format_int_sign_padding() {

#[test]
fn test_format_int_twos_complement() {
use core::{i16, i32, i64, i8};
assert_eq!(format!("{}", i8::MIN), "-128");
assert_eq!(format!("{}", i16::MIN), "-32768");
assert_eq!(format!("{}", i32::MIN), "-2147483648");
Expand Down
Loading

0 comments on commit b543afc

Please sign in to comment.