Skip to content

Commit

Permalink
Auto merge of rust-lang#66917 - Centril:rollup-xj2enik, r=Centril
Browse files Browse the repository at this point in the history
Rollup of 9 pull requests

Successful merges:

 - rust-lang#66503 (More useful test error messages on should_panic(expected=...) mismatch)
 - rust-lang#66662 (Miri: run panic-catching tests in liballoc)
 - rust-lang#66679 (Improve lifetime errors with implicit trait object lifetimes)
 - rust-lang#66726 (Use recursion_limit for const eval stack limit)
 - rust-lang#66790 (Do `min_const_fn` checks for `SetDiscriminant`s target)
 - rust-lang#66832 (const_prop: detect and avoid catching Miri errors that require allocation)
 - rust-lang#66880 (Add long error code explanation message for E0203)
 - rust-lang#66890 (Format liballoc with rustfmt)
 - rust-lang#66896 (pass Queries to compiler callbacks)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Dec 1, 2019
2 parents 135ccba + bed4c09 commit 4007d4e
Show file tree
Hide file tree
Showing 47 changed files with 657 additions and 631 deletions.
6 changes: 3 additions & 3 deletions src/liballoc/alloc/tests.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use super::*;

extern crate test;
use test::Bencher;
use crate::boxed::Box;
use test::Bencher;

#[test]
fn allocate_zeroed() {
unsafe {
let layout = Layout::from_size_align(1024, 1).unwrap();
let ptr = Global.alloc_zeroed(layout.clone())
.unwrap_or_else(|_| handle_alloc_error(layout));
let ptr =
Global.alloc_zeroed(layout.clone()).unwrap_or_else(|_| handle_alloc_error(layout));

let mut i = ptr.cast::<u8>().as_ptr();
let end = i.add(layout.size());
Expand Down
38 changes: 19 additions & 19 deletions src/liballoc/benches/btree/map.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::collections::BTreeMap;
use std::iter::Iterator;
use std::vec::Vec;
use std::collections::BTreeMap;

use rand::{Rng, seq::SliceRandom, thread_rng};
use test::{Bencher, black_box};
use rand::{seq::SliceRandom, thread_rng, Rng};
use test::{black_box, Bencher};

macro_rules! map_insert_rand_bench {
($name: ident, $n: expr, $map: ident) => (
($name: ident, $n: expr, $map: ident) => {
#[bench]
pub fn $name(b: &mut Bencher) {
let n: usize = $n;
Expand All @@ -27,11 +27,11 @@ macro_rules! map_insert_rand_bench {
});
black_box(map);
}
)
};
}

macro_rules! map_insert_seq_bench {
($name: ident, $n: expr, $map: ident) => (
($name: ident, $n: expr, $map: ident) => {
#[bench]
pub fn $name(b: &mut Bencher) {
let mut map = $map::new();
Expand All @@ -50,11 +50,11 @@ macro_rules! map_insert_seq_bench {
});
black_box(map);
}
)
};
}

macro_rules! map_find_rand_bench {
($name: ident, $n: expr, $map: ident) => (
($name: ident, $n: expr, $map: ident) => {
#[bench]
pub fn $name(b: &mut Bencher) {
let mut map = $map::new();
Expand All @@ -78,11 +78,11 @@ macro_rules! map_find_rand_bench {
black_box(t);
})
}
)
};
}

macro_rules! map_find_seq_bench {
($name: ident, $n: expr, $map: ident) => (
($name: ident, $n: expr, $map: ident) => {
#[bench]
pub fn $name(b: &mut Bencher) {
let mut map = $map::new();
Expand All @@ -101,20 +101,20 @@ macro_rules! map_find_seq_bench {
black_box(x);
})
}
)
};
}

map_insert_rand_bench!{insert_rand_100, 100, BTreeMap}
map_insert_rand_bench!{insert_rand_10_000, 10_000, BTreeMap}
map_insert_rand_bench! {insert_rand_100, 100, BTreeMap}
map_insert_rand_bench! {insert_rand_10_000, 10_000, BTreeMap}

