From 3ccb87a532159701486ae0ca33346c838791c699 Mon Sep 17 00:00:00 2001 From: Tatsuyuki Ishi Date: Fri, 3 Feb 2017 16:15:34 +0900 Subject: [PATCH 01/19] liballoc_jemalloc: fix linking with system library --- src/liballoc_jemalloc/build.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/liballoc_jemalloc/build.rs b/src/liballoc_jemalloc/build.rs index 1143df0c6302d..297f5ce99fd5e 100644 --- a/src/liballoc_jemalloc/build.rs +++ b/src/liballoc_jemalloc/build.rs @@ -42,6 +42,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={}", @@ -176,11 +182,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"); - } // The pthread_atfork symbols is used by jemalloc on android but the really // old android we're building on doesn't have them defined, so just make From 458167e3a066ae7a032dbd457d003c9266d6b080 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20P=C3=A9dron?= Date: Wed, 25 Jan 2017 21:09:18 +0100 Subject: [PATCH 02/19] Add `aarch64-unknown-freebsd` to the supported targets --- mk/cfg/aarch64-unknown-freebsd.mk | 1 + .../target/aarch64_unknown_freebsd.rs | 34 +++++++++++++++++++ src/librustc_back/target/mod.rs | 1 + 3 files changed, 36 insertions(+) create mode 100644 mk/cfg/aarch64-unknown-freebsd.mk create mode 100644 src/librustc_back/target/aarch64_unknown_freebsd.rs diff --git a/mk/cfg/aarch64-unknown-freebsd.mk b/mk/cfg/aarch64-unknown-freebsd.mk new file mode 100644 index 0000000000000..34aee77ae2107 --- /dev/null +++ b/mk/cfg/aarch64-unknown-freebsd.mk @@ -0,0 +1 @@ +# rustbuild-only target diff --git a/src/librustc_back/target/aarch64_unknown_freebsd.rs b/src/librustc_back/target/aarch64_unknown_freebsd.rs new file mode 100644 index 0000000000000..3c5d6308ee6ba --- /dev/null +++ b/src/librustc_back/target/aarch64_unknown_freebsd.rs @@ -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 or the MIT license +// , 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 + }, + }) +} diff --git a/src/librustc_back/target/mod.rs b/src/librustc_back/target/mod.rs index 5afa85d155279..d6acdceb3f5e2 100644 --- a/src/librustc_back/target/mod.rs +++ b/src/librustc_back/target/mod.rs @@ -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), From f6c6b31d26b5b08fbd1df907e37c5c02c7d71f90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20P=C3=A9dron?= Date: Fri, 3 Feb 2017 08:56:46 +0100 Subject: [PATCH 03/19] `aarch64` CPU type is called `arm64` on FreeBSD --- configure | 2 +- src/bootstrap/bootstrap.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/configure b/configure index 208fb7e683637..eea70b33e7ea9 100755 --- a/configure +++ b/configure @@ -517,7 +517,7 @@ case $CFG_CPUTYPE in CFG_OSTYPE="${CFG_OSTYPE}eabihf" ;; - aarch64) + aarch64 | arm64) CFG_CPUTYPE=aarch64 ;; diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index 85e8dbce1a955..7265d183000d3 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -379,6 +379,8 @@ def build_triple(self): ostype += 'eabihf' elif cputype == 'aarch64': cputype = 'aarch64' + elif cputype == 'arm64': + cputype = 'aarch64' elif cputype == 'mips': if sys.byteorder == 'big': cputype = 'mips' From 5e41ec2cccb86db1a9677d2bfb9d2f623755f3de Mon Sep 17 00:00:00 2001 From: king6cong Date: Wed, 1 Feb 2017 11:49:24 +0800 Subject: [PATCH 04/19] rename other than copy/remove --- src/librustc_driver/driver.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index a04a5b106b8f1..6fe6541c1d919 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -1084,10 +1084,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, + fs::rename(&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 From 768f6a9b57c83030919adb30565918f1b520596f Mon Sep 17 00:00:00 2001 From: king6cong Date: Fri, 3 Feb 2017 17:42:01 +0800 Subject: [PATCH 05/19] add and use rename_or_copy_remove fn that fallback to copy & remove --- src/librustc/util/fs.rs | 25 +++++++++++++++++++++++++ src/librustc_driver/driver.rs | 3 ++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/librustc/util/fs.rs b/src/librustc/util/fs.rs index c290d8f893e9e..7f8a69de60723 100644 --- a/src/librustc/util/fs.rs +++ b/src/librustc/util/fs.rs @@ -82,6 +82,31 @@ pub fn link_or_copy, Q: AsRef>(p: P, q: Q) -> io::Result
  • , Q: AsRef>(p: P, q: Q) -> io::Result { + 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) + } + } + } +} + // Like std::fs::create_dir_all, except handles concurrent calls among multiple // threads or processes. pub fn create_dir_racy(path: &Path) -> io::Result<()> { diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index 6fe6541c1d919..33bf4d5276adf 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -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,7 +1085,7 @@ 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::rename(&f, + rename_or_copy_remove(&f, f.with_file_name(format!("{}.0.o", f.file_stem().unwrap().to_string_lossy()))).unwrap(); } From d14b268b9d0f37811c47cc6b1ebf2433fbb0ad0e Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 4 Feb 2017 01:18:10 +0300 Subject: [PATCH 06/19] libbacktrace: Fix uninitialized variable --- src/libbacktrace/pecoff.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libbacktrace/pecoff.c b/src/libbacktrace/pecoff.c index 04e0bafb14981..2d6a9877219dc 100644 --- a/src/libbacktrace/pecoff.c +++ b/src/libbacktrace/pecoff.c @@ -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; From 34f444de5d2fbab533eb523f8d8b0b75bf07217d Mon Sep 17 00:00:00 2001 From: Son Date: Sat, 4 Feb 2017 10:04:22 +1100 Subject: [PATCH 07/19] Extract libcore benchmarks to a separate folder --- src/libcore/Cargo.toml | 7 +- src/libcore/bench/any.rs | 22 +++ src/libcore/bench/hash/mod.rs | 11 ++ src/libcore/bench/hash/sip.rs | 151 ++++++++++++++++++ src/libcore/bench/iter.rs | 101 ++++++++++++ src/libcore/bench/lib.rs | 25 +++ src/libcore/bench/mem.rs | 70 ++++++++ src/libcore/bench/num/dec2flt/mod.rs | 68 ++++++++ src/libcore/bench/num/flt2dec/mod.rs | 24 +++ .../bench/num/flt2dec/strategy/dragon.rs | 70 ++++++++ .../bench/num/flt2dec/strategy/grisu.rs | 77 +++++++++ src/libcore/bench/num/mod.rs | 12 ++ src/libcore/bench/ops.rs | 30 ++++ src/libcoretest/any.rs | 13 +- src/libcoretest/hash/sip.rs | 130 --------------- src/libcoretest/iter.rs | 91 ----------- src/libcoretest/mem.rs | 60 +------ src/libcoretest/num/dec2flt/mod.rs | 57 ------- .../num/flt2dec/strategy/dragon.rs | 57 ------- src/libcoretest/num/flt2dec/strategy/grisu.rs | 58 +------ src/libcoretest/ops.rs | 19 --- 21 files changed, 667 insertions(+), 486 deletions(-) create mode 100644 src/libcore/bench/any.rs create mode 100644 src/libcore/bench/hash/mod.rs create mode 100644 src/libcore/bench/hash/sip.rs create mode 100644 src/libcore/bench/iter.rs create mode 100644 src/libcore/bench/lib.rs create mode 100644 src/libcore/bench/mem.rs create mode 100644 src/libcore/bench/num/dec2flt/mod.rs create mode 100644 src/libcore/bench/num/flt2dec/mod.rs create mode 100644 src/libcore/bench/num/flt2dec/strategy/dragon.rs create mode 100644 src/libcore/bench/num/flt2dec/strategy/grisu.rs create mode 100644 src/libcore/bench/num/mod.rs create mode 100644 src/libcore/bench/ops.rs diff --git a/src/libcore/Cargo.toml b/src/libcore/Cargo.toml index e0dbc096cd0d9..4f7cd7b016d66 100644 --- a/src/libcore/Cargo.toml +++ b/src/libcore/Cargo.toml @@ -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" diff --git a/src/libcore/bench/any.rs b/src/libcore/bench/any.rs new file mode 100644 index 0000000000000..67e02cf9509b6 --- /dev/null +++ b/src/libcore/bench/any.rs @@ -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 or the MIT license +// , 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::() == Some(&0)); + }); +} diff --git a/src/libcore/bench/hash/mod.rs b/src/libcore/bench/hash/mod.rs new file mode 100644 index 0000000000000..55d9e3e091380 --- /dev/null +++ b/src/libcore/bench/hash/mod.rs @@ -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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +mod sip; diff --git a/src/libcore/bench/hash/sip.rs b/src/libcore/bench/hash/sip.rs new file mode 100644 index 0000000000000..3379c85bbec7d --- /dev/null +++ b/src/libcore/bench/hash/sip.rs @@ -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 or the MIT license +// , 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(mut s: H, x: &[u8]) -> u64 { + Hasher::write(&mut s, x); + s.finish() +} + +fn hash_with(mut st: H, x: &T) -> u64 { + x.hash(&mut st); + st.finish() +} + +fn 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; +} diff --git a/src/libcore/bench/iter.rs b/src/libcore/bench/iter.rs new file mode 100644 index 0000000000000..93d38a5bc83bb --- /dev/null +++ b/src/libcore/bench/iter.rs @@ -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 or the MIT license +// , 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 = (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) + }); +} diff --git a/src/libcore/bench/lib.rs b/src/libcore/bench/lib.rs new file mode 100644 index 0000000000000..d2db329da7999 --- /dev/null +++ b/src/libcore/bench/lib.rs @@ -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 or the MIT license +// , 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; diff --git a/src/libcore/bench/mem.rs b/src/libcore/bench/mem.rs new file mode 100644 index 0000000000000..8e541d92a7f17 --- /dev/null +++ b/src/libcore/bench/mem.rs @@ -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 or the MIT license +// , 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, + } + }); +} diff --git a/src/libcore/bench/num/dec2flt/mod.rs b/src/libcore/bench/num/dec2flt/mod.rs new file mode 100644 index 0000000000000..562866e11777c --- /dev/null +++ b/src/libcore/bench/num/dec2flt/mod.rs @@ -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 or the MIT license +// , 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::()); +} + +#[bench] +fn bench_42(b: &mut Bencher) { + b.iter(|| "42".parse::()); +} + +#[bench] +fn bench_huge_int(b: &mut Bencher) { + // 2^128 - 1 + b.iter(|| "170141183460469231731687303715884105727".parse::()); +} + +#[bench] +fn bench_short_decimal(b: &mut Bencher) { + b.iter(|| "1234.5678".parse::()); +} + +#[bench] +fn bench_pi_long(b: &mut Bencher) { + b.iter(|| "3.14159265358979323846264338327950288".parse::()); +} + +#[bench] +fn bench_pi_short(b: &mut Bencher) { + b.iter(|| "3.141592653589793".parse::()) +} + +#[bench] +fn bench_1e150(b: &mut Bencher) { + b.iter(|| "1e150".parse::()); +} + +#[bench] +fn bench_long_decimal_and_exp(b: &mut Bencher) { + b.iter(|| "727501488517303786137132964064381141071e-123".parse::()); +} + +#[bench] +fn bench_min_subnormal(b: &mut Bencher) { + b.iter(|| "5e-324".parse::()); +} + +#[bench] +fn bench_min_normal(b: &mut Bencher) { + b.iter(|| "2.2250738585072014e-308".parse::()); +} + +#[bench] +fn bench_max(b: &mut Bencher) { + b.iter(|| "1.7976931348623157e308".parse::()); +} diff --git a/src/libcore/bench/num/flt2dec/mod.rs b/src/libcore/bench/num/flt2dec/mod.rs new file mode 100644 index 0000000000000..1de2bf4921f58 --- /dev/null +++ b/src/libcore/bench/num/flt2dec/mod.rs @@ -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 or the MIT license +// , 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(v: T) -> Decoded { + match decode(v).1 { + FullDecoded::Finite(decoded) => decoded, + full_decoded => panic!("expected finite, got {:?} instead", full_decoded) + } +} diff --git a/src/libcore/bench/num/flt2dec/strategy/dragon.rs b/src/libcore/bench/num/flt2dec/strategy/dragon.rs new file mode 100644 index 0000000000000..6824cf40ed2ae --- /dev/null +++ b/src/libcore/bench/num/flt2dec/strategy/dragon.rs @@ -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 or the MIT license +// , 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)); +} diff --git a/src/libcore/bench/num/flt2dec/strategy/grisu.rs b/src/libcore/bench/num/flt2dec/strategy/grisu.rs new file mode 100644 index 0000000000000..82e1a858fca9f --- /dev/null +++ b/src/libcore/bench/num/flt2dec/strategy/grisu.rs @@ -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 or the MIT license +// , 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(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)); +} diff --git a/src/libcore/bench/num/mod.rs b/src/libcore/bench/num/mod.rs new file mode 100644 index 0000000000000..55f0bdb57ec82 --- /dev/null +++ b/src/libcore/bench/num/mod.rs @@ -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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +mod flt2dec; +mod dec2flt; diff --git a/src/libcore/bench/ops.rs b/src/libcore/bench/ops.rs new file mode 100644 index 0000000000000..7f36a4b0771aa --- /dev/null +++ b/src/libcore/bench/ops.rs @@ -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 or the MIT license +// , 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 }; + }) +} diff --git a/src/libcoretest/any.rs b/src/libcoretest/any.rs index a9fc8913182b3..2d3e81aa131ed 100644 --- a/src/libcoretest/any.rs +++ b/src/libcoretest/any.rs @@ -7,9 +7,8 @@ // , 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() {} 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::() == Some(&0)); - }); -} diff --git a/src/libcoretest/hash/sip.rs b/src/libcoretest/hash/sip.rs index fa3bfdea42df8..4a9657e03404a 100644 --- a/src/libcoretest/hash/sip.rs +++ b/src/libcoretest/hash/sip.rs @@ -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(x: &T) -> u64 { hash_with(SipHasher::new(), x) } -fn hash_bytes(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; -} diff --git a/src/libcoretest/iter.rs b/src/libcoretest/iter.rs index 6d02f76c33d16..89f59a9c2de76 100644 --- a/src/libcoretest/iter.rs +++ b/src/libcoretest/iter.rs @@ -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] = []; @@ -1079,91 +1076,3 @@ fn test_chain_fold() { assert_eq!(&[2, 3, 1, 2, 0], &result[..]); } -#[bench] -fn bench_rposition(b: &mut Bencher) { - let it: Vec = (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) - }); -} diff --git a/src/libcoretest/mem.rs b/src/libcoretest/mem.rs index 01bafe49a7acd..86e59c736ba4a 100644 --- a/src/libcoretest/mem.rs +++ b/src/libcoretest/mem.rs @@ -7,8 +7,8 @@ // , 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, - } - }); -} diff --git a/src/libcoretest/num/dec2flt/mod.rs b/src/libcoretest/num/dec2flt/mod.rs index fe6f52406fbc8..5d546c643e7ee 100644 --- a/src/libcoretest/num/dec2flt/mod.rs +++ b/src/libcoretest/num/dec2flt/mod.rs @@ -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::(); } - -#[bench] -fn bench_0(b: &mut test::Bencher) { - b.iter(|| "0.0".parse::()); -} - -#[bench] -fn bench_42(b: &mut test::Bencher) { - b.iter(|| "42".parse::()); -} - -#[bench] -fn bench_huge_int(b: &mut test::Bencher) { - // 2^128 - 1 - b.iter(|| "170141183460469231731687303715884105727".parse::()); -} - -#[bench] -fn bench_short_decimal(b: &mut test::Bencher) { - b.iter(|| "1234.5678".parse::()); -} - -#[bench] -fn bench_pi_long(b: &mut test::Bencher) { - b.iter(|| "3.14159265358979323846264338327950288".parse::()); -} - -#[bench] -fn bench_pi_short(b: &mut test::Bencher) { - b.iter(|| "3.141592653589793".parse::()) -} - -#[bench] -fn bench_1e150(b: &mut test::Bencher) { - b.iter(|| "1e150".parse::()); -} - -#[bench] -fn bench_long_decimal_and_exp(b: &mut test::Bencher) { - b.iter(|| "727501488517303786137132964064381141071e-123".parse::()); -} - -#[bench] -fn bench_min_subnormal(b: &mut test::Bencher) { - b.iter(|| "5e-324".parse::()); -} - -#[bench] -fn bench_min_normal(b: &mut test::Bencher) { - b.iter(|| "2.2250738585072014e-308".parse::()); -} - -#[bench] -fn bench_max(b: &mut test::Bencher) { - b.iter(|| "1.7976931348623157e308".parse::()); -} diff --git a/src/libcoretest/num/flt2dec/strategy/dragon.rs b/src/libcoretest/num/flt2dec/strategy/dragon.rs index 08c2cd0a7326f..4edb0f3df60c4 100644 --- a/src/libcoretest/num/flt2dec/strategy/dragon.rs +++ b/src/libcoretest/num/flt2dec/strategy/dragon.rs @@ -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); diff --git a/src/libcoretest/num/flt2dec/strategy/grisu.rs b/src/libcoretest/num/flt2dec/strategy/grisu.rs index 311bd252353c7..79e66ee669e14 100644 --- a/src/libcoretest/num/flt2dec/strategy/grisu.rs +++ b/src/libcoretest/num/flt2dec/strategy/grisu.rs @@ -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); diff --git a/src/libcoretest/ops.rs b/src/libcoretest/ops.rs index 33674a3abd870..1c6c13b0d02e8 100644 --- a/src/libcoretest/ops.rs +++ b/src/libcoretest/ops.rs @@ -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] From efeb42be2837842d1beb47b51bb693c7474aba3d Mon Sep 17 00:00:00 2001 From: Tobias Bucher Date: Sat, 4 Feb 2017 01:10:12 +0100 Subject: [PATCH 08/19] Use less syscalls in `FileDesc::set_{nonblocking,cloexec}` Only set the flags if they differ from what the OS reported, use `FIONBIO` to atomically set the non-blocking IO flag on Linux. --- src/libstd/sys/unix/fd.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/libstd/sys/unix/fd.rs b/src/libstd/sys/unix/fd.rs index dcab30aad8385..c690fd467ee41 100644 --- a/src/libstd/sys/unix/fd.rs +++ b/src/libstd/sys/unix/fd.rs @@ -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(()) } } From 3c161393b717c35702c164e5099cc6a34a5ddc80 Mon Sep 17 00:00:00 2001 From: est31 Date: Thu, 2 Feb 2017 22:32:20 +0100 Subject: [PATCH 09/19] Don't use "unadjusted" ABI on non windows platforms We introduced the unadjusted ABI to work around wrong (buggy) ABI expectations by LLVM on Windows [1]. Therefore, it should be solely used on Windows and not on other platforms, like right now is the case. [1]: see this comment for details https://github.com/rust-lang/rust/pull/38482#issuecomment-269074031 --- src/libcompiler_builtins/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libcompiler_builtins/lib.rs b/src/libcompiler_builtins/lib.rs index b2a615456aa59..4634301058b25 100644 --- a/src/libcompiler_builtins/lib.rs +++ b/src/libcompiler_builtins/lib.rs @@ -652,17 +652,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) } From 5a21f42cb7f193663fa7a3e95f27e4bf805b5be2 Mon Sep 17 00:00:00 2001 From: king6cong Date: Sat, 4 Feb 2017 10:21:26 +0800 Subject: [PATCH 10/19] run rustfmt for librustc/util/fs.rs --- src/librustc/util/fs.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/librustc/util/fs.rs b/src/librustc/util/fs.rs index 7f8a69de60723..3b4b3998c5745 100644 --- a/src/librustc/util/fs.rs +++ b/src/librustc/util/fs.rs @@ -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,7 @@ pub fn link_or_copy, Q: AsRef>(p: P, q: Q) -> io::Result
  • { match fs::copy(p, q) { Ok(_) => Ok(LinkOrCopy::Copy), - Err(e) => Err(e) + Err(e) => Err(e), } } } @@ -85,12 +85,15 @@ pub fn link_or_copy, Q: AsRef>(p: P, q: Q) -> io::Result
  • , Q: AsRef>(p: P, q: Q) -> io::Result { +/// If `rename` fails (rename may fail for reasons such as crossing +/// filesystem), fallback to copy & remove +pub fn rename_or_copy_remove, Q: AsRef>(p: P, + q: Q) + -> io::Result { let p = p.as_ref(); let q = q.as_ref(); match fs::rename(p, q) { @@ -100,8 +103,8 @@ pub fn rename_or_copy_remove, Q: AsRef>(p: P, q: Q) -> io:: Ok(_) => { fs::remove_file(p)?; Ok(RenameOrCopyRemove::CopyRemove) - }, - Err(e) => Err(e) + } + Err(e) => Err(e), } } } @@ -118,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(()), From 87ace0d7200c12ae268e895ad880cf9589d1b1ac Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Sat, 4 Feb 2017 04:53:09 +0200 Subject: [PATCH 11/19] More snap cleanup --- src/libcompiler_builtins/lib.rs | 6 ++---- src/librustc_const_eval/eval.rs | 9 +++------ src/librustc_const_math/int.rs | 6 ++---- src/librustc_trans/common.rs | 13 ++++--------- src/librustc_trans/mir/constant.rs | 4 ++-- src/test/run-pass/issue-38987.rs | 4 ---- 6 files changed, 13 insertions(+), 29 deletions(-) diff --git a/src/libcompiler_builtins/lib.rs b/src/libcompiler_builtins/lib.rs index b2a615456aa59..5ed497f6159b0 100644 --- a/src/libcompiler_builtins/lib.rs +++ b/src/libcompiler_builtins/lib.rs @@ -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 { diff --git a/src/librustc_const_eval/eval.rs b/src/librustc_const_eval/eval.rs index e2e76cdfb6ebd..af4f63a05613e 100644 --- a/src/librustc_const_eval/eval.rs +++ b/src/librustc_const_eval/eval.rs @@ -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)), _) => { diff --git a/src/librustc_const_math/int.rs b/src/librustc_const_math/int.rs index 3618bfa20811f..17714f2fb2d6c 100644 --- a/src/librustc_const_math/int.rs +++ b/src/librustc_const_math/int.rs @@ -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 }; diff --git a/src/librustc_trans/common.rs b/src/librustc_trans/common.rs index 01b2aeef004db..b995760f5b7a3 100644 --- a/src/librustc_trans/common.rs +++ b/src/librustc_trans/common.rs @@ -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::() == 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()) } } diff --git a/src/librustc_trans/mir/constant.rs b/src/librustc_trans/mir/constant.rs index 3d5e1694355b3..2a427da4d683e 100644 --- a/src/librustc_trans/mir/constant.rs +++ b/src/librustc_trans/mir/constant.rs @@ -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) diff --git a/src/test/run-pass/issue-38987.rs b/src/test/run-pass/issue-38987.rs index 29e96c162b8de..a513476d4a33a 100644 --- a/src/test/run-pass/issue-38987.rs +++ b/src/test/run-pass/issue-38987.rs @@ -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; } From 206ee202581688818e1b305f2c0376df12e65b72 Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Sat, 4 Feb 2017 06:12:23 +0200 Subject: [PATCH 12/19] Unignore stage0/1 i128 tests as well --- src/test/run-pass/i128-ffi.rs | 3 --- src/test/run-pass/i128.rs | 3 --- 2 files changed, 6 deletions(-) diff --git a/src/test/run-pass/i128-ffi.rs b/src/test/run-pass/i128-ffi.rs index 222f32754fb6b..473f1cc2301dc 100644 --- a/src/test/run-pass/i128-ffi.rs +++ b/src/test/run-pass/i128-ffi.rs @@ -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. diff --git a/src/test/run-pass/i128.rs b/src/test/run-pass/i128.rs index 3eb1c95050267..dc4f0774b9771 100644 --- a/src/test/run-pass/i128.rs +++ b/src/test/run-pass/i128.rs @@ -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)] From 768c6c081e4a8cac6b6f8eee5cde72ed13a7e87a Mon Sep 17 00:00:00 2001 From: Dylan McKay Date: Sat, 4 Feb 2017 23:22:05 +1300 Subject: [PATCH 13/19] Support a debug info API change for LLVM 4.0 Instead of directly creating a 'DIGlobalVariable', we now have to create a 'DIGlobalVariableExpression' which itself contains a reference to a 'DIGlobalVariable'. This is a straightforward change. In the future, we should rename 'DIGlobalVariable' in the FFI bindings, assuming we will only refer to 'DIGlobalVariableExpression' and not 'DIGlobalVariable'. --- src/librustc_llvm/ffi.rs | 6 ++++++ src/rustllvm/RustWrapper.cpp | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/src/librustc_llvm/ffi.rs b/src/librustc_llvm/ffi.rs index 58b2017ceb66e..8510b9f523cb5 100644 --- a/src/librustc_llvm/ffi.rs +++ b/src/librustc_llvm/ffi.rs @@ -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, diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp index 34ee7d552f346..c7bcd2558186e 100644 --- a/src/rustllvm/RustWrapper.cpp +++ b/src/rustllvm/RustWrapper.cpp @@ -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(Context), Name, LinkageName, unwrapDI(File), LineNo, unwrapDI(Ty), IsLocalToUnit, #if LLVM_VERSION_GE(4, 0) From 112a5a00e839bfb3dbdaa9166afe595163248174 Mon Sep 17 00:00:00 2001 From: Tim Neumann Date: Sat, 4 Feb 2017 11:44:29 +0100 Subject: [PATCH 14/19] ignore more gdb versions with buggy rust support --- src/test/debuginfo/borrowed-enum.rs | 2 +- src/test/debuginfo/generic-struct-style-enum.rs | 2 +- src/test/debuginfo/generic-tuple-style-enum.rs | 2 +- src/test/debuginfo/packed-struct.rs | 2 +- src/test/debuginfo/recursive-struct.rs | 2 +- src/test/debuginfo/struct-in-enum.rs | 2 +- src/test/debuginfo/struct-style-enum.rs | 2 +- src/test/debuginfo/tuple-style-enum.rs | 2 +- src/test/debuginfo/union-smoke.rs | 2 +- src/test/debuginfo/unique-enum.rs | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/test/debuginfo/borrowed-enum.rs b/src/test/debuginfo/borrowed-enum.rs index c457fed7ecd52..9e63beff3cb2e 100644 --- a/src/test/debuginfo/borrowed-enum.rs +++ b/src/test/debuginfo/borrowed-enum.rs @@ -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 diff --git a/src/test/debuginfo/generic-struct-style-enum.rs b/src/test/debuginfo/generic-struct-style-enum.rs index df56ccccca3f5..4a1d14ccf6118 100644 --- a/src/test/debuginfo/generic-struct-style-enum.rs +++ b/src/test/debuginfo/generic-struct-style-enum.rs @@ -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 diff --git a/src/test/debuginfo/generic-tuple-style-enum.rs b/src/test/debuginfo/generic-tuple-style-enum.rs index e538700f0f84c..012bd6140cdbe 100644 --- a/src/test/debuginfo/generic-tuple-style-enum.rs +++ b/src/test/debuginfo/generic-tuple-style-enum.rs @@ -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 diff --git a/src/test/debuginfo/packed-struct.rs b/src/test/debuginfo/packed-struct.rs index c476e9fe0796f..16e6371a9c0a9 100644 --- a/src/test/debuginfo/packed-struct.rs +++ b/src/test/debuginfo/packed-struct.rs @@ -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 diff --git a/src/test/debuginfo/recursive-struct.rs b/src/test/debuginfo/recursive-struct.rs index f33dfac07d203..75c2feb480ede 100644 --- a/src/test/debuginfo/recursive-struct.rs +++ b/src/test/debuginfo/recursive-struct.rs @@ -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 diff --git a/src/test/debuginfo/struct-in-enum.rs b/src/test/debuginfo/struct-in-enum.rs index d9763aedd7c15..bd044188dbcbc 100644 --- a/src/test/debuginfo/struct-in-enum.rs +++ b/src/test/debuginfo/struct-in-enum.rs @@ -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 diff --git a/src/test/debuginfo/struct-style-enum.rs b/src/test/debuginfo/struct-style-enum.rs index 6212caa69538d..b156a3be699e3 100644 --- a/src/test/debuginfo/struct-style-enum.rs +++ b/src/test/debuginfo/struct-style-enum.rs @@ -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 diff --git a/src/test/debuginfo/tuple-style-enum.rs b/src/test/debuginfo/tuple-style-enum.rs index f85cd6a50f519..f36153d1f5c5a 100644 --- a/src/test/debuginfo/tuple-style-enum.rs +++ b/src/test/debuginfo/tuple-style-enum.rs @@ -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 diff --git a/src/test/debuginfo/union-smoke.rs b/src/test/debuginfo/union-smoke.rs index 844e9405ba55c..0b2544151fd32 100644 --- a/src/test/debuginfo/union-smoke.rs +++ b/src/test/debuginfo/union-smoke.rs @@ -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 diff --git a/src/test/debuginfo/unique-enum.rs b/src/test/debuginfo/unique-enum.rs index e8eb4315007af..5a99de7779cff 100644 --- a/src/test/debuginfo/unique-enum.rs +++ b/src/test/debuginfo/unique-enum.rs @@ -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 From a884a6c60d3ec2338d7dfed9998a7aa96e10260e Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Sat, 4 Feb 2017 16:26:01 +0100 Subject: [PATCH 15/19] Slightly optimize slice::sort First, get rid of some bound checks. Second, instead of comparing by ternary `compare` function, use a binary function testing whether an element is less than some other element. This apparently makes it easier for the compiler to reason about the code. Benchmark: ``` name before ns/iter after ns/iter diff ns/iter diff % slice::bench::sort_large_ascending 8,969 (8919 MB/s) 7,410 (10796 MB/s) -1,559 -17.38% slice::bench::sort_large_big_ascending 355,640 (3599 MB/s) 359,137 (3564 MB/s) 3,497 0.98% slice::bench::sort_large_big_descending 427,112 (2996 MB/s) 424,721 (3013 MB/s) -2,391 -0.56% slice::bench::sort_large_big_random 2,207,799 (579 MB/s) 2,138,804 (598 MB/s) -68,995 -3.13% slice::bench::sort_large_descending 13,694 (5841 MB/s) 13,514 (5919 MB/s) -180 -1.31% slice::bench::sort_large_mostly_ascending 239,697 (333 MB/s) 203,542 (393 MB/s) -36,155 -15.08% slice::bench::sort_large_mostly_descending 270,102 (296 MB/s) 234,263 (341 MB/s) -35,839 -13.27% slice::bench::sort_large_random 513,406 (155 MB/s) 470,084 (170 MB/s) -43,322 -8.44% slice::bench::sort_large_random_expensive 23,650,321 (3 MB/s) 23,675,098 (3 MB/s) 24,777 0.10% slice::bench::sort_medium_ascending 143 (5594 MB/s) 132 (6060 MB/s) -11 -7.69% slice::bench::sort_medium_descending 197 (4060 MB/s) 188 (4255 MB/s) -9 -4.57% slice::bench::sort_medium_random 3,358 (238 MB/s) 3,271 (244 MB/s) -87 -2.59% slice::bench::sort_small_ascending 32 (2500 MB/s) 32 (2500 MB/s) 0 0.00% slice::bench::sort_small_big_ascending 97 (13195 MB/s) 97 (13195 MB/s) 0 0.00% slice::bench::sort_small_big_descending 247 (5182 MB/s) 249 (5140 MB/s) 2 0.81% slice::bench::sort_small_big_random 502 (2549 MB/s) 498 (2570 MB/s) -4 -0.80% slice::bench::sort_small_descending 55 (1454 MB/s) 61 (1311 MB/s) 6 10.91% slice::bench::sort_small_random 358 (223 MB/s) 356 (224 MB/s) -2 -0.56% ``` --- src/libcollections/slice.rs | 68 ++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 11f513ed798e0..2ea953df87357 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -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] { 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] { pub fn sort_by_key(&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] { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn sort_by(&mut self, compare: F) + pub fn sort_by(&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 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(v: &mut [T], compare: &mut F) - where F: FnMut(&T, &T) -> Ordering +fn insert_head(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(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(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(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(v: &mut [T], mid: usize, buf: *mut T, compare: &mut F) - where F: FnMut(&T, &T) -> Ordering +unsafe fn merge(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(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(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(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(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(v: &mut [T], mut compare: F) - where F: FnMut(&T, &T) -> Ordering +fn merge_sort(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::() == 0 { @@ -1565,7 +1565,7 @@ fn merge_sort(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::() <= 16 { + let (max_insertion, min_run) = if size_of::() <= 2 * mem::size_of::() { (64, 32) } else { (32, 16) @@ -1577,7 +1577,7 @@ fn merge_sort(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(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(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(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(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, From fa457bff264ea62acf56bb9e645b8227ecdc7529 Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Sat, 4 Feb 2017 18:04:26 +0100 Subject: [PATCH 16/19] Minor fix in the *_expensive benchmark Before, the `count` would be copied into the closure and could potentially be optimized way. This change ensures it's borrowed by closure and finally consumed by `test::black_box`. --- src/libcollectionstest/slice.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/libcollectionstest/slice.rs b/src/libcollectionstest/slice.rs index 1b52214dee6ae..b9dec6be7b885 100644 --- a/src/libcollectionstest/slice.rs +++ b/src/libcollectionstest/slice.rs @@ -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::() as u64; From fc88683fba6bcd7102bc15639939525bb382d422 Mon Sep 17 00:00:00 2001 From: "Zack M. Davis" Date: Sat, 4 Feb 2017 23:30:26 -0800 Subject: [PATCH 17/19] prefer issue-${no}.rs to bug-${no}.rs test file names Thanks to @nagisa for pointing these out (https://github.com/rust-lang/rust/pull/38473#issuecomment-268076606). --- ...unds-check-overflow.rs => issue-2470-bounds-check-overflow.rs} | 0 src/test/run-fail/{bug-811.rs => issue-811.rs} | 0 .../run-pass/{bug-7183-generics.rs => issue-7183-generics.rs} | 0 src/test/run-pass/{bug-7295.rs => issue-7295.rs} | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename src/test/run-fail/{bug-2470-bounds-check-overflow.rs => issue-2470-bounds-check-overflow.rs} (100%) rename src/test/run-fail/{bug-811.rs => issue-811.rs} (100%) rename src/test/run-pass/{bug-7183-generics.rs => issue-7183-generics.rs} (100%) rename src/test/run-pass/{bug-7295.rs => issue-7295.rs} (100%) diff --git a/src/test/run-fail/bug-2470-bounds-check-overflow.rs b/src/test/run-fail/issue-2470-bounds-check-overflow.rs similarity index 100% rename from src/test/run-fail/bug-2470-bounds-check-overflow.rs rename to src/test/run-fail/issue-2470-bounds-check-overflow.rs diff --git a/src/test/run-fail/bug-811.rs b/src/test/run-fail/issue-811.rs similarity index 100% rename from src/test/run-fail/bug-811.rs rename to src/test/run-fail/issue-811.rs diff --git a/src/test/run-pass/bug-7183-generics.rs b/src/test/run-pass/issue-7183-generics.rs similarity index 100% rename from src/test/run-pass/bug-7183-generics.rs rename to src/test/run-pass/issue-7183-generics.rs diff --git a/src/test/run-pass/bug-7295.rs b/src/test/run-pass/issue-7295.rs similarity index 100% rename from src/test/run-pass/bug-7295.rs rename to src/test/run-pass/issue-7295.rs From de8df0141f57c82026e520694e9dfea1a9fbb5fd Mon Sep 17 00:00:00 2001 From: "Zack M. Davis" Date: Sat, 4 Feb 2017 23:52:43 -0800 Subject: [PATCH 18/19] continue to prefer hyphens in test files named after issue numbers --- .../{issue28498-must-work-ex1.rs => issue-28498-must-work-ex1.rs} | 0 .../{issue28498-must-work-ex2.rs => issue-28498-must-work-ex2.rs} | 0 .../run-pass/{issue28498-ugeh-ex1.rs => issue-28498-ugeh-ex1.rs} | 0 ...-lifetime-param.rs => issue-28498-ugeh-with-lifetime-param.rs} | 0 ...with-passed-to-fn.rs => issue-28498-ugeh-with-passed-to-fn.rs} | 0 ...h-with-trait-bound.rs => issue-28498-ugeh-with-trait-bound.rs} | 0 src/test/run-pass/{issue29927-1.rs => issue29927.rs} | 0 .../span/{issue28498-reject-ex1.rs => issue-28498-reject-ex1.rs} | 0 ...ect-lifetime-param.rs => issue-28498-reject-lifetime-param.rs} | 0 ...-reject-passed-to-fn.rs => issue-28498-reject-passed-to-fn.rs} | 0 ...98-reject-trait-bound.rs => issue-28498-reject-trait-bound.rs} | 0 11 files changed, 0 insertions(+), 0 deletions(-) rename src/test/run-pass/{issue28498-must-work-ex1.rs => issue-28498-must-work-ex1.rs} (100%) rename src/test/run-pass/{issue28498-must-work-ex2.rs => issue-28498-must-work-ex2.rs} (100%) rename src/test/run-pass/{issue28498-ugeh-ex1.rs => issue-28498-ugeh-ex1.rs} (100%) rename src/test/run-pass/{issue28498-ugeh-with-lifetime-param.rs => issue-28498-ugeh-with-lifetime-param.rs} (100%) rename src/test/run-pass/{issue28498-ugeh-with-passed-to-fn.rs => issue-28498-ugeh-with-passed-to-fn.rs} (100%) rename src/test/run-pass/{issue28498-ugeh-with-trait-bound.rs => issue-28498-ugeh-with-trait-bound.rs} (100%) rename src/test/run-pass/{issue29927-1.rs => issue29927.rs} (100%) rename src/test/ui/span/{issue28498-reject-ex1.rs => issue-28498-reject-ex1.rs} (100%) rename src/test/ui/span/{issue28498-reject-lifetime-param.rs => issue-28498-reject-lifetime-param.rs} (100%) rename src/test/ui/span/{issue28498-reject-passed-to-fn.rs => issue-28498-reject-passed-to-fn.rs} (100%) rename src/test/ui/span/{issue28498-reject-trait-bound.rs => issue-28498-reject-trait-bound.rs} (100%) diff --git a/src/test/run-pass/issue28498-must-work-ex1.rs b/src/test/run-pass/issue-28498-must-work-ex1.rs similarity index 100% rename from src/test/run-pass/issue28498-must-work-ex1.rs rename to src/test/run-pass/issue-28498-must-work-ex1.rs diff --git a/src/test/run-pass/issue28498-must-work-ex2.rs b/src/test/run-pass/issue-28498-must-work-ex2.rs similarity index 100% rename from src/test/run-pass/issue28498-must-work-ex2.rs rename to src/test/run-pass/issue-28498-must-work-ex2.rs diff --git a/src/test/run-pass/issue28498-ugeh-ex1.rs b/src/test/run-pass/issue-28498-ugeh-ex1.rs similarity index 100% rename from src/test/run-pass/issue28498-ugeh-ex1.rs rename to src/test/run-pass/issue-28498-ugeh-ex1.rs diff --git a/src/test/run-pass/issue28498-ugeh-with-lifetime-param.rs b/src/test/run-pass/issue-28498-ugeh-with-lifetime-param.rs similarity index 100% rename from src/test/run-pass/issue28498-ugeh-with-lifetime-param.rs rename to src/test/run-pass/issue-28498-ugeh-with-lifetime-param.rs diff --git a/src/test/run-pass/issue28498-ugeh-with-passed-to-fn.rs b/src/test/run-pass/issue-28498-ugeh-with-passed-to-fn.rs similarity index 100% rename from src/test/run-pass/issue28498-ugeh-with-passed-to-fn.rs rename to src/test/run-pass/issue-28498-ugeh-with-passed-to-fn.rs diff --git a/src/test/run-pass/issue28498-ugeh-with-trait-bound.rs b/src/test/run-pass/issue-28498-ugeh-with-trait-bound.rs similarity index 100% rename from src/test/run-pass/issue28498-ugeh-with-trait-bound.rs rename to src/test/run-pass/issue-28498-ugeh-with-trait-bound.rs diff --git a/src/test/run-pass/issue29927-1.rs b/src/test/run-pass/issue29927.rs similarity index 100% rename from src/test/run-pass/issue29927-1.rs rename to src/test/run-pass/issue29927.rs diff --git a/src/test/ui/span/issue28498-reject-ex1.rs b/src/test/ui/span/issue-28498-reject-ex1.rs similarity index 100% rename from src/test/ui/span/issue28498-reject-ex1.rs rename to src/test/ui/span/issue-28498-reject-ex1.rs diff --git a/src/test/ui/span/issue28498-reject-lifetime-param.rs b/src/test/ui/span/issue-28498-reject-lifetime-param.rs similarity index 100% rename from src/test/ui/span/issue28498-reject-lifetime-param.rs rename to src/test/ui/span/issue-28498-reject-lifetime-param.rs diff --git a/src/test/ui/span/issue28498-reject-passed-to-fn.rs b/src/test/ui/span/issue-28498-reject-passed-to-fn.rs similarity index 100% rename from src/test/ui/span/issue28498-reject-passed-to-fn.rs rename to src/test/ui/span/issue-28498-reject-passed-to-fn.rs diff --git a/src/test/ui/span/issue28498-reject-trait-bound.rs b/src/test/ui/span/issue-28498-reject-trait-bound.rs similarity index 100% rename from src/test/ui/span/issue28498-reject-trait-bound.rs rename to src/test/ui/span/issue-28498-reject-trait-bound.rs From 1c26f8ce4fde3719f9218ecf8a517110d6c74455 Mon Sep 17 00:00:00 2001 From: "Zack M. Davis" Date: Sun, 5 Feb 2017 00:01:23 -0800 Subject: [PATCH 19/19] unify both existing test files for issue #32829 issue-32829.rs was introduced in f6a243d2 (2 June 2016), but issue32829.rs was introduced in 94a05526 (9 May 2016). Weird! Let's combine them for the best of both worlds. --- src/test/compile-fail/issue-32829.rs | 80 ++++++++++++++++++++++++- src/test/compile-fail/issue32829.rs | 88 ---------------------------- 2 files changed, 78 insertions(+), 90 deletions(-) delete mode 100644 src/test/compile-fail/issue32829.rs diff --git a/src/test/compile-fail/issue-32829.rs b/src/test/compile-fail/issue-32829.rs index 9ac70882ca28c..e889c34700cf8 100644 --- a/src/test/compile-fail/issue-32829.rs +++ b/src/test/compile-fail/issue-32829.rs @@ -8,9 +8,85 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern: calls in statics are limited +#![feature(const_fn)] -static S : u64 = { { panic!("foo"); 0 } }; +const bad: u32 = { + { + 5; //~ ERROR: blocks in constants are limited to items and tail expressions + 0 + } +}; + +const bad_two: u32 = { + { + invalid(); + //~^ ERROR: blocks in constants are limited to items and tail expressions + //~^^ ERROR: calls in constants are limited to constant functions, struct and enum + 0 + } +}; + +const bad_three: u32 = { + { + valid(); + //~^ ERROR: blocks in constants are limited to items and tail expressions + 0 + } +}; + +static bad_four: u32 = { + { + 5; //~ ERROR: blocks in statics are limited to items and tail expressions + 0 + } +}; + +static bad_five: u32 = { + { + invalid(); + //~^ ERROR: blocks in statics are limited to items and tail expressions + //~^^ ERROR: calls in statics are limited to constant functions, struct and enum + 0 + } +}; + +static bad_six: u32 = { + { + valid(); + //~^ ERROR: blocks in statics are limited to items and tail expressions + 0 + } +}; + +static mut bad_seven: u32 = { + { + 5; //~ ERROR: blocks in statics are limited to items and tail expressions + 0 + } +}; + +static mut bad_eight: u32 = { + { + invalid(); + //~^ ERROR: blocks in statics are limited to items and tail expressions + //~^^ ERROR: calls in statics are limited to constant functions, struct and enum + 0 + } +}; + +static mut bad_nine: u32 = { + { + valid(); + //~^ ERROR: blocks in statics are limited to items and tail expressions + 0 + } +}; + +fn invalid() {} +const fn valid() {} + +static S: u64 = { { panic!("foo"); 0 } }; +//~^ ERROR: calls in statics are limited fn main() { println!("{:?}", S); diff --git a/src/test/compile-fail/issue32829.rs b/src/test/compile-fail/issue32829.rs deleted file mode 100644 index e0b847fc99470..0000000000000 --- a/src/test/compile-fail/issue32829.rs +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright 2016 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. -#![feature(const_fn)] - -const bad : u32 = { - { - 5; //~ ERROR: blocks in constants are limited to items and tail expressions - 0 - } -}; - -const bad_two : u32 = { - { - invalid(); - //~^ ERROR: blocks in constants are limited to items and tail expressions - //~^^ ERROR: calls in constants are limited to constant functions, struct and enum - 0 - } -}; - -const bad_three : u32 = { - { - valid(); - //~^ ERROR: blocks in constants are limited to items and tail expressions - 0 - } -}; - -static bad_four : u32 = { - { - 5; //~ ERROR: blocks in statics are limited to items and tail expressions - 0 - } -}; - -static bad_five : u32 = { - { - invalid(); - //~^ ERROR: blocks in statics are limited to items and tail expressions - //~^^ ERROR: calls in statics are limited to constant functions, struct and enum - 0 - } -}; - -static bad_six : u32 = { - { - valid(); - //~^ ERROR: blocks in statics are limited to items and tail expressions - 0 - } -}; - -static mut bad_seven : u32 = { - { - 5; //~ ERROR: blocks in statics are limited to items and tail expressions - 0 - } -}; - -static mut bad_eight : u32 = { - { - invalid(); - //~^ ERROR: blocks in statics are limited to items and tail expressions - //~^^ ERROR: calls in statics are limited to constant functions, struct and enum - 0 - } -}; - -static mut bad_nine : u32 = { - { - valid(); - //~^ ERROR: blocks in statics are limited to items and tail expressions - 0 - } -}; - - -fn invalid() {} -const fn valid() {} - -fn main() {}