Auto merge of #39567 - frewsxcv:rollup, r=frewsxcv
Rollup of 12 pull requests - Successful merges: #39439, #39472, #39481, #39491, #39501, #39509, #39514, #39519, #39526, #39528, #39530, #39538 - Failed merges:
This commit is contained in:
commit
031c1168b9
2
configure
vendored
2
configure
vendored
@ -517,7 +517,7 @@ case $CFG_CPUTYPE in
|
||||
CFG_OSTYPE="${CFG_OSTYPE}eabihf"
|
||||
;;
|
||||
|
||||
aarch64)
|
||||
aarch64 | arm64)
|
||||
CFG_CPUTYPE=aarch64
|
||||
;;
|
||||
|
||||
|
1
mk/cfg/aarch64-unknown-freebsd.mk
Normal file
1
mk/cfg/aarch64-unknown-freebsd.mk
Normal file
@ -0,0 +1 @@
|
||||
# rustbuild-only target
|
@ -379,6 +379,8 @@ class RustBuild(object):
|
||||
ostype += 'eabihf'
|
||||
elif cputype == 'aarch64':
|
||||
cputype = 'aarch64'
|
||||
elif cputype == 'arm64':
|
||||
cputype = 'aarch64'
|
||||
elif cputype == 'mips':
|
||||
if sys.byteorder == 'big':
|
||||
cputype = 'mips'
|
||||
|
@ -41,6 +41,12 @@ fn main() {
|
||||
return;
|
||||
}
|
||||
|
||||
if target.contains("android") {
|
||||
println!("cargo:rustc-link-lib=gcc");
|
||||
} else if !target.contains("windows") && !target.contains("musl") {
|
||||
println!("cargo:rustc-link-lib=pthread");
|
||||
}
|
||||
|
||||
if let Some(jemalloc) = env::var_os("JEMALLOC_OVERRIDE") {
|
||||
let jemalloc = PathBuf::from(jemalloc);
|
||||
println!("cargo:rustc-link-search=native={}",
|
||||
@ -66,11 +72,6 @@ fn main() {
|
||||
println!("cargo:rustc-link-lib=static=jemalloc_pic");
|
||||
}
|
||||
println!("cargo:rustc-link-search=native={}/lib", build_dir.display());
|
||||
if target.contains("android") {
|
||||
println!("cargo:rustc-link-lib=gcc");
|
||||
} else if !target.contains("windows") && !target.contains("musl") {
|
||||
println!("cargo:rustc-link-lib=pthread");
|
||||
}
|
||||
let src_dir = env::current_dir().unwrap().join("../jemalloc");
|
||||
rerun_if_changed_anything_in_dir(&src_dir);
|
||||
let timestamp = build_dir.join("rustbuild.timestamp");
|
||||
|
@ -607,7 +607,9 @@ coff_add (struct backtrace_state *state, int descriptor,
|
||||
// against the upstream libbacktrace, that's what's going on.
|
||||
uint32_t str_size;
|
||||
off_t str_off;
|
||||
struct backtrace_view syms_view;
|
||||
// NOTE: upstream doesn't have `{0}`, this is a fix for Rust issue #39468.
|
||||
// If syms_view is not initialized, then `free(syms_view.base)` may segfault later.
|
||||
struct backtrace_view syms_view = {0};
|
||||
off_t syms_off;
|
||||
size_t syms_size;
|
||||
int syms_view_valid;
|
||||
|
@ -98,7 +98,7 @@
|
||||
#![cfg_attr(test, allow(unused_imports, dead_code))]
|
||||
|
||||
use alloc::boxed::Box;
|
||||
use core::cmp::Ordering::{self, Greater};
|
||||
use core::cmp::Ordering::{self, Less};
|
||||
use core::mem::size_of;
|
||||
use core::mem;
|
||||
use core::ptr;
|
||||
@ -1089,7 +1089,7 @@ impl<T> [T] {
|
||||
pub fn sort(&mut self)
|
||||
where T: Ord
|
||||
{
|
||||
self.sort_by(|a, b| a.cmp(b))
|
||||
merge_sort(self, |a, b| a.lt(b));
|
||||
}
|
||||
|
||||
/// Sorts the slice using `f` to extract a key to compare elements by.
|
||||
@ -1119,7 +1119,7 @@ impl<T> [T] {
|
||||
pub fn sort_by_key<B, F>(&mut self, mut f: F)
|
||||
where F: FnMut(&T) -> B, B: Ord
|
||||
{
|
||||
self.sort_by(|a, b| f(a).cmp(&f(b)))
|
||||
merge_sort(self, |a, b| f(a).lt(&f(b)));
|
||||
}
|
||||
|
||||
/// Sorts the slice using `compare` to compare elements.
|
||||
@ -1149,10 +1149,10 @@ impl<T> [T] {
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn sort_by<F>(&mut self, compare: F)
|
||||
pub fn sort_by<F>(&mut self, mut compare: F)
|
||||
where F: FnMut(&T, &T) -> Ordering
|
||||
{
|
||||
merge_sort(self, compare)
|
||||
merge_sort(self, |a, b| compare(a, b) == Less);
|
||||
}
|
||||
|
||||
/// Copies the elements from `src` into `self`.
|
||||
@ -1355,10 +1355,10 @@ impl<T: Clone> ToOwned for [T] {
|
||||
/// Inserts `v[0]` into pre-sorted sequence `v[1..]` so that whole `v[..]` becomes sorted.
|
||||
///
|
||||
/// This is the integral subroutine of insertion sort.
|
||||
fn insert_head<T, F>(v: &mut [T], compare: &mut F)
|
||||
where F: FnMut(&T, &T) -> Ordering
|
||||
fn insert_head<T, F>(v: &mut [T], is_less: &mut F)
|
||||
where F: FnMut(&T, &T) -> bool
|
||||
{
|
||||
if v.len() >= 2 && compare(&v[0], &v[1]) == Greater {
|
||||
if v.len() >= 2 && is_less(&v[1], &v[0]) {
|
||||
unsafe {
|
||||
// There are three ways to implement insertion here:
|
||||
//
|
||||
@ -1381,12 +1381,12 @@ fn insert_head<T, F>(v: &mut [T], compare: &mut F)
|
||||
|
||||
// Intermediate state of the insertion process is always tracked by `hole`, which
|
||||
// serves two purposes:
|
||||
// 1. Protects integrity of `v` from panics in `compare`.
|
||||
// 1. Protects integrity of `v` from panics in `is_less`.
|
||||
// 2. Fills the remaining hole in `v` in the end.
|
||||
//
|
||||
// Panic safety:
|
||||
//
|
||||
// If `compare` panics at any point during the process, `hole` will get dropped and
|
||||
// If `is_less` panics at any point during the process, `hole` will get dropped and
|
||||
// fill the hole in `v` with `tmp`, thus ensuring that `v` still holds every object it
|
||||
// initially held exactly once.
|
||||
let mut hole = InsertionHole {
|
||||
@ -1396,7 +1396,7 @@ fn insert_head<T, F>(v: &mut [T], compare: &mut F)
|
||||
ptr::copy_nonoverlapping(&v[1], &mut v[0], 1);
|
||||
|
||||
for i in 2..v.len() {
|
||||
if compare(&tmp.value, &v[i]) != Greater {
|
||||
if !is_less(&v[i], &tmp.value) {
|
||||
break;
|
||||
}
|
||||
ptr::copy_nonoverlapping(&v[i], &mut v[i - 1], 1);
|
||||
@ -1432,8 +1432,8 @@ fn insert_head<T, F>(v: &mut [T], compare: &mut F)
|
||||
///
|
||||
/// The two slices must be non-empty and `mid` must be in bounds. Buffer `buf` must be long enough
|
||||
/// to hold a copy of the shorter slice. Also, `T` must not be a zero-sized type.
|
||||
unsafe fn merge<T, F>(v: &mut [T], mid: usize, buf: *mut T, compare: &mut F)
|
||||
where F: FnMut(&T, &T) -> Ordering
|
||||
unsafe fn merge<T, F>(v: &mut [T], mid: usize, buf: *mut T, is_less: &mut F)
|
||||
where F: FnMut(&T, &T) -> bool
|
||||
{
|
||||
let len = v.len();
|
||||
let v = v.as_mut_ptr();
|
||||
@ -1449,12 +1449,12 @@ unsafe fn merge<T, F>(v: &mut [T], mid: usize, buf: *mut T, compare: &mut F)
|
||||
// hole in `v`.
|
||||
//
|
||||
// Intermediate state of the process is always tracked by `hole`, which serves two purposes:
|
||||
// 1. Protects integrity of `v` from panics in `compare`.
|
||||
// 1. Protects integrity of `v` from panics in `is_less`.
|
||||
// 2. Fills the remaining hole in `v` if the longer run gets consumed first.
|
||||
//
|
||||
// Panic safety:
|
||||
//
|
||||
// If `compare` panics at any point during the process, `hole` will get dropped and fill the
|
||||
// If `is_less` panics at any point during the process, `hole` will get dropped and fill the
|
||||
// hole in `v` with the unconsumed range in `buf`, thus ensuring that `v` still holds every
|
||||
// object it initially held exactly once.
|
||||
let mut hole;
|
||||
@ -1476,7 +1476,7 @@ unsafe fn merge<T, F>(v: &mut [T], mid: usize, buf: *mut T, compare: &mut F)
|
||||
while *left < hole.end && right < v_end {
|
||||
// Consume the lesser side.
|
||||
// If equal, prefer the left run to maintain stability.
|
||||
let to_copy = if compare(&**left, &*right) == Greater {
|
||||
let to_copy = if is_less(&*right, &**left) {
|
||||
get_and_increment(&mut right)
|
||||
} else {
|
||||
get_and_increment(left)
|
||||
@ -1500,7 +1500,7 @@ unsafe fn merge<T, F>(v: &mut [T], mid: usize, buf: *mut T, compare: &mut F)
|
||||
while v < *left && buf < *right {
|
||||
// Consume the greater side.
|
||||
// If equal, prefer the right run to maintain stability.
|
||||
let to_copy = if compare(&*left.offset(-1), &*right.offset(-1)) == Greater {
|
||||
let to_copy = if is_less(&*right.offset(-1), &*left.offset(-1)) {
|
||||
decrement_and_get(left)
|
||||
} else {
|
||||
decrement_and_get(right)
|
||||
@ -1550,8 +1550,8 @@ unsafe fn merge<T, F>(v: &mut [T], mid: usize, buf: *mut T, compare: &mut F)
|
||||
/// 2. for every `i` in `2..runs.len()`: `runs[i - 2].len > runs[i - 1].len + runs[i].len`
|
||||
///
|
||||
/// The invariants ensure that the total running time is `O(n log n)` worst-case.
|
||||
fn merge_sort<T, F>(v: &mut [T], mut compare: F)
|
||||
where F: FnMut(&T, &T) -> Ordering
|
||||
fn merge_sort<T, F>(v: &mut [T], mut is_less: F)
|
||||
where F: FnMut(&T, &T) -> bool
|
||||
{
|
||||
// Sorting has no meaningful behavior on zero-sized types.
|
||||
if size_of::<T>() == 0 {
|
||||
@ -1565,7 +1565,7 @@ fn merge_sort<T, F>(v: &mut [T], mut compare: F)
|
||||
//
|
||||
// Short runs are extended using insertion sort to span at least `min_run` elements, in order
|
||||
// to improve performance.
|
||||
let (max_insertion, min_run) = if size_of::<T>() <= 16 {
|
||||
let (max_insertion, min_run) = if size_of::<T>() <= 2 * mem::size_of::<usize>() {
|
||||
(64, 32)
|
||||
} else {
|
||||
(32, 16)
|
||||
@ -1577,7 +1577,7 @@ fn merge_sort<T, F>(v: &mut [T], mut compare: F)
|
||||
if len <= max_insertion {
|
||||
if len >= 2 {
|
||||
for i in (0..len-1).rev() {
|
||||
insert_head(&mut v[i..], &mut compare);
|
||||
insert_head(&mut v[i..], &mut is_less);
|
||||
}
|
||||
}
|
||||
return;
|
||||
@ -1585,7 +1585,7 @@ fn merge_sort<T, F>(v: &mut [T], mut compare: F)
|
||||
|
||||
// Allocate a buffer to use as scratch memory. We keep the length 0 so we can keep in it
|
||||
// shallow copies of the contents of `v` without risking the dtors running on copies if
|
||||
// `compare` panics. When merging two sorted runs, this buffer holds a copy of the shorter run,
|
||||
// `is_less` panics. When merging two sorted runs, this buffer holds a copy of the shorter run,
|
||||
// which will always have length at most `len / 2`.
|
||||
let mut buf = Vec::with_capacity(len / 2);
|
||||
|
||||
@ -1600,14 +1600,18 @@ fn merge_sort<T, F>(v: &mut [T], mut compare: F)
|
||||
let mut start = end - 1;
|
||||
if start > 0 {
|
||||
start -= 1;
|
||||
if compare(&v[start], &v[start + 1]) == Greater {
|
||||
while start > 0 && compare(&v[start - 1], &v[start]) == Greater {
|
||||
start -= 1;
|
||||
}
|
||||
v[start..end].reverse();
|
||||
} else {
|
||||
while start > 0 && compare(&v[start - 1], &v[start]) != Greater {
|
||||
start -= 1;
|
||||
unsafe {
|
||||
if is_less(v.get_unchecked(start + 1), v.get_unchecked(start)) {
|
||||
while start > 0 && is_less(v.get_unchecked(start),
|
||||
v.get_unchecked(start - 1)) {
|
||||
start -= 1;
|
||||
}
|
||||
v[start..end].reverse();
|
||||
} else {
|
||||
while start > 0 && !is_less(v.get_unchecked(start),
|
||||
v.get_unchecked(start - 1)) {
|
||||
start -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1616,7 +1620,7 @@ fn merge_sort<T, F>(v: &mut [T], mut compare: F)
|
||||
// merge sort on short sequences, so this significantly improves performance.
|
||||
while start > 0 && end - start < min_run {
|
||||
start -= 1;
|
||||
insert_head(&mut v[start..end], &mut compare);
|
||||
insert_head(&mut v[start..end], &mut is_less);
|
||||
}
|
||||
|
||||
// Push this run onto the stack.
|
||||
@ -1632,7 +1636,7 @@ fn merge_sort<T, F>(v: &mut [T], mut compare: F)
|
||||
let right = runs[r];
|
||||
unsafe {
|
||||
merge(&mut v[left.start .. right.start + right.len], left.len, buf.as_mut_ptr(),
|
||||
&mut compare);
|
||||
&mut is_less);
|
||||
}
|
||||
runs[r] = Run {
|
||||
start: left.start,
|
||||
|
@ -1429,18 +1429,15 @@ mod bench {
|
||||
fn sort_large_random_expensive(b: &mut Bencher) {
|
||||
let len = 10000;
|
||||
b.iter(|| {
|
||||
let mut v = gen_random(len);
|
||||
let mut count = 0;
|
||||
let cmp = move |a: &u64, b: &u64| {
|
||||
v.sort_by(|a: &u64, b: &u64| {
|
||||
count += 1;
|
||||
if count % 1_000_000_000 == 0 {
|
||||
panic!("should not happen");
|
||||
}
|
||||
(*a as f64).cos().partial_cmp(&(*b as f64).cos()).unwrap()
|
||||
};
|
||||
|
||||
let mut v = gen_random(len);
|
||||
v.sort_by(cmp);
|
||||
|
||||
});
|
||||
black_box(count);
|
||||
});
|
||||
b.bytes = len as u64 * mem::size_of::<u64>() as u64;
|
||||
|
@ -544,8 +544,7 @@ pub mod reimpls {
|
||||
const MD1 : u32 = MANTISSA_DIGITS + 1;
|
||||
const MD2 : u32 = MANTISSA_DIGITS + 2;
|
||||
|
||||
// SNAP: replace this with !0u128
|
||||
let negn :u128 = !0;
|
||||
let negn = !0u128;
|
||||
|
||||
if sd > MANTISSA_DIGITS {
|
||||
a = match sd {
|
||||
@ -579,8 +578,7 @@ pub mod reimpls {
|
||||
const MD1 : u32 = MANTISSA_DIGITS + 1;
|
||||
const MD2 : u32 = MANTISSA_DIGITS + 2;
|
||||
|
||||
// SNAP: replace this with !0u128
|
||||
let negn :u128 = !0;
|
||||
let negn = !0u128;
|
||||
|
||||
if sd > MANTISSA_DIGITS {
|
||||
a = match sd {
|
||||
@ -652,17 +650,17 @@ pub mod reimpls {
|
||||
}
|
||||
|
||||
#[export_name="__fixunssfti"]
|
||||
pub extern "unadjusted" fn f32_as_u128(a: f32) -> u128 {
|
||||
pub extern $unadj fn f32_as_u128(a: f32) -> u128 {
|
||||
float_as_unsigned!(a, f32, u128)
|
||||
}
|
||||
|
||||
#[export_name="__fixdfti"]
|
||||
pub extern "unadjusted" fn f64_as_i128(a: f64) -> i128 {
|
||||
pub extern $unadj fn f64_as_i128(a: f64) -> i128 {
|
||||
float_as_signed!(a, f64, i128)
|
||||
}
|
||||
|
||||
#[export_name="__fixsfti"]
|
||||
pub extern "unadjusted" fn f32_as_i128(a: f32) -> i128 {
|
||||
pub extern $unadj fn f32_as_i128(a: f32) -> i128 {
|
||||
float_as_signed!(a, f32, i128)
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,6 @@ bench = false
|
||||
name = "coretest"
|
||||
path = "../libcoretest/lib.rs"
|
||||
|
||||
# FIXME: need to extract benchmarks to a separate crate
|
||||
#[[bench]]
|
||||
#name = "coretest"
|
||||
#path = "../libcoretest/lib.rs"
|
||||
[[bench]]
|
||||
name = "corebench"
|
||||
path = "../libcore/bench/lib.rs"
|
||||
|
22
src/libcore/bench/any.rs
Normal file
22
src/libcore/bench/any.rs
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use core::any::*;
|
||||
use test::{Bencher, black_box};
|
||||
|
||||
#[bench]
|
||||
fn bench_downcast_ref(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let mut x = 0;
|
||||
let mut y = &mut x as &mut Any;
|
||||
black_box(&mut y);
|
||||
black_box(y.downcast_ref::<isize>() == Some(&0));
|
||||
});
|
||||
}
|
11
src/libcore/bench/hash/mod.rs
Normal file
11
src/libcore/bench/hash/mod.rs
Normal file
@ -0,0 +1,11 @@
|
||||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
mod sip;
|
151
src/libcore/bench/hash/sip.rs
Normal file
151
src/libcore/bench/hash/sip.rs
Normal file
@ -0,0 +1,151 @@
|
||||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![allow(deprecated)]
|
||||
|
||||
use core::hash::*;
|
||||
use test::{Bencher, black_box};
|
||||
|
||||
fn hash_bytes<H: Hasher>(mut s: H, x: &[u8]) -> u64 {
|
||||
Hasher::write(&mut s, x);
|
||||
s.finish()
|
||||
}
|
||||
|
||||
fn hash_with<H: Hasher, T: Hash>(mut st: H, x: &T) -> u64 {
|
||||
x.hash(&mut st);
|
||||
st.finish()
|
||||
}
|
||||
|
||||
fn hash<T: Hash>(x: &T) -> u64 {
|
||||
hash_with(SipHasher::new(), x)
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_str_under_8_bytes(b: &mut Bencher) {
|
||||
let s = "foo";
|
||||
b.iter(|| {
|
||||
assert_eq!(hash(&s), 16262950014981195938);
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_str_of_8_bytes(b: &mut Bencher) {
|
||||
let s = "foobar78";
|
||||
b.iter(|| {
|
||||
assert_eq!(hash(&s), 4898293253460910787);
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_str_over_8_bytes(b: &mut Bencher) {
|
||||
let s = "foobarbaz0";
|
||||
b.iter(|| {
|
||||
assert_eq!(hash(&s), 10581415515220175264);
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_long_str(b: &mut Bencher) {
|
||||
let s = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor \
|
||||
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud \
|
||||
exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute \
|
||||
irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla \
|
||||
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui \
|
||||
officia deserunt mollit anim id est laborum.";
|
||||
b.iter(|| {
|
||||
assert_eq!(hash(&s), 17717065544121360093);
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_u32(b: &mut Bencher) {
|
||||
let u = 162629500u32;
|
||||
let u = black_box(u);
|
||||
b.iter(|| {
|
||||
hash(&u)
|
||||
});
|
||||
b.bytes = 8;
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_u32_keyed(b: &mut Bencher) {
|
||||
let u = 162629500u32;
|
||||
let u = black_box(u);
|
||||
let k1 = black_box(0x1);
|
||||
let k2 = black_box(0x2);
|
||||
b.iter(|| {
|
||||
hash_with(SipHasher::new_with_keys(k1, k2), &u)
|
||||
});
|
||||
b.bytes = 8;
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_u64(b: &mut Bencher) {
|
||||
let u = 16262950014981195938u64;
|
||||
let u = black_box(u);
|
||||
b.iter(|| {
|
||||
hash(&u)
|
||||
});
|
||||
b.bytes = 8;
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_bytes_4(b: &mut Bencher) {
|
||||
let data = black_box([b' '; 4]);
|
||||
b.iter(|| {
|
||||
hash_bytes(SipHasher::default(), &data)
|
||||
});
|
||||
b.bytes = 4;
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_bytes_7(b: &mut Bencher) {
|
||||
let data = black_box([b' '; 7]);
|
||||
b.iter(|| {
|
||||
hash_bytes(SipHasher::default(), &data)
|
||||
});
|
||||
b.bytes = 7;
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_bytes_8(b: &mut Bencher) {
|
||||
let data = black_box([b' '; 8]);
|
||||
b.iter(|| {
|
||||
hash_bytes(SipHasher::default(), &data)
|
||||
});
|
||||
b.bytes = 8;
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_bytes_a_16(b: &mut Bencher) {
|
||||
let data = black_box([b' '; 16]);
|
||||
b.iter(|| {
|
||||
hash_bytes(SipHasher::default(), &data)
|
||||
});
|
||||
b.bytes = 16;
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_bytes_b_32(b: &mut Bencher) {
|
||||
let data = black_box([b' '; 32]);
|
||||
b.iter(|| {
|
||||
hash_bytes(SipHasher::default(), &data)
|
||||
});
|
||||
b.bytes = 32;
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_bytes_c_128(b: &mut Bencher) {
|
||||
let data = black_box([b' '; 128]);
|
||||
b.iter(|| {
|
||||
hash_bytes(SipHasher::default(), &data)
|
||||
});
|
||||
b.bytes = 128;
|
||||
}
|
101
src/libcore/bench/iter.rs
Normal file
101
src/libcore/bench/iter.rs
Normal file
@ -0,0 +1,101 @@
|
||||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use core::iter::*;
|
||||
use test::{Bencher, black_box};
|
||||
|
||||
#[bench]
|
||||
fn bench_rposition(b: &mut Bencher) {
|
||||
let it: Vec<usize> = (0..300).collect();
|
||||
b.iter(|| {
|
||||
it.iter().rposition(|&x| x <= 150);
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_skip_while(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let it = 0..100;
|
||||
let mut sum = 0;
|
||||
it.skip_while(|&x| { sum += x; sum < 4000 }).all(|_| true);
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_multiple_take(b: &mut Bencher) {
|
||||
let mut it = (0..42).cycle();
|
||||
b.iter(|| {
|
||||
let n = it.next().unwrap();
|
||||
for _ in 0..n {
|
||||
it.clone().take(it.next().unwrap()).all(|_| true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn scatter(x: i32) -> i32 { (x * 31) % 127 }
|
||||
|
||||
#[bench]
|
||||
fn bench_max_by_key(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let it = 0..100;
|
||||
it.max_by_key(|&x| scatter(x))
|
||||
})
|
||||
}
|
||||
|
||||
// http://www.reddit.com/r/rust/comments/31syce/using_iterators_to_find_the_index_of_the_min_or/
|
||||
#[bench]
|
||||
fn bench_max_by_key2(b: &mut Bencher) {
|
||||
fn max_index_iter(array: &[i32]) -> usize {
|
||||
array.iter().enumerate().max_by_key(|&(_, item)| item).unwrap().0
|
||||
}
|
||||
|
||||
let mut data = vec![0; 1638];
|
||||
data[514] = 9999;
|
||||
|
||||
b.iter(|| max_index_iter(&data));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_max(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let it = 0..100;
|
||||
it.map(scatter).max()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn copy_zip(xs: &[u8], ys: &mut [u8]) {
|
||||
for (a, b) in ys.iter_mut().zip(xs) {
|
||||
*a = *b;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_zip(xs: &[f32], ys: &mut [f32]) {
|
||||
for (a, b) in ys.iter_mut().zip(xs) {
|
||||
*a += *b;
|
||||
}
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_zip_copy(b: &mut Bencher) {
|
||||
let source = vec![0u8; 16 * 1024];
|
||||
let mut dst = black_box(vec![0u8; 16 * 1024]);
|
||||
b.iter(|| {
|
||||
copy_zip(&source, &mut dst)
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_zip_add(b: &mut Bencher) {
|
||||
let source = vec![1.; 16 * 1024];
|
||||
let mut dst = vec![0.; 16 * 1024];
|
||||
b.iter(|| {
|
||||
add_zip(&source, &mut dst)
|
||||
});
|
||||
}
|
25
src/libcore/bench/lib.rs
Normal file
25
src/libcore/bench/lib.rs
Normal file
@ -0,0 +1,25 @@
|
||||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![deny(warnings)]
|
||||
|
||||
#![feature(flt2dec)]
|
||||
#![feature(slice_patterns)]
|
||||
#![feature(test)]
|
||||
|
||||
extern crate core;
|
||||
extern crate test;
|
||||
|
||||
mod any;
|
||||
mod hash;
|
||||
mod iter;
|
||||
mod mem;
|
||||
mod num;
|
||||
mod ops;
|
70
src/libcore/bench/mem.rs
Normal file
70
src/libcore/bench/mem.rs
Normal file
@ -0,0 +1,70 @@
|
||||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use test::Bencher;
|
||||
|
||||
// FIXME #13642 (these benchmarks should be in another place)
|
||||
// Completely miscellaneous language-construct benchmarks.
|
||||
// Static/dynamic method dispatch
|
||||
|
||||
struct Struct {
|
||||
field: isize
|
||||
}
|
||||
|
||||
trait Trait {
|
||||
fn method(&self) -> isize;
|
||||
}
|
||||
|
||||
impl Trait for Struct {
|
||||
fn method(&self) -> isize {
|
||||
self.field
|
||||
}
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn trait_vtable_method_call(b: &mut Bencher) {
|
||||
let s = Struct { field: 10 };
|
||||
let t = &s as &Trait;
|
||||
b.iter(|| {
|
||||
t.method()
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn trait_static_method_call(b: &mut Bencher) {
|
||||
let s = Struct { field: 10 };
|
||||
b.iter(|| {
|
||||
s.method()
|
||||
});
|
||||
}
|
||||
|
||||
// Overhead of various match forms
|
||||
|
||||
#[bench]
|
||||
fn match_option_some(b: &mut Bencher) {
|
||||
let x = Some(10);
|
||||
b.iter(|| {
|
||||
match x {
|
||||
Some(y) => y,
|
||||
None => 11
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn match_vec_pattern(b: &mut Bencher) {
|
||||
let x = [1,2,3,4,5,6];
|
||||
b.iter(|| {
|
||||
match x {
|
||||
[1,2,3,..] => 10,
|
||||
_ => 11,
|
||||
}
|
||||
});
|
||||
}
|
68
src/libcore/bench/num/dec2flt/mod.rs
Normal file
68
src/libcore/bench/num/dec2flt/mod.rs
Normal file
@ -0,0 +1,68 @@
|
||||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::f64;
|
||||
use test::Bencher;
|
||||
|
||||
#[bench]
|
||||
fn bench_0(b: &mut Bencher) {
|
||||
b.iter(|| "0.0".parse::<f64>());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_42(b: &mut Bencher) {
|
||||
b.iter(|| "42".parse::<f64>());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_huge_int(b: &mut Bencher) {
|
||||
// 2^128 - 1
|
||||
b.iter(|| "170141183460469231731687303715884105727".parse::<f64>());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_short_decimal(b: &mut Bencher) {
|
||||
b.iter(|| "1234.5678".parse::<f64>());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_pi_long(b: &mut Bencher) {
|
||||
b.iter(|| "3.14159265358979323846264338327950288".parse::<f64>());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_pi_short(b: &mut Bencher) {
|
||||
b.iter(|| "3.141592653589793".parse::<f64>())
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_1e150(b: &mut Bencher) {
|
||||
b.iter(|| "1e150".parse::<f64>());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_long_decimal_and_exp(b: &mut Bencher) {
|
||||
b.iter(|| "727501488517303786137132964064381141071e-123".parse::<f64>());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_min_subnormal(b: &mut Bencher) {
|
||||
b.iter(|| "5e-324".parse::<f64>());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_min_normal(b: &mut Bencher) {
|
||||
b.iter(|| "2.2250738585072014e-308".parse::<f64>());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_max(b: &mut Bencher) {
|
||||
b.iter(|| "1.7976931348623157e308".parse::<f64>());
|
||||
}
|
24
src/libcore/bench/num/flt2dec/mod.rs
Normal file
24
src/libcore/bench/num/flt2dec/mod.rs
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
mod strategy {
|
||||
mod dragon;
|
||||
mod grisu;
|
||||
}
|
||||
|
||||
use core::num::flt2dec::{decode, DecodableFloat, FullDecoded, Decoded};
|
||||
use core::num::flt2dec::MAX_SIG_DIGITS;
|
||||
|
||||
pub fn decode_finite<T: DecodableFloat>(v: T) -> Decoded {
|
||||
match decode(v).1 {
|
||||
FullDecoded::Finite(decoded) => decoded,
|
||||
full_decoded => panic!("expected finite, got {:?} instead", full_decoded)
|
||||
}
|
||||
}
|
70
src/libcore/bench/num/flt2dec/strategy/dragon.rs
Normal file
70
src/libcore/bench/num/flt2dec/strategy/dragon.rs
Normal file
@ -0,0 +1,70 @@
|
||||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::{i16, f64};
|
||||
use super::super::*;
|
||||
use core::num::flt2dec::strategy::dragon::*;
|
||||
use test::Bencher;
|
||||
|
||||
#[bench]
|
||||
fn bench_small_shortest(b: &mut Bencher) {
|
||||
let decoded = decode_finite(3.141592f64);
|
||||
let mut buf = [0; MAX_SIG_DIGITS];
|
||||
b.iter(|| format_shortest(&decoded, &mut buf));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_big_shortest(b: &mut Bencher) {
|
||||
let decoded = decode_finite(f64::MAX);
|
||||
let mut buf = [0; MAX_SIG_DIGITS];
|
||||
b.iter(|| format_shortest(&decoded, &mut buf));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_small_exact_3(b: &mut Bencher) {
|
||||
let decoded = decode_finite(3.141592f64);
|
||||
let mut buf = [0; 3];
|
||||
b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_big_exact_3(b: &mut Bencher) {
|
||||
let decoded = decode_finite(f64::MAX);
|
||||
let mut buf = [0; 3];
|
||||
b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_small_exact_12(b: &mut Bencher) {
|
||||
let decoded = decode_finite(3.141592f64);
|
||||
let mut buf = [0; 12];
|
||||
b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_big_exact_12(b: &mut Bencher) {
|
||||
let decoded = decode_finite(f64::MAX);
|
||||
let mut buf = [0; 12];
|
||||
b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_small_exact_inf(b: &mut Bencher) {
|
||||
let decoded = decode_finite(3.141592f64);
|
||||
let mut buf = [0; 1024];
|
||||
b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_big_exact_inf(b: &mut Bencher) {
|
||||
let decoded = decode_finite(f64::MAX);
|
||||
let mut buf = [0; 1024];
|
||||
b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
|
||||
}
|
77
src/libcore/bench/num/flt2dec/strategy/grisu.rs
Normal file
77
src/libcore/bench/num/flt2dec/strategy/grisu.rs
Normal file
@ -0,0 +1,77 @@
|
||||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::{i16, f64};
|
||||
use super::super::*;
|
||||
use core::num::flt2dec::strategy::grisu::*;
|
||||
use test::Bencher;
|
||||
|
||||
pub fn decode_finite<T: DecodableFloat>(v: T) -> Decoded {
|
||||
match decode(v).1 {
|
||||
FullDecoded::Finite(decoded) => decoded,
|
||||
full_decoded => panic!("expected finite, got {:?} instead", full_decoded)
|
||||
}
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_small_shortest(b: &mut Bencher) {
|
||||
let decoded = decode_finite(3.141592f64);
|
||||
let mut buf = [0; MAX_SIG_DIGITS];
|
||||
b.iter(|| format_shortest(&decoded, &mut buf));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_big_shortest(b: &mut Bencher) {
|
||||
let decoded = decode_finite(f64::MAX);
|
||||
let mut buf = [0; MAX_SIG_DIGITS];
|
||||
b.iter(|| format_shortest(&decoded, &mut buf));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_small_exact_3(b: &mut Bencher) {
|
||||
let decoded = decode_finite(3.141592f64);
|
||||
let mut buf = [0; 3];
|
||||
b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_big_exact_3(b: &mut Bencher) {
|
||||
let decoded = decode_finite(f64::MAX);
|
||||
let mut buf = [0; 3];
|
||||
b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_small_exact_12(b: &mut Bencher) {
|
||||
let decoded = decode_finite(3.141592f64);
|
||||
let mut buf = [0; 12];
|
||||
b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_big_exact_12(b: &mut Bencher) {
|
||||
let decoded = decode_finite(f64::MAX);
|
||||
let mut buf = [0; 12];
|
||||
b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_small_exact_inf(b: &mut Bencher) {
|
||||
let decoded = decode_finite(3.141592f64);
|
||||
let mut buf = [0; 1024];
|
||||
b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_big_exact_inf(b: &mut Bencher) {
|
||||
let decoded = decode_finite(f64::MAX);
|
||||
let mut buf = [0; 1024];
|
||||
b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
|
||||
}
|
12
src/libcore/bench/num/mod.rs
Normal file
12
src/libcore/bench/num/mod.rs
Normal file
@ -0,0 +1,12 @@
|
||||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
mod flt2dec;
|
||||
mod dec2flt;
|
30
src/libcore/bench/ops.rs
Normal file
30
src/libcore/bench/ops.rs
Normal file
@ -0,0 +1,30 @@
|
||||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use core::ops::*;
|
||||
use test::Bencher;
|
||||
|
||||
// Overhead of dtors
|
||||
|
||||
struct HasDtor {
|
||||
_x: isize
|
||||
}
|
||||
|
||||
impl Drop for HasDtor {
|
||||
fn drop(&mut self) {
|
||||
}
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn alloc_obj_with_dtor(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
HasDtor { _x : 10 };
|
||||
})
|
||||
}
|
@ -7,9 +7,8 @@
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use core::any::*;
|
||||
use test::Bencher;
|
||||
use test;
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
struct Test;
|
||||
@ -124,13 +123,3 @@ fn any_unsized() {
|
||||
fn is_any<T: Any + ?Sized>() {}
|
||||
is_any::<[i32]>();
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_downcast_ref(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let mut x = 0;
|
||||
let mut y = &mut x as &mut Any;
|
||||
test::black_box(&mut y);
|
||||
test::black_box(y.downcast_ref::<isize>() == Some(&0));
|
||||
});
|
||||
}
|
||||
|
@ -10,8 +10,6 @@
|
||||
|
||||
#![allow(deprecated)]
|
||||
|
||||
use test::{Bencher, black_box};
|
||||
|
||||
use core::hash::{Hash, Hasher};
|
||||
use core::hash::{SipHasher, SipHasher13, SipHasher24};
|
||||
use core::{slice, mem};
|
||||
@ -58,11 +56,6 @@ fn hash<T: Hash>(x: &T) -> u64 {
|
||||
hash_with(SipHasher::new(), x)
|
||||
}
|
||||
|
||||
fn hash_bytes<H: Hasher>(mut s: H, x: &[u8]) -> u64 {
|
||||
Hasher::write(&mut s, x);
|
||||
s.finish()
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[allow(unused_must_use)]
|
||||
fn test_siphash_1_3() {
|
||||
@ -347,126 +340,3 @@ fn test_write_short_works() {
|
||||
h2.write(&[0xFFu8, 0x01u8]);
|
||||
assert_eq!(h1.finish(), h2.finish());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_str_under_8_bytes(b: &mut Bencher) {
|
||||
let s = "foo";
|
||||
b.iter(|| {
|
||||
assert_eq!(hash(&s), 16262950014981195938);
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_str_of_8_bytes(b: &mut Bencher) {
|
||||
let s = "foobar78";
|
||||
b.iter(|| {
|
||||
assert_eq!(hash(&s), 4898293253460910787);
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_str_over_8_bytes(b: &mut Bencher) {
|
||||
let s = "foobarbaz0";
|
||||
b.iter(|| {
|
||||
assert_eq!(hash(&s), 10581415515220175264);
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_long_str(b: &mut Bencher) {
|
||||
let s = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor \
|
||||
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud \
|
||||
exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute \
|
||||
irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla \
|
||||
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui \
|
||||
officia deserunt mollit anim id est laborum.";
|
||||
b.iter(|| {
|
||||
assert_eq!(hash(&s), 17717065544121360093);
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_u32(b: &mut Bencher) {
|
||||
let u = 162629500u32;
|
||||
let u = black_box(u);
|
||||
b.iter(|| {
|
||||
hash(&u)
|
||||
});
|
||||
b.bytes = 8;
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_u32_keyed(b: &mut Bencher) {
|
||||
let u = 162629500u32;
|
||||
let u = black_box(u);
|
||||
let k1 = black_box(0x1);
|
||||
let k2 = black_box(0x2);
|
||||
b.iter(|| {
|
||||
hash_with(SipHasher::new_with_keys(k1, k2), &u)
|
||||
});
|
||||
b.bytes = 8;
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_u64(b: &mut Bencher) {
|
||||
let u = 16262950014981195938u64;
|
||||
let u = black_box(u);
|
||||
b.iter(|| {
|
||||
hash(&u)
|
||||
});
|
||||
b.bytes = 8;
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_bytes_4(b: &mut Bencher) {
|
||||
let data = black_box([b' '; 4]);
|
||||
b.iter(|| {
|
||||
hash_bytes(SipHasher::default(), &data)
|
||||
});
|
||||
b.bytes = 4;
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_bytes_7(b: &mut Bencher) {
|
||||
let data = black_box([b' '; 7]);
|
||||
b.iter(|| {
|
||||
hash_bytes(SipHasher::default(), &data)
|
||||
});
|
||||
b.bytes = 7;
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_bytes_8(b: &mut Bencher) {
|
||||
let data = black_box([b' '; 8]);
|
||||
b.iter(|| {
|
||||
hash_bytes(SipHasher::default(), &data)
|
||||
});
|
||||
b.bytes = 8;
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_bytes_a_16(b: &mut Bencher) {
|
||||
let data = black_box([b' '; 16]);
|
||||
b.iter(|| {
|
||||
hash_bytes(SipHasher::default(), &data)
|
||||
});
|
||||
b.bytes = 16;
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_bytes_b_32(b: &mut Bencher) {
|
||||
let data = black_box([b' '; 32]);
|
||||
b.iter(|| {
|
||||
hash_bytes(SipHasher::default(), &data)
|
||||
});
|
||||
b.bytes = 32;
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_bytes_c_128(b: &mut Bencher) {
|
||||
let data = black_box([b' '; 128]);
|
||||
b.iter(|| {
|
||||
hash_bytes(SipHasher::default(), &data)
|
||||
});
|
||||
b.bytes = 128;
|
||||
}
|
||||
|
@ -12,9 +12,6 @@ use core::iter::*;
|
||||
use core::{i8, i16, isize};
|
||||
use core::usize;
|
||||
|
||||
use test::Bencher;
|
||||
use test::black_box;
|
||||
|
||||
#[test]
|
||||
fn test_lt() {
|
||||
let empty: [isize; 0] = [];
|
||||
@ -1085,91 +1082,3 @@ fn test_chain_fold() {
|
||||
assert_eq!(&[2, 3, 1, 2, 0], &result[..]);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_rposition(b: &mut Bencher) {
|
||||
let it: Vec<usize> = (0..300).collect();
|
||||
b.iter(|| {
|
||||
it.iter().rposition(|&x| x <= 150);
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_skip_while(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let it = 0..100;
|
||||
let mut sum = 0;
|
||||
it.skip_while(|&x| { sum += x; sum < 4000 }).all(|_| true);
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_multiple_take(b: &mut Bencher) {
|
||||
let mut it = (0..42).cycle();
|
||||
b.iter(|| {
|
||||
let n = it.next().unwrap();
|
||||
for _ in 0..n {
|
||||
it.clone().take(it.next().unwrap()).all(|_| true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn scatter(x: i32) -> i32 { (x * 31) % 127 }
|
||||
|
||||
#[bench]
|
||||
fn bench_max_by_key(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let it = 0..100;
|
||||
it.max_by_key(|&x| scatter(x))
|
||||
})
|
||||
}
|
||||
|
||||
// http://www.reddit.com/r/rust/comments/31syce/using_iterators_to_find_the_index_of_the_min_or/
|
||||
#[bench]
|
||||
fn bench_max_by_key2(b: &mut Bencher) {
|
||||
fn max_index_iter(array: &[i32]) -> usize {
|
||||
array.iter().enumerate().max_by_key(|&(_, item)| item).unwrap().0
|
||||
}
|
||||
|
||||
let mut data = vec![0; 1638];
|
||||
data[514] = 9999;
|
||||
|
||||
b.iter(|| max_index_iter(&data));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_max(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let it = 0..100;
|
||||
it.map(scatter).max()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn copy_zip(xs: &[u8], ys: &mut [u8]) {
|
||||
for (a, b) in ys.iter_mut().zip(xs) {
|
||||
*a = *b;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_zip(xs: &[f32], ys: &mut [f32]) {
|
||||
for (a, b) in ys.iter_mut().zip(xs) {
|
||||
*a += *b;
|
||||
}
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_zip_copy(b: &mut Bencher) {
|
||||
let source = vec![0u8; 16 * 1024];
|
||||
let mut dst = black_box(vec![0u8; 16 * 1024]);
|
||||
b.iter(|| {
|
||||
copy_zip(&source, &mut dst)
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_zip_add(b: &mut Bencher) {
|
||||
let source = vec![1.; 16 * 1024];
|
||||
let mut dst = vec![0.; 16 * 1024];
|
||||
b.iter(|| {
|
||||
add_zip(&source, &mut dst)
|
||||
});
|
||||
}
|
||||
|
@ -7,8 +7,8 @@
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use core::mem::*;
|
||||
use test::Bencher;
|
||||
|
||||
#[test]
|
||||
fn size_of_basic() {
|
||||
@ -121,61 +121,3 @@ fn test_transmute() {
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME #13642 (these benchmarks should be in another place)
|
||||
/// Completely miscellaneous language-construct benchmarks.
|
||||
// Static/dynamic method dispatch
|
||||
|
||||
struct Struct {
|
||||
field: isize
|
||||
}
|
||||
|
||||
trait Trait {
|
||||
fn method(&self) -> isize;
|
||||
}
|
||||
|
||||
impl Trait for Struct {
|
||||
fn method(&self) -> isize {
|
||||
self.field
|
||||
}
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn trait_vtable_method_call(b: &mut Bencher) {
|
||||
let s = Struct { field: 10 };
|
||||
let t = &s as &Trait;
|
||||
b.iter(|| {
|
||||
t.method()
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn trait_static_method_call(b: &mut Bencher) {
|
||||
let s = Struct { field: 10 };
|
||||
b.iter(|| {
|
||||
s.method()
|
||||
});
|
||||
}
|
||||
|
||||
// Overhead of various match forms
|
||||
|
||||
#[bench]
|
||||
fn match_option_some(b: &mut Bencher) {
|
||||
let x = Some(10);
|
||||
b.iter(|| {
|
||||
match x {
|
||||
Some(y) => y,
|
||||
None => 11
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn match_vec_pattern(b: &mut Bencher) {
|
||||
let x = [1,2,3,4,5,6];
|
||||
b.iter(|| {
|
||||
match x {
|
||||
[1,2,3,..] => 10,
|
||||
_ => 11,
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -11,7 +11,6 @@
|
||||
#![allow(overflowing_literals)]
|
||||
|
||||
use std::{i64, f32, f64};
|
||||
use test;
|
||||
|
||||
mod parse;
|
||||
mod rawfp;
|
||||
@ -144,59 +143,3 @@ fn borderline_overflow() {
|
||||
// It makes no sense to enshrine that in a test, the important part is that it doesn't panic.
|
||||
let _ = s.parse::<f64>();
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_0(b: &mut test::Bencher) {
|
||||
b.iter(|| "0.0".parse::<f64>());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_42(b: &mut test::Bencher) {
|
||||
b.iter(|| "42".parse::<f64>());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_huge_int(b: &mut test::Bencher) {
|
||||
// 2^128 - 1
|
||||
b.iter(|| "170141183460469231731687303715884105727".parse::<f64>());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_short_decimal(b: &mut test::Bencher) {
|
||||
b.iter(|| "1234.5678".parse::<f64>());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_pi_long(b: &mut test::Bencher) {
|
||||
b.iter(|| "3.14159265358979323846264338327950288".parse::<f64>());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_pi_short(b: &mut test::Bencher) {
|
||||
b.iter(|| "3.141592653589793".parse::<f64>())
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_1e150(b: &mut test::Bencher) {
|
||||
b.iter(|| "1e150".parse::<f64>());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_long_decimal_and_exp(b: &mut test::Bencher) {
|
||||
b.iter(|| "727501488517303786137132964064381141071e-123".parse::<f64>());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_min_subnormal(b: &mut test::Bencher) {
|
||||
b.iter(|| "5e-324".parse::<f64>());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_min_normal(b: &mut test::Bencher) {
|
||||
b.iter(|| "2.2250738585072014e-308".parse::<f64>());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_max(b: &mut test::Bencher) {
|
||||
b.iter(|| "1.7976931348623157e308".parse::<f64>());
|
||||
}
|
||||
|
@ -9,7 +9,6 @@
|
||||
// except according to those terms.
|
||||
|
||||
use std::prelude::v1::*;
|
||||
use std::{i16, f64};
|
||||
use super::super::*;
|
||||
use core::num::bignum::Big32x40 as Big;
|
||||
use core::num::flt2dec::strategy::dragon::*;
|
||||
@ -53,62 +52,6 @@ fn exact_sanity_test() {
|
||||
f32_exact_sanity_test(format_exact);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_small_shortest(b: &mut Bencher) {
|
||||
let decoded = decode_finite(3.141592f64);
|
||||
let mut buf = [0; MAX_SIG_DIGITS];
|
||||
b.iter(|| format_shortest(&decoded, &mut buf));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_big_shortest(b: &mut Bencher) {
|
||||
let decoded = decode_finite(f64::MAX);
|
||||
let mut buf = [0; MAX_SIG_DIGITS];
|
||||
b.iter(|| format_shortest(&decoded, &mut buf));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_small_exact_3(b: &mut Bencher) {
|
||||
let decoded = decode_finite(3.141592f64);
|
||||
let mut buf = [0; 3];
|
||||
b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_big_exact_3(b: &mut Bencher) {
|
||||
let decoded = decode_finite(f64::MAX);
|
||||
let mut buf = [0; 3];
|
||||
b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_small_exact_12(b: &mut Bencher) {
|
||||
let decoded = decode_finite(3.141592f64);
|
||||
let mut buf = [0; 12];
|
||||
b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_big_exact_12(b: &mut Bencher) {
|
||||
let decoded = decode_finite(f64::MAX);
|
||||
let mut buf = [0; 12];
|
||||
b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_small_exact_inf(b: &mut Bencher) {
|
||||
let decoded = decode_finite(3.141592f64);
|
||||
let mut buf = [0; 1024];
|
||||
b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_big_exact_inf(b: &mut Bencher) {
|
||||
let decoded = decode_finite(f64::MAX);
|
||||
let mut buf = [0; 1024];
|
||||
b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_to_shortest_str() {
|
||||
to_shortest_str_test(format_shortest);
|
||||
|
@ -8,7 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::{i16, f64};
|
||||
use std::i16;
|
||||
use super::super::*;
|
||||
use core::num::flt2dec::strategy::grisu::*;
|
||||
|
||||
@ -102,62 +102,6 @@ fn exact_f64_random_equivalence_test() {
|
||||
}
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_small_shortest(b: &mut Bencher) {
|
||||
let decoded = decode_finite(3.141592f64);
|
||||
let mut buf = [0; MAX_SIG_DIGITS];
|
||||
b.iter(|| format_shortest(&decoded, &mut buf));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_big_shortest(b: &mut Bencher) {
|
||||
let decoded = decode_finite(f64::MAX);
|
||||
let mut buf = [0; MAX_SIG_DIGITS];
|
||||
b.iter(|| format_shortest(&decoded, &mut buf));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_small_exact_3(b: &mut Bencher) {
|
||||
let decoded = decode_finite(3.141592f64);
|
||||
let mut buf = [0; 3];
|
||||
b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_big_exact_3(b: &mut Bencher) {
|
||||
let decoded = decode_finite(f64::MAX);
|
||||
let mut buf = [0; 3];
|
||||
b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_small_exact_12(b: &mut Bencher) {
|
||||
let decoded = decode_finite(3.141592f64);
|
||||
let mut buf = [0; 12];
|
||||
b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_big_exact_12(b: &mut Bencher) {
|
||||
let decoded = decode_finite(f64::MAX);
|
||||
let mut buf = [0; 12];
|
||||
b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_small_exact_inf(b: &mut Bencher) {
|
||||
let decoded = decode_finite(3.141592f64);
|
||||
let mut buf = [0; 1024];
|
||||
b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_big_exact_inf(b: &mut Bencher) {
|
||||
let decoded = decode_finite(f64::MAX);
|
||||
let mut buf = [0; 1024];
|
||||
b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_to_shortest_str() {
|
||||
to_shortest_str_test(format_shortest);
|
||||
|
@ -8,27 +8,8 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use test::Bencher;
|
||||
use core::ops::{Range, RangeFull, RangeFrom, RangeTo};
|
||||
|
||||
// Overhead of dtors
|
||||
|
||||
struct HasDtor {
|
||||
_x: isize
|
||||
}
|
||||
|
||||
impl Drop for HasDtor {
|
||||
fn drop(&mut self) {
|
||||
}
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn alloc_obj_with_dtor(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
HasDtor { _x : 10 };
|
||||
})
|
||||
}
|
||||
|
||||
// Test the Range structs without the syntactic sugar.
|
||||
|
||||
#[test]
|
||||
|
@ -31,7 +31,7 @@ use std::io;
|
||||
// https://github.com/rust-lang/rust/issues/25505#issuecomment-102876737
|
||||
pub fn fix_windows_verbatim_for_gcc(p: &Path) -> PathBuf {
|
||||
if !cfg!(windows) {
|
||||
return p.to_path_buf()
|
||||
return p.to_path_buf();
|
||||
}
|
||||
let mut components = p.components();
|
||||
let prefix = match components.next() {
|
||||
@ -58,7 +58,7 @@ pub fn fix_windows_verbatim_for_gcc(p: &Path) -> PathBuf {
|
||||
|
||||
pub enum LinkOrCopy {
|
||||
Link,
|
||||
Copy
|
||||
Copy,
|
||||
}
|
||||
|
||||
/// Copy `p` into `q`, preferring to use hard-linking if possible. If
|
||||
@ -76,7 +76,35 @@ pub fn link_or_copy<P: AsRef<Path>, Q: AsRef<Path>>(p: P, q: Q) -> io::Result<Li
|
||||
Err(_) => {
|
||||
match fs::copy(p, q) {
|
||||
Ok(_) => Ok(LinkOrCopy::Copy),
|
||||
Err(e) => Err(e)
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum RenameOrCopyRemove {
|
||||
Rename,
|
||||
CopyRemove,
|
||||
}
|
||||
|
||||
/// Rename `p` into `q`, preferring to use `rename` if possible.
|
||||
/// If `rename` fails (rename may fail for reasons such as crossing
|
||||
/// filesystem), fallback to copy & remove
|
||||
pub fn rename_or_copy_remove<P: AsRef<Path>, Q: AsRef<Path>>(p: P,
|
||||
q: Q)
|
||||
-> io::Result<RenameOrCopyRemove> {
|
||||
let p = p.as_ref();
|
||||
let q = q.as_ref();
|
||||
match fs::rename(p, q) {
|
||||
Ok(()) => Ok(RenameOrCopyRemove::Rename),
|
||||
Err(_) => {
|
||||
match fs::copy(p, q) {
|
||||
Ok(_) => {
|
||||
fs::remove_file(p)?;
|
||||
Ok(RenameOrCopyRemove::CopyRemove)
|
||||
}
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -93,8 +121,7 @@ pub fn create_dir_racy(path: &Path) -> io::Result<()> {
|
||||
}
|
||||
match path.parent() {
|
||||
Some(p) => try!(create_dir_racy(p)),
|
||||
None => return Err(io::Error::new(io::ErrorKind::Other,
|
||||
"failed to create whole tree")),
|
||||
None => return Err(io::Error::new(io::ErrorKind::Other, "failed to create whole tree")),
|
||||
}
|
||||
match fs::create_dir(path) {
|
||||
Ok(()) => Ok(()),
|
||||
|
34
src/librustc_back/target/aarch64_unknown_freebsd.rs
Normal file
34
src/librustc_back/target/aarch64_unknown_freebsd.rs
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use target::{Target, TargetOptions, TargetResult};
|
||||
|
||||
pub fn target() -> TargetResult {
|
||||
let mut base = super::freebsd_base::opts();
|
||||
base.max_atomic_width = Some(128);
|
||||
|
||||
// see #36994
|
||||
base.exe_allocation_crate = "alloc_system".to_string();
|
||||
|
||||
Ok(Target {
|
||||
llvm_target: "aarch64-unknown-freebsd".to_string(),
|
||||
target_endian: "little".to_string(),
|
||||
target_pointer_width: "64".to_string(),
|
||||
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
|
||||
arch: "aarch64".to_string(),
|
||||
target_os: "freebsd".to_string(),
|
||||
target_env: "".to_string(),
|
||||
target_vendor: "unknown".to_string(),
|
||||
options: TargetOptions {
|
||||
abi_blacklist: super::arm_base::abi_blacklist(),
|
||||
.. base
|
||||
},
|
||||
})
|
||||
}
|
@ -165,6 +165,7 @@ supported_targets! {
|
||||
("armv7-linux-androideabi", armv7_linux_androideabi),
|
||||
("aarch64-linux-android", aarch64_linux_android),
|
||||
|
||||
("aarch64-unknown-freebsd", aarch64_unknown_freebsd),
|
||||
("i686-unknown-freebsd", i686_unknown_freebsd),
|
||||
("x86_64-unknown-freebsd", x86_64_unknown_freebsd),
|
||||
|
||||
|
@ -273,7 +273,7 @@ fn check_arms<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
|
||||
let mut seen = Matrix::empty();
|
||||
let mut catchall = None;
|
||||
let mut printed_if_let_err = false;
|
||||
for &(ref pats, guard) in arms {
|
||||
for (arm_index, &(ref pats, guard)) in arms.iter().enumerate() {
|
||||
for &(pat, hir_pat) in pats {
|
||||
let v = vec![pat];
|
||||
|
||||
@ -302,10 +302,27 @@ fn check_arms<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
|
||||
let &(ref first_arm_pats, _) = &arms[0];
|
||||
let first_pat = &first_arm_pats[0];
|
||||
let span = first_pat.0.span;
|
||||
struct_span_err!(cx.tcx.sess, span, E0165,
|
||||
"irrefutable while-let pattern")
|
||||
.span_label(span, &format!("irrefutable pattern"))
|
||||
.emit();
|
||||
|
||||
// check which arm we're on.
|
||||
match arm_index {
|
||||
// The arm with the user-specified pattern.
|
||||
0 => {
|
||||
let mut diagnostic = Diagnostic::new(Level::Warning,
|
||||
"unreachable pattern");
|
||||
diagnostic.set_span(pat.span);
|
||||
cx.tcx.sess.add_lint_diagnostic(
|
||||
lint::builtin::UNREACHABLE_PATTERNS,
|
||||
hir_pat.id, diagnostic);
|
||||
},
|
||||
// The arm with the wildcard pattern.
|
||||
1 => {
|
||||
struct_span_err!(cx.tcx.sess, span, E0165,
|
||||
"irrefutable while-let pattern")
|
||||
.span_label(span, &format!("irrefutable pattern"))
|
||||
.emit();
|
||||
},
|
||||
_ => bug!(),
|
||||
}
|
||||
},
|
||||
|
||||
hir::MatchSource::ForLoopDesugar |
|
||||
|
@ -482,12 +482,9 @@ fn eval_const_expr_partial<'a, 'tcx>(cx: &ConstContext<'a, 'tcx>,
|
||||
(&LitKind::Int(I64_OVERFLOW, Signed(IntTy::I64)), _) => {
|
||||
return Ok(Integral(I64(i64::min_value())))
|
||||
},
|
||||
(&LitKind::Int(n, _), Some(&ty::TyInt(IntTy::I128))) |
|
||||
(&LitKind::Int(n, Signed(IntTy::I128)), _) => {
|
||||
// SNAP: replace n in pattern with I128_OVERFLOW and remove this if.
|
||||
if n == I128_OVERFLOW {
|
||||
return Ok(Integral(I128(i128::min_value())))
|
||||
}
|
||||
(&LitKind::Int(I128_OVERFLOW, _), Some(&ty::TyInt(IntTy::I128))) |
|
||||
(&LitKind::Int(I128_OVERFLOW, Signed(IntTy::I128)), _) => {
|
||||
return Ok(Integral(I128(i128::min_value())))
|
||||
},
|
||||
(&LitKind::Int(n, _), Some(&ty::TyInt(IntTy::Is))) |
|
||||
(&LitKind::Int(n, Signed(IntTy::Is)), _) => {
|
||||
|
@ -155,13 +155,11 @@ impl ConstInt {
|
||||
(InferSigned(a @ 0...ibounds::U8MAX), U8(_)) => U8(a as u8),
|
||||
(InferSigned(a @ 0...ibounds::U16MAX), U16(_)) => U16(a as u16),
|
||||
(InferSigned(a @ 0...ibounds::U32MAX), U32(_)) => U32(a as u32),
|
||||
// SNAP: replace with U64MAX
|
||||
(InferSigned(a @ 0...ibounds::I64MAX), U64(_)) => U64(a as u64),
|
||||
(InferSigned(a @ 0...ibounds::U64MAX), U64(_)) => U64(a as u64),
|
||||
(InferSigned(a @ 0...ibounds::I128MAX), U128(_)) => U128(a as u128),
|
||||
(InferSigned(a @ 0...ibounds::U16MAX), Usize(Us16(_))) => Usize(Us16(a as u16)),
|
||||
(InferSigned(a @ 0...ibounds::U32MAX), Usize(Us32(_))) => Usize(Us32(a as u32)),
|
||||
// SNAP: replace with U64MAX
|
||||
(InferSigned(a @ 0...ibounds::I64MAX), Usize(Us64(_))) => Usize(Us64(a as u64)),
|
||||
(InferSigned(a @ 0...ibounds::U64MAX), Usize(Us64(_))) => Usize(Us64(a as u64)),
|
||||
(InferSigned(_), _) => return Err(ConstMathErr::NotInRange),
|
||||
_ => self, // already known types
|
||||
};
|
||||
|
@ -22,6 +22,7 @@ use rustc::middle::privacy::AccessLevels;
|
||||
use rustc::ty::{self, TyCtxt, Resolutions, GlobalArenas};
|
||||
use rustc::util::common::time;
|
||||
use rustc::util::nodemap::{NodeSet, NodeMap};
|
||||
use rustc::util::fs::rename_or_copy_remove;
|
||||
use rustc_borrowck as borrowck;
|
||||
use rustc_incremental::{self, IncrementalHashesMap};
|
||||
use rustc_incremental::ich::Fingerprint;
|
||||
@ -1084,10 +1085,9 @@ pub fn phase_5_run_llvm_passes(sess: &Session,
|
||||
// are going to build an executable
|
||||
if sess.opts.output_types.contains_key(&OutputType::Exe) {
|
||||
let f = outputs.path(OutputType::Object);
|
||||
fs::copy(&f,
|
||||
rename_or_copy_remove(&f,
|
||||
f.with_file_name(format!("{}.0.o",
|
||||
f.file_stem().unwrap().to_string_lossy()))).unwrap();
|
||||
fs::remove_file(f).unwrap();
|
||||
}
|
||||
|
||||
// Remove assembly source, unless --save-temps was specified
|
||||
|
@ -8,6 +8,12 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// FIXME: Rename 'DIGlobalVariable' to 'DIGlobalVariableExpression'
|
||||
// once support for LLVM 3.9 is dropped.
|
||||
//
|
||||
// This method was changed in this LLVM patch:
|
||||
// https://reviews.llvm.org/D26769
|
||||
|
||||
use debuginfo::{DIBuilderRef, DIDescriptor, DIFile, DILexicalBlock, DISubprogram, DIType,
|
||||
DIBasicType, DIDerivedType, DICompositeType, DIScope, DIVariable,
|
||||
DIGlobalVariable, DIArray, DISubrange, DITemplateTypeParameter, DIEnumerator,
|
||||
|
@ -229,15 +229,10 @@ pub fn C_integral(t: Type, u: u64, sign_extend: bool) -> ValueRef {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn C_big_integral(t: Type, u: u128, sign_extend: bool) -> ValueRef {
|
||||
if ::std::mem::size_of::<u128>() == 16 {
|
||||
unsafe {
|
||||
let words = [u as u64, u.wrapping_shr(64) as u64];
|
||||
llvm::LLVMConstIntOfArbitraryPrecision(t.to_ref(), 2, words.as_ptr())
|
||||
}
|
||||
} else {
|
||||
// SNAP: remove after snapshot
|
||||
C_integral(t, u as u64, sign_extend)
|
||||
pub fn C_big_integral(t: Type, u: u128) -> ValueRef {
|
||||
unsafe {
|
||||
let words = [u as u64, u.wrapping_shr(64) as u64];
|
||||
llvm::LLVMConstIntOfArbitraryPrecision(t.to_ref(), 2, words.as_ptr())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ impl<'tcx> Const<'tcx> {
|
||||
ConstVal::Integral(I16(v)) => C_integral(Type::i16(ccx), v as u64, true),
|
||||
ConstVal::Integral(I32(v)) => C_integral(Type::i32(ccx), v as u64, true),
|
||||
ConstVal::Integral(I64(v)) => C_integral(Type::i64(ccx), v as u64, true),
|
||||
ConstVal::Integral(I128(v)) => C_big_integral(Type::i128(ccx), v as u128, true),
|
||||
ConstVal::Integral(I128(v)) => C_big_integral(Type::i128(ccx), v as u128),
|
||||
ConstVal::Integral(Isize(v)) => {
|
||||
let i = v.as_i64(ccx.tcx().sess.target.int_type);
|
||||
C_integral(Type::int(ccx), i as u64, true)
|
||||
@ -84,7 +84,7 @@ impl<'tcx> Const<'tcx> {
|
||||
ConstVal::Integral(U16(v)) => C_integral(Type::i16(ccx), v as u64, false),
|
||||
ConstVal::Integral(U32(v)) => C_integral(Type::i32(ccx), v as u64, false),
|
||||
ConstVal::Integral(U64(v)) => C_integral(Type::i64(ccx), v, false),
|
||||
ConstVal::Integral(U128(v)) => C_big_integral(Type::i128(ccx), v, false),
|
||||
ConstVal::Integral(U128(v)) => C_big_integral(Type::i128(ccx), v),
|
||||
ConstVal::Integral(Usize(v)) => {
|
||||
let u = v.as_u64(ccx.tcx().sess.target.uint_type);
|
||||
C_integral(Type::int(ccx), u, false)
|
||||
|
@ -144,11 +144,24 @@ impl FileDesc {
|
||||
pub fn set_cloexec(&self) -> io::Result<()> {
|
||||
unsafe {
|
||||
let previous = cvt(libc::fcntl(self.fd, libc::F_GETFD))?;
|
||||
cvt(libc::fcntl(self.fd, libc::F_SETFD, previous | libc::FD_CLOEXEC))?;
|
||||
let new = previous | libc::FD_CLOEXEC;
|
||||
if new != previous {
|
||||
cvt(libc::fcntl(self.fd, libc::F_SETFD, new))?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
|
||||
unsafe {
|
||||
let v = nonblocking as c_int;
|
||||
cvt(libc::ioctl(self.fd, libc::FIONBIO, &v))?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
|
||||
unsafe {
|
||||
let previous = cvt(libc::fcntl(self.fd, libc::F_GETFL))?;
|
||||
@ -157,7 +170,9 @@ impl FileDesc {
|
||||
} else {
|
||||
previous & !libc::O_NONBLOCK
|
||||
};
|
||||
cvt(libc::fcntl(self.fd, libc::F_SETFL, new))?;
|
||||
if new != previous {
|
||||
cvt(libc::fcntl(self.fd, libc::F_SETFL, new))?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -588,7 +588,11 @@ extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateStaticVariable(
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LLVM_VERSION_GE(4, 0)
|
||||
return wrap(Builder->createGlobalVariableExpression(
|
||||
#else
|
||||
return wrap(Builder->createGlobalVariable(
|
||||
#endif
|
||||
unwrapDI<DIDescriptor>(Context), Name, LinkageName,
|
||||
unwrapDI<DIFile>(File), LineNo, unwrapDI<DIType>(Ty), IsLocalToUnit,
|
||||
#if LLVM_VERSION_GE(4, 0)
|
||||
|
@ -24,6 +24,10 @@ struct NotSoSecretlyEmpty {
|
||||
_priv: !,
|
||||
}
|
||||
|
||||
fn foo() -> Option<NotSoSecretlyEmpty> {
|
||||
None
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x: &[!] = &[];
|
||||
|
||||
@ -45,5 +49,9 @@ fn main() {
|
||||
Err(Err(_y)) => (),
|
||||
Err(Ok(_y)) => (), //~ ERROR unreachable pattern
|
||||
}
|
||||
|
||||
while let Some(_y) = foo() {
|
||||
//~^ ERROR unreachable pattern
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
// ignore-tidy-linelength
|
||||
// min-lldb-version: 310
|
||||
// ignore-gdb-version: 7.11.90 - 7.12
|
||||
// ignore-gdb-version: 7.11.90 - 7.12.9
|
||||
|
||||
// compile-flags:-g
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
// ignore-tidy-linelength
|
||||
// min-lldb-version: 310
|
||||
// ignore-gdb-version: 7.11.90 - 7.12
|
||||
// ignore-gdb-version: 7.11.90 - 7.12.9
|
||||
|
||||
// compile-flags:-g
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
// ignore-tidy-linelength
|
||||
// min-lldb-version: 310
|
||||
// ignore-gdb-version: 7.11.90 - 7.12
|
||||
// ignore-gdb-version: 7.11.90 - 7.12.9
|
||||
|
||||
// compile-flags:-g
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
// ignore-tidy-linelength
|
||||
// min-lldb-version: 310
|
||||
// ignore-gdb-version: 7.11.90 - 7.12
|
||||
// ignore-gdb-version: 7.11.90 - 7.12.9
|
||||
|
||||
// compile-flags:-g
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
// ignore-tidy-linelength
|
||||
// ignore-lldb
|
||||
// ignore-gdb-version: 7.11.90 - 7.12
|
||||
// ignore-gdb-version: 7.11.90 - 7.12.9
|
||||
|
||||
// compile-flags:-g
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
// ignore-tidy-linelength
|
||||
// min-lldb-version: 310
|
||||
// ignore-gdb-version: 7.11.90 - 7.12
|
||||
// ignore-gdb-version: 7.11.90 - 7.12.9
|
||||
|
||||
// compile-flags:-g
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
// ignore-tidy-linelength
|
||||
// min-lldb-version: 310
|
||||
// ignore-gdb-version: 7.11.90 - 7.12
|
||||
// ignore-gdb-version: 7.11.90 - 7.12.9
|
||||
|
||||
// compile-flags:-g
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
// ignore-tidy-linelength
|
||||
// min-lldb-version: 310
|
||||
// ignore-gdb-version: 7.11.90 - 7.12
|
||||
// ignore-gdb-version: 7.11.90 - 7.12.9
|
||||
|
||||
// compile-flags:-g
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
// except according to those terms.
|
||||
|
||||
// min-lldb-version: 310
|
||||
// ignore-gdb-version: 7.11.90 - 7.12
|
||||
// ignore-gdb-version: 7.11.90 - 7.12.9
|
||||
|
||||
// compile-flags:-g
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
// ignore-tidy-linelength
|
||||
// min-lldb-version: 310
|
||||
// ignore-gdb-version: 7.11.90 - 7.12
|
||||
// ignore-gdb-version: 7.11.90 - 7.12.9
|
||||
|
||||
// compile-flags:-g
|
||||
|
||||
|
@ -8,9 +8,6 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-stage0
|
||||
// ignore-stage1
|
||||
|
||||
// MSVC doesn't support 128 bit integers, and other Windows
|
||||
// C compilers have very inconsistent views on how the ABI
|
||||
// should look like.
|
||||
|
@ -8,9 +8,6 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-stage0
|
||||
// ignore-stage1
|
||||
|
||||
// ignore-emscripten
|
||||
|
||||
#![feature(i128_type, test)]
|
||||
|
@ -9,10 +9,6 @@
|
||||
// except according to those terms.
|
||||
#![feature(i128_type)]
|
||||
|
||||
// SNAP: run on all stages after snapshot, i128 currently doesn't work on stages 0 and 1
|
||||
// ignore-stage1
|
||||
// ignore-stage0
|
||||
|
||||
fn main() {
|
||||
let _ = -0x8000_0000_0000_0000_0000_0000_0000_0000i128;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user