map_insert_seq_bench!{insert_seq_100, 100, BTreeMap}
map_insert_seq_bench!{insert_seq_10_000, 10_000, BTreeMap}
map_insert_seq_bench! {insert_seq_100, 100, BTreeMap}
map_insert_seq_bench! {insert_seq_10_000, 10_000, BTreeMap}

map_find_rand_bench!{find_rand_100, 100, BTreeMap}
map_find_rand_bench!{find_rand_10_000, 10_000, BTreeMap}
map_find_rand_bench! {find_rand_100, 100, BTreeMap}
map_find_rand_bench! {find_rand_10_000, 10_000, BTreeMap}

map_find_seq_bench!{find_seq_100, 100, BTreeMap}
map_find_seq_bench!{find_seq_10_000, 10_000, BTreeMap}
map_find_seq_bench! {find_seq_100, 100, BTreeMap}
map_find_seq_bench! {find_seq_10_000, 10_000, BTreeMap}

fn bench_iter(b: &mut Bencher, size: i32) {
let mut map = BTreeMap::<i32, i32>::new();
Expand Down
63 changes: 32 additions & 31 deletions src/liballoc/benches/slice.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::{mem, ptr};

use rand::distributions::{Alphanumeric, Standard};
use rand::{thread_rng, Rng, SeedableRng};
use rand::distributions::{Standard, Alphanumeric};
use rand_xorshift::XorShiftRng;
use test::{Bencher, black_box};
use test::{black_box, Bencher};

#[bench]
fn iterator(b: &mut Bencher) {
Expand Down Expand Up @@ -239,7 +239,7 @@ macro_rules! sort {
b.iter(|| v.clone().$f());
b.bytes = $len * mem::size_of_val(&$gen(1)[0]) as u64;
}
}
};
}

macro_rules! sort_strings {
Expand All @@ -251,7 +251,7 @@ macro_rules! sort_strings {
b.iter(|| v.clone().$f());
b.bytes = $len * mem::size_of::<&str>() as u64;
}
}
};
}

macro_rules! sort_expensive {
Expand All @@ -273,7 +273,7 @@ macro_rules! sort_expensive {
});
b.bytes = $len * mem::size_of_val(&$gen(1)[0]) as u64;
}
}
};
}

macro_rules! sort_lexicographic {
Expand All @@ -284,7 +284,7 @@ macro_rules! sort_lexicographic {
b.iter(|| v.clone().$f(|x| x.to_string()));
b.bytes = $len * mem::size_of_val(&$gen(1)[0]) as u64;
}
}
};
}

sort!(sort, sort_small_ascending, gen_ascending, 10);
Expand Down Expand Up @@ -325,57 +325,58 @@ macro_rules! reverse {
fn $name(b: &mut Bencher) {
// odd length and offset by 1 to be as unaligned as possible
let n = 0xFFFFF;
let mut v: Vec<_> =
(0..1+(n / mem::size_of::<$ty>() as u64))
.map($f)
.collect();
let mut v: Vec<_> = (0..1 + (n / mem::size_of::<$ty>() as u64)).map($f).collect();
b.iter(|| black_box(&mut v[1..]).reverse());
b.bytes = n;
}
}
};
}

reverse!(reverse_u8, u8, |x| x as u8);
reverse!(reverse_u16, u16, |x| x as u16);
reverse!(reverse_u8x3, [u8;3], |x| [x as u8, (x>>8) as u8, (x>>16) as u8]);
reverse!(reverse_u8x3, [u8; 3], |x| [x as u8, (x >> 8) as u8, (x >> 16) as u8]);
reverse!(reverse_u32, u32, |x| x as u32);
reverse!(reverse_u64, u64, |x| x as u64);
reverse!(reverse_u128, u128, |x| x as u128);
#[repr(simd)] struct F64x4(f64, f64, f64, f64);
reverse!(reverse_simd_f64x4, F64x4, |x| { let x = x as f64; F64x4(x,x,x,x) });
#[repr(simd)]
struct F64x4(f64, f64, f64, f64);
reverse!(reverse_simd_f64x4, F64x4, |x| {
let x = x as f64;
F64x4(x, x, x, x)
});

