From cf55ba1d20af34bf7bde10cb199f429aa06a9568 Mon Sep 17 00:00:00 2001 From: Gabriel Majeri Date: Fri, 27 Sep 2019 15:52:25 +0300 Subject: [PATCH 1/7] Fix Clippy for main crate --- src/api/minimal/ptr.rs | 2 +- src/lib.rs | 3 ++- src/masks.rs | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/api/minimal/ptr.rs b/src/api/minimal/ptr.rs index 75e5aad5c..e8424209b 100644 --- a/src/api/minimal/ptr.rs +++ b/src/api/minimal/ptr.rs @@ -215,7 +215,7 @@ macro_rules! impl_minimal_p { f, "{}<{}>(", stringify!($id), - unsafe { crate::intrinsics::type_name::() } + crate::intrinsics::type_name::() )?; for i in 0..$elem_count { if i > 0 { diff --git a/src/lib.rs b/src/lib.rs index c3da0d3c0..d2812e18a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -220,7 +220,8 @@ clippy::cast_precision_loss, // This lint is currently broken for generic code // See https://github.com/rust-lang/rust-clippy/issues/3410 - clippy::use_self + clippy::use_self, + clippy::wrong_self_convention )] #![cfg_attr(test, feature(hashmap_internals))] #![deny(rust_2018_idioms, clippy::missing_inline_in_public_items)] diff --git a/src/masks.rs b/src/masks.rs index f0cdbf92a..aeb36d232 100644 --- a/src/masks.rs +++ b/src/masks.rs @@ -8,6 +8,7 @@ macro_rules! impl_mask_ty { impl crate::sealed::Seal for $id {} impl crate::sealed::Mask for $id { + #[inline] fn test(&self) -> bool { $id::test(self) } From b9634b6f7dabc43e82d9d142b86fa0a2f2c7459d Mon Sep 17 00:00:00 2001 From: Gabriel Majeri Date: Fri, 27 Sep 2019 15:52:35 +0300 Subject: [PATCH 2/7] Fix Clippy lints for examples --- examples/aobench/src/image.rs | 4 ++-- examples/aobench/src/random.rs | 4 ++-- examples/slice_sum/src/main.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/aobench/src/image.rs b/examples/aobench/src/image.rs index a13db7706..e1b43b2fc 100644 --- a/examples/aobench/src/image.rs +++ b/examples/aobench/src/image.rs @@ -48,7 +48,6 @@ impl Image { i as u8 } - use png::HasParameters; use std::fs::File; use std::io::BufWriter; @@ -60,7 +59,8 @@ impl Image { self.height as u32, ); - encoder.set(png::ColorType::RGB).set(png::BitDepth::Eight); + encoder.set_color(png::ColorType::RGB); + encoder.set_depth(png::BitDepth::Eight); let mut writer = encoder.write_header().unwrap(); if soa { diff --git a/examples/aobench/src/random.rs b/examples/aobench/src/random.rs index c4f448e6f..b6fef0e20 100644 --- a/examples/aobench/src/random.rs +++ b/examples/aobench/src/random.rs @@ -67,7 +67,7 @@ pub mod scalar { pub fn thread_rng() -> RngH { RngH { - rng: THREAD_RNG_KEY.with(|t| t.clone()), + rng: THREAD_RNG_KEY.with(Clone::clone), } } } @@ -134,7 +134,7 @@ pub mod vector { pub fn thread_rng() -> RngH { RngH { - rng: THREAD_RNG_KEY.with(|t| t.clone()), + rng: THREAD_RNG_KEY.with(Clone::clone), } } } diff --git a/examples/slice_sum/src/main.rs b/examples/slice_sum/src/main.rs index 2b874ac84..18b3692aa 100644 --- a/examples/slice_sum/src/main.rs +++ b/examples/slice_sum/src/main.rs @@ -23,7 +23,7 @@ fn sum_hor(x: &[f32]) -> f32 { x.chunks_exact(f32s::lanes()) .map(f32s::from_slice_unaligned) - .map(|vec| vec.sum()) + .map(f32s::sum) .sum() } From e3335262d882df7cdf06841e712fb7b9ebfa74e8 Mon Sep 17 00:00:00 2001 From: Gabriel Majeri Date: Tue, 29 Oct 2019 19:28:53 +0200 Subject: [PATCH 3/7] Update dependencies # Conflicts: # Cargo.toml --- Cargo.toml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7352ff7a3..a103154ce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,9 +21,9 @@ is-it-maintained-open-issues = { repository = "rust-lang-nursery/packed_simd" } maintenance = { status = "experimental" } [dependencies] -cfg-if = "^0.1.6" -core_arch = { version = "^0.1.4", optional = true } -libm = "0.1.2" +cfg-if = "0.1.10" +core_arch = { version = "0.1.5", optional = true } +libm = "0.1.4" [features] default = [] @@ -35,7 +35,7 @@ paste = "^0.1.3" arrayvec = { version = "^0.5", default-features = false } [target.'cfg(target_arch = "x86_64")'.dependencies.sleef-sys] -version = "^0.1.2" +version = "0.1.2" optional = true [target.wasm32-unknown-unknown.dev-dependencies] From d17a6a81db644ac5be475d1147a3f0af45519153 Mon Sep 17 00:00:00 2001 From: Gabriel Majeri Date: Wed, 30 Oct 2019 20:50:43 +0200 Subject: [PATCH 4/7] Update core_arch to latest git version --- Cargo.toml | 2 +- examples/mandelbrot/Cargo.toml | 2 +- examples/mandelbrot/src/main.rs | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a103154ce..b51e01697 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ maintenance = { status = "experimental" } [dependencies] cfg-if = "0.1.10" -core_arch = { version = "0.1.5", optional = true } +core_arch = { git = "https://github.com/rust-lang/stdarch", optional = true } libm = "0.1.4" [features] diff --git a/examples/mandelbrot/Cargo.toml b/examples/mandelbrot/Cargo.toml index a56ad36aa..a6432ca08 100644 --- a/examples/mandelbrot/Cargo.toml +++ b/examples/mandelbrot/Cargo.toml @@ -9,7 +9,7 @@ edition = "2018" packed_simd = { path = "../.." } rayon = "^1.0" ispc = { version = "^1.0.4", optional = true } -structopt = "0.3.0" +structopt = { version = "0.3.0", features = ["color"] } [build-dependencies] ispc = { version = "^1.0.4", optional = true } diff --git a/examples/mandelbrot/src/main.rs b/examples/mandelbrot/src/main.rs index 932e4f55e..6f82f05ac 100644 --- a/examples/mandelbrot/src/main.rs +++ b/examples/mandelbrot/src/main.rs @@ -12,7 +12,6 @@ use structopt::StructOpt; /// /// Output is printed to `stdout`. #[derive(StructOpt)] -#[structopt(raw(setting = "structopt::clap::AppSettings::ColoredHelp"))] struct Opt { /// Image width. width: usize, From 59f4df121e4fa0671c489c4d36b38c903a958e3b Mon Sep 17 00:00:00 2001 From: Gabriel Majeri Date: Wed, 30 Oct 2019 21:13:27 +0200 Subject: [PATCH 5/7] Fix benchmarks in CI --- examples/aobench/benchmark.sh | 4 ++-- examples/mandelbrot/benchmark.sh | 6 +++--- examples/options_pricing/benchmark.sh | 4 ++-- examples/stencil/benchmark.sh | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/aobench/benchmark.sh b/examples/aobench/benchmark.sh index df207048b..cbf9a3fcd 100755 --- a/examples/aobench/benchmark.sh +++ b/examples/aobench/benchmark.sh @@ -34,7 +34,7 @@ fi for alg in "${ALGS[@]}" do - hyperfine "target/release/aobench ${WIDTH} ${HEIGHT} --algo ${alg}" + hyperfine "../target/release/aobench ${WIDTH} ${HEIGHT} --algo ${alg}" done echo "Benchmark 128-bit wide vectors" @@ -43,5 +43,5 @@ RUSTFLAGS="-C target-cpu=native ${RUSTFLAGS}" \ --features="${FEATURES}" for alg in "${ALGS[@]}" do - hyperfine "target/release/aobench ${WIDTH} ${HEIGHT} --algo ${alg}" + hyperfine "../target/release/aobench ${WIDTH} ${HEIGHT} --algo ${alg}" done diff --git a/examples/mandelbrot/benchmark.sh b/examples/mandelbrot/benchmark.sh index 0590eae9a..7ba25a185 100755 --- a/examples/mandelbrot/benchmark.sh +++ b/examples/mandelbrot/benchmark.sh @@ -27,9 +27,9 @@ if [[ "${NORUN}" == "1" ]]; then exit 0 fi -hyperfine "target/release/mandelbrot ${WIDTH} ${HEIGHT} --algo scalar" -hyperfine "target/release/mandelbrot ${WIDTH} ${HEIGHT} --algo simd" +hyperfine "../target/release/mandelbrot ${WIDTH} ${HEIGHT} --algo scalar" +hyperfine "../target/release/mandelbrot ${WIDTH} ${HEIGHT} --algo simd" if echo "$FEATURES" | grep -q "ispc"; then - hyperfine "target/release/mandelbrot ${WIDTH} ${HEIGHT} --algo ispc" + hyperfine "../target/release/mandelbrot ${WIDTH} ${HEIGHT} --algo ispc" fi diff --git a/examples/options_pricing/benchmark.sh b/examples/options_pricing/benchmark.sh index f5a1dc660..597246a20 100755 --- a/examples/options_pricing/benchmark.sh +++ b/examples/options_pricing/benchmark.sh @@ -27,7 +27,7 @@ fi #for alg in "${ALGS[@]}" #do -# hyperfine "target/release/options_pricing ${NUM_OPTIONS_BLACK_SCHOLES} ${alg}" +# hyperfine "../target/release/options_pricing ${NUM_OPTIONS_BLACK_SCHOLES} ${alg}" #done # Binomial put: @@ -40,5 +40,5 @@ NUM_OPTIONS_BINOMIAL_PUT=500000 for alg in "${ALGS[@]}" do - hyperfine "target/release/options_pricing ${NUM_OPTIONS_BINOMIAL_PUT} ${alg}" + hyperfine "../target/release/options_pricing ${NUM_OPTIONS_BINOMIAL_PUT} ${alg}" done diff --git a/examples/stencil/benchmark.sh b/examples/stencil/benchmark.sh index 562b7b767..746ef4081 100755 --- a/examples/stencil/benchmark.sh +++ b/examples/stencil/benchmark.sh @@ -30,5 +30,5 @@ fi for alg in "${algs[@]}" do - hyperfine "target/release/stencil ${alg}" + hyperfine "../target/release/stencil ${alg}" done From 36d9e8de65f7d6bdef36677c0bb3c69027395fdf Mon Sep 17 00:00:00 2001 From: Gabriel Majeri Date: Fri, 22 Nov 2019 23:02:34 +0200 Subject: [PATCH 6/7] Fix more Clippy lints --- examples/aobench/src/intersection/ray_plane.rs | 6 +++--- examples/aobench/src/intersection/ray_sphere.rs | 6 +++--- examples/aobench/src/lib.rs | 3 ++- examples/dot_product/src/lib.rs | 1 + examples/fannkuch_redux/src/lib.rs | 3 ++- examples/mandelbrot/src/lib.rs | 3 ++- examples/mandelbrot/src/simd_par.rs | 5 +++-- examples/matrix_inverse/src/lib.rs | 1 + examples/nbody/src/lib.rs | 6 +++++- examples/options_pricing/src/lib.rs | 1 + examples/spectral_norm/src/lib.rs | 5 ++++- examples/stencil/src/lib.rs | 3 ++- examples/triangle_xform/src/lib.rs | 2 ++ src/api/minimal/ptr.rs | 14 +++++++------- src/lib.rs | 2 ++ 15 files changed, 40 insertions(+), 21 deletions(-) diff --git a/examples/aobench/src/intersection/ray_plane.rs b/examples/aobench/src/intersection/ray_plane.rs index 2394bf0c3..5751c29e1 100644 --- a/examples/aobench/src/intersection/ray_plane.rs +++ b/examples/aobench/src/intersection/ray_plane.rs @@ -53,7 +53,8 @@ impl Intersect for RayxN { } } - debug_assert!({ + #[cfg(debug_assertions)] + { // Check that the vector and the scalar version produce the same results // for the same inputs in debug builds for i in 0..f32xN::lanes() { @@ -62,8 +63,7 @@ impl Intersect for RayxN { let isect_i = ray_i.intersect(plane, old_isect_i); assert!(isect_i.almost_eq(&isect.get(i)), "{:?} !~= {:?}\n\nplane: {:?}\n\nold_isect: {:?}\n\nrays: {:?}\n\ni: {:?}\nold_isect_i: {:?}\nray_i: {:?}\n\n", isect_i, isect.get(i), plane, old_isect, self, i, old_isect_i, ray_i); } - true - }); + } isect } diff --git a/examples/aobench/src/intersection/ray_sphere.rs b/examples/aobench/src/intersection/ray_sphere.rs index 5a15710b8..205f81c01 100644 --- a/examples/aobench/src/intersection/ray_sphere.rs +++ b/examples/aobench/src/intersection/ray_sphere.rs @@ -59,7 +59,8 @@ impl Intersect for RayxN { } } - debug_assert!({ + #[cfg(debug_assertions)] + { // Check that the vector and the scalar version produce the same results // for the same inputs in debug builds for i in 0..f32xN::lanes() { @@ -68,8 +69,7 @@ impl Intersect for RayxN { let isect_i = ray_i.intersect(sphere, old_isect_i); assert!(isect_i.almost_eq(&isect.get(i)), "{:?} !~= {:?}\n\nsphere: {:?}\n\nold_isect: {:?}\n\nrays: {:?}\n\ni: {:?}\nold_isect_i: {:?}\nray_i: {:?}\n\n", isect_i, isect.get(i), sphere, old_isect, self, i, old_isect_i, ray_i); } - true - }); + } isect } diff --git a/examples/aobench/src/lib.rs b/examples/aobench/src/lib.rs index b45c0390e..7c7993107 100644 --- a/examples/aobench/src/lib.rs +++ b/examples/aobench/src/lib.rs @@ -12,7 +12,8 @@ clippy::cast_possible_truncation, clippy::cast_sign_loss, clippy::identity_op, - clippy::erasing_op + clippy::erasing_op, + clippy::must_use_candidate )] pub mod ambient_occlusion; diff --git a/examples/dot_product/src/lib.rs b/examples/dot_product/src/lib.rs index e6da98adf..fae2ec3bd 100644 --- a/examples/dot_product/src/lib.rs +++ b/examples/dot_product/src/lib.rs @@ -1,6 +1,7 @@ //! Vector dot product #![deny(warnings, rust_2018_idioms)] #![feature(custom_inner_attributes)] +#![allow(clippy::must_use_candidate)] pub mod scalar; pub mod simd; diff --git a/examples/fannkuch_redux/src/lib.rs b/examples/fannkuch_redux/src/lib.rs index e45546ac3..63b862e14 100644 --- a/examples/fannkuch_redux/src/lib.rs +++ b/examples/fannkuch_redux/src/lib.rs @@ -6,7 +6,8 @@ clippy::many_single_char_names, clippy::cast_possible_truncation, clippy::cast_sign_loss, - clippy::cast_possible_wrap + clippy::cast_possible_wrap, + clippy::must_use_candidate )] pub mod scalar; diff --git a/examples/mandelbrot/src/lib.rs b/examples/mandelbrot/src/lib.rs index 6b2d09f93..2760ba44c 100644 --- a/examples/mandelbrot/src/lib.rs +++ b/examples/mandelbrot/src/lib.rs @@ -6,7 +6,8 @@ #![allow( clippy::cast_precision_loss, clippy::cast_sign_loss, - clippy::cast_possible_truncation + clippy::cast_possible_truncation, + clippy::must_use_candidate )] use rayon::prelude::*; diff --git a/examples/mandelbrot/src/simd_par.rs b/examples/mandelbrot/src/simd_par.rs index 3bf0bccd4..d458cbcf6 100644 --- a/examples/mandelbrot/src/simd_par.rs +++ b/examples/mandelbrot/src/simd_par.rs @@ -145,10 +145,11 @@ pub fn generate(dims: Dimensions, xr: Range, yr: Range) -> Vec { }); }); + // This is safe, we're transmuting from a more-aligned type to a + // less-aligned one. + #[allow(clippy::unsound_collection_transmute)] unsafe { let mut out: Vec = std::mem::transmute(out); - // This is safe, we're transmuting from a more-aligned type to a - // less-aligned one. out.set_len(width * height); out } diff --git a/examples/matrix_inverse/src/lib.rs b/examples/matrix_inverse/src/lib.rs index f6a8ad860..1f9bab3f8 100644 --- a/examples/matrix_inverse/src/lib.rs +++ b/examples/matrix_inverse/src/lib.rs @@ -1,6 +1,7 @@ //! 4x4 matrix inverse #![feature(custom_inner_attributes)] #![deny(warnings, rust_2018_idioms)] +#![allow(clippy::must_use_candidate)] pub mod scalar; pub mod simd; diff --git a/examples/nbody/src/lib.rs b/examples/nbody/src/lib.rs index c99bee259..d15854d5d 100644 --- a/examples/nbody/src/lib.rs +++ b/examples/nbody/src/lib.rs @@ -2,7 +2,11 @@ //! //! [bg]: https://benchmarksgame-team.pages.debian.net/benchmarksgame/description/nbody.html#nbody #![deny(warnings, rust_2018_idioms)] -#![allow(clippy::similar_names, clippy::excessive_precision)] +#![allow( + clippy::similar_names, + clippy::excessive_precision, + clippy::must_use_candidate +)] pub mod scalar; pub mod simd; diff --git a/examples/options_pricing/src/lib.rs b/examples/options_pricing/src/lib.rs index 00a0afd48..677109bd1 100644 --- a/examples/options_pricing/src/lib.rs +++ b/examples/options_pricing/src/lib.rs @@ -6,6 +6,7 @@ clippy::cast_precision_loss, clippy::cast_possible_truncation, clippy::cast_possible_wrap, + clippy::must_use_candidate, clippy::too_many_arguments )] diff --git a/examples/spectral_norm/src/lib.rs b/examples/spectral_norm/src/lib.rs index fab666177..1134fb0b6 100644 --- a/examples/spectral_norm/src/lib.rs +++ b/examples/spectral_norm/src/lib.rs @@ -1,7 +1,10 @@ //! Spectral Norm #![deny(warnings, rust_2018_idioms)] #![allow(non_snake_case, non_camel_case_types)] -#![allow(clippy::cast_precision_loss)] +#![allow( + clippy::cast_precision_loss, + clippy::must_use_candidate +)] pub mod scalar; pub mod simd; diff --git a/examples/stencil/src/lib.rs b/examples/stencil/src/lib.rs index d59c2c930..2ff408e59 100644 --- a/examples/stencil/src/lib.rs +++ b/examples/stencil/src/lib.rs @@ -7,7 +7,8 @@ clippy::too_many_arguments, clippy::cast_possible_wrap, clippy::cast_possible_truncation, - clippy::inline_always + clippy::inline_always, + clippy::must_use_candidate )] #[cfg(feature = "ispc")] diff --git a/examples/triangle_xform/src/lib.rs b/examples/triangle_xform/src/lib.rs index 6a7c22112..7ecdb011a 100644 --- a/examples/triangle_xform/src/lib.rs +++ b/examples/triangle_xform/src/lib.rs @@ -1,3 +1,5 @@ +#![allow(clippy::must_use_candidate)] + /// Simple matrix type. /// The memory layout is the same as the one for Direct3D/OpenGL: fourth vector /// represents the translation vector `[x, y, z]`. diff --git a/src/api/minimal/ptr.rs b/src/api/minimal/ptr.rs index e8424209b..8b42b6959 100644 --- a/src/api/minimal/ptr.rs +++ b/src/api/minimal/ptr.rs @@ -68,7 +68,7 @@ macro_rules! impl_minimal_p { /// Extracts the value at `index`. /// - /// # Precondition + /// # Safety /// /// If `index >= Self::lanes()` the behavior is undefined. #[inline] @@ -96,7 +96,7 @@ macro_rules! impl_minimal_p { /// Returns a new vector where the value at `index` is replaced by `new_value`. /// - /// # Precondition + /// # Safety /// /// If `index >= Self::lanes()` the behavior is undefined. #[inline] @@ -611,7 +611,7 @@ macro_rules! impl_minimal_p { /// Instantiates a new vector with the values of the `slice`. /// - /// # Precondition + /// # Safety /// /// If `slice.len() < Self::lanes()` or `&slice[0]` is not aligned /// to an `align_of::()` boundary, the behavior is undefined. @@ -624,7 +624,7 @@ macro_rules! impl_minimal_p { /// Instantiates a new vector with the values of the `slice`. /// - /// # Precondition + /// # Safety /// /// If `slice.len() < Self::lanes()` the behavior is undefined. #[inline] @@ -827,7 +827,7 @@ macro_rules! impl_minimal_p { /// Writes the values of the vector to the `slice`. /// - /// # Precondition + /// # Safety /// /// If `slice.len() < Self::lanes()` or `&slice[0]` is not /// aligned to an `align_of::()` boundary, the behavior is @@ -843,7 +843,7 @@ macro_rules! impl_minimal_p { /// Writes the values of the vector to the `slice`. /// - /// # Precondition + /// # Safety /// /// If `slice.len() < Self::lanes()` the behavior is undefined. #[inline] @@ -1151,7 +1151,7 @@ macro_rules! impl_minimal_p { /// As such, memory acquired directly from allocators or memory /// mapped files may be too large to handle with this function. /// - /// Consider using wrapping_offset_from instead if these constraints + /// Consider using `wrapping_offset_from` instead if these constraints /// are difficult to satisfy. The only advantage of this method is /// that it enables more aggressive compiler optimizations. #[inline] diff --git a/src/lib.rs b/src/lib.rs index d2812e18a..4b78080b5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -218,6 +218,8 @@ clippy::cast_lossless, clippy::cast_possible_wrap, clippy::cast_precision_loss, + // TODO: manually add the `#[must_use]` attribute where appropiate + clippy::must_use_candidate, // This lint is currently broken for generic code // See https://github.com/rust-lang/rust-clippy/issues/3410 clippy::use_self, From a4b030548d9a18180bf48e97fafe4d96530bd2d2 Mon Sep 17 00:00:00 2001 From: Gabriel Majeri Date: Fri, 22 Nov 2019 23:04:05 +0200 Subject: [PATCH 7/7] Use latest released `core_arch` version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index b51e01697..a103154ce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ maintenance = { status = "experimental" } [dependencies] cfg-if = "0.1.10" -core_arch = { git = "https://github.com/rust-lang/stdarch", optional = true } +core_arch = { version = "0.1.5", optional = true } libm = "0.1.4" [features]