macro_rules! rotate {
($name:ident, $gen:expr, $len:expr, $mid:expr) => {
#[bench]
fn $name(b: &mut Bencher) {
let size = mem::size_of_val(&$gen(1)[0]);
let mut v = $gen($len * 8 / size);
b.iter(|| black_box(&mut v).rotate_left(($mid*8+size-1)/size));
b.iter(|| black_box(&mut v).rotate_left(($mid * 8 + size - 1) / size));
b.bytes = (v.len() * size) as u64;
}
}
};
}

rotate!(rotate_tiny_by1, gen_random, 16, 1);
rotate!(rotate_tiny_half, gen_random, 16, 16/2);
rotate!(rotate_tiny_half_plus_one, gen_random, 16, 16/2+1);
rotate!(rotate_tiny_half, gen_random, 16, 16 / 2);
rotate!(rotate_tiny_half_plus_one, gen_random, 16, 16 / 2 + 1);

rotate!(rotate_medium_by1, gen_random, 9158, 1);
rotate!(rotate_medium_by727_u64, gen_random, 9158, 727);
rotate!(rotate_medium_by727_bytes, gen_random_bytes, 9158, 727);
rotate!(rotate_medium_by727_strings, gen_strings, 9158, 727);
rotate!(rotate_medium_half, gen_random, 9158, 9158/2);
rotate!(rotate_medium_half_plus_one, gen_random, 9158, 9158/2+1);
rotate!(rotate_medium_half, gen_random, 9158, 9158 / 2);
rotate!(rotate_medium_half_plus_one, gen_random, 9158, 9158 / 2 + 1);

// Intended to use more RAM than the machine has cache
rotate!(rotate_huge_by1, gen_random, 5*1024*1024, 1);
rotate!(rotate_huge_by9199_u64, gen_random, 5*1024*1024, 9199);
rotate!(rotate_huge_by9199_bytes, gen_random_bytes, 5*1024*1024, 9199);
rotate!(rotate_huge_by9199_strings, gen_strings, 5*1024*1024, 9199);
rotate!(rotate_huge_by9199_big, gen_big_random, 5*1024*1024, 9199);
rotate!(rotate_huge_by1234577_u64, gen_random, 5*1024*1024, 1234577);
rotate!(rotate_huge_by1234577_bytes, gen_random_bytes, 5*1024*1024, 1234577);
rotate!(rotate_huge_by1234577_strings, gen_strings, 5*1024*1024, 1234577);
rotate!(rotate_huge_by1234577_big, gen_big_random, 5*1024*1024, 1234577);
rotate!(rotate_huge_half, gen_random, 5*1024*1024, 5*1024*1024/2);
rotate!(rotate_huge_half_plus_one, gen_random, 5*1024*1024, 5*1024*1024/2+1);
rotate!(rotate_huge_by1, gen_random, 5 * 1024 * 1024, 1);
rotate!(rotate_huge_by9199_u64, gen_random, 5 * 1024 * 1024, 9199);
rotate!(rotate_huge_by9199_bytes, gen_random_bytes, 5 * 1024 * 1024, 9199);
rotate!(rotate_huge_by9199_strings, gen_strings, 5 * 1024 * 1024, 9199);
rotate!(rotate_huge_by9199_big, gen_big_random, 5 * 1024 * 1024, 9199);
rotate!(rotate_huge_by1234577_u64, gen_random, 5 * 1024 * 1024, 1234577);
rotate!(rotate_huge_by1234577_bytes, gen_random_bytes, 5 * 1024 * 1024, 1234577);
rotate!(rotate_huge_by1234577_strings, gen_strings, 5 * 1024 * 1024, 1234577);
rotate!(rotate_huge_by1234577_big, gen_big_random, 5 * 1024 * 1024, 1234577);
rotate!(rotate_huge_half, gen_random, 5 * 1024 * 1024, 5 * 1024 * 1024 / 2);
rotate!(rotate_huge_half_plus_one, gen_random, 5 * 1024 * 1024, 5 * 1024 * 1024 / 2 + 1);
35 changes: 19 additions & 16 deletions src/liballoc/benches/str.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use test::{Bencher, black_box};
use test::{black_box, Bencher};

#[bench]
fn char_iterator(b: &mut Bencher) {
Expand All @@ -12,7 +12,9 @@ fn char_iterator_for(b: &mut Bencher) {
let s = "ศไทย中华Việt Nam; Mary had a little lamb, Little lamb";

b.iter(|| {
for ch in s.chars() { black_box(ch); }
for ch in s.chars() {
black_box(ch);
}
});
}

Expand Down Expand Up @@ -40,7 +42,9 @@ fn char_iterator_rev_for(b: &mut Bencher) {
let s = "ศไทย中华Việt Nam; Mary had a little lamb, Little lamb";

b.iter(|| {
for ch in s.chars().rev() { black_box(ch); }
for ch in s.chars().rev() {
black_box(ch);
}
});
}

Expand Down Expand Up @@ -79,7 +83,9 @@ fn split_ascii(b: &mut Bencher) {
fn split_extern_fn(b: &mut Bencher) {
let s = "Mary had a little lamb, Little lamb, little-lamb.";
let len = s.split(' ').count();
fn pred(c: char) -> bool { c == ' ' }
fn pred(c: char) -> bool {
c == ' '
}

b.iter(|| assert_eq!(s.split(pred).count(), len));
}
Expand Down Expand Up @@ -185,16 +191,19 @@ fn bench_contains_equal(b: &mut Bencher) {
})
}


macro_rules! make_test_inner {
($s:ident, $code:expr, $name:ident, $str:expr, $iters:expr) => {
#[bench]
fn $name(bencher: &mut Bencher) {
let mut $s = $str;
black_box(&mut $s);
bencher.iter(|| for _ in 0..$iters { black_box($code); });
bencher.iter(|| {
for _ in 0..$iters {
black_box($code);
}
});
}
}
};
}

macro_rules! make_test {
Expand Down Expand Up @@ -261,15 +270,9 @@ make_test!(match_indices_a_str, s, s.match_indices("a").count());

make_test!(split_a_str, s, s.split("a").count());

make_test!(trim_ascii_char, s, {
s.trim_matches(|c: char| c.is_ascii())
});
make_test!(trim_start_ascii_char, s, {
s.trim_start_matches(|c: char| c.is_ascii())
});
make_test!(trim_end_ascii_char, s, {
s.trim_end_matches(|c: char| c.is_ascii())
});
make_test!(trim_ascii_char, s, { s.trim_matches(|c: char| c.is_ascii()) });
make_test!(trim_start_ascii_char, s, { s.trim_start_matches(|c: char| c.is_ascii()) });
make_test!(trim_end_ascii_char, s, { s.trim_end_matches(|c: char| c.is_ascii()) });

make_test!(find_underscore_char, s, s.find('_'));
make_test!(rfind_underscore_char, s, s.rfind('_'));
Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/benches/vec_deque.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::collections::VecDeque;
use test::{Bencher, black_box};
use test::{black_box, Bencher};

#[bench]
fn bench_new(b: &mut Bencher) {
Expand Down
5 changes: 1 addition & 4 deletions src/liballoc/benches/vec_deque_append.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,5 @@ fn main() {

assert!(BENCH_N % 2 == 0);
let median = (durations[(l / 2) - 1] + durations[l / 2]) / 2;
println!(
"\ncustom-bench vec_deque_append {:?} ns/iter\n",
median.as_nanos()
);
println!("\ncustom-bench vec_deque_append {:?} ns/iter\n", median.as_nanos());
}
2 changes: 1 addition & 1 deletion src/liballoc/collections/btree/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub mod map;
mod node;
mod search;
pub mod map;
pub mod set;

#[doc(hidden)]
Expand Down
Loading

0 comments on commit 4007d4e

Please sign in to comment.