Skip to content

Commit

Permalink
Silence clippy warnings for libm and add clippy to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
gnzlbg committed Jul 5, 2019
1 parent ae3ab74 commit c4c8dca
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 15 deletions.
6 changes: 5 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
variables:
TOOLCHAIN: nightly

- job: rustfmt
- job: tools
pool:
vmImage: ubuntu-16.04
steps:
Expand All @@ -63,6 +63,10 @@ jobs:
displayName: "install rustfmt"
- bash: cargo fmt --all -- --check
displayName: "check formatting"
- bash: rustup component add clippy
displayName: "install clippy"
- bash: cargo clippy --all -- -D clippy::pedantic
displayName: "check clippy"

- job: compiler_builtins_works
pool:
Expand Down
6 changes: 3 additions & 3 deletions crates/libm-analyze/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,18 +208,18 @@ fn get_functions(files: &[syn::File]) -> Vec<FnSig> {
));
}
if attrs.is_empty() {
err!(format!("missing `#[inline]` and `#[no_panic]` attributes"));
err!("missing `#[inline]` and `#[no_panic]` attributes");
} else {
let attrs = attrs
.iter()
.map(|a| syn_to_str!(a))
.collect::<Vec<_>>()
.join(",");
if !attrs.contains("inline") {
err!(format!("missing `#[inline]` attribute"));
err!("missing `#[inline]` attribute");
}
if !attrs.contains("no_panic") {
err!(format!("missing `#[no_panic]` attributes"));
err!("missing `#[no_panic]` attributes");
}
}
// Validate and parse output parameters and function arguments:
Expand Down
35 changes: 27 additions & 8 deletions crates/libm-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl_tuple_vec!((i32, f32): x: x.0, x.1);
impl_tuple_vec!((f32, f32, f32): x: x.0, x.1, x.2);
impl_tuple_vec!((f64, f64, f64): x: x.0, x.1, x.2);

/// Kind of LibmApi - used to handle generating tests
/// Kind of libm API - used to handle generating tests
/// for some functions slightly differently.
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum ApiKind {
Expand Down Expand Up @@ -155,7 +155,7 @@ macro_rules! assert_approx_eq {
if !$crate::WithinUlps::within_ulps($result, $expected, $ulps) {
panic!("{:?} != {:?}", $result, $expected);
}
}
};
}

pub trait Toward: Sized {
Expand Down Expand Up @@ -190,8 +190,10 @@ pub trait RandSeq: Sized {

macro_rules! impl_rand_seq_f {
($float_ty:ident) => {
#[allow(clippy::use_self)]
impl RandSeq for $float_ty {
fn rand_seq<R: rand::Rng>(rng: &mut R, _api_kind: ApiKind, len: usize) -> Vec<Self> {
use rand::seq::SliceRandom;
use std::$float_ty::*;
let mut vec = Vec::with_capacity(len);

Expand All @@ -212,12 +214,12 @@ macro_rules! impl_rand_seq_f {
const NSTEPS: usize = 1_000;
vec.extend(INFINITY.toward(0., NSTEPS));
vec.extend(NEG_INFINITY.toward(0., NSTEPS));
vec.extend((0. as $float_ty).toward(MIN_POSITIVE, NSTEPS));
vec.extend((0. as $float_ty).toward(-MIN_POSITIVE, NSTEPS));
vec.extend((0. as Self).toward(MIN_POSITIVE, NSTEPS));
vec.extend((0. as Self).toward(-MIN_POSITIVE, NSTEPS));

for i in 0..=NSTEPS {
let dx = 2. / NSTEPS as $float_ty;
let next = (-1. as $float_ty) + (i as $float_ty) * dx;
let dx = 2. / NSTEPS as Self;
let next = (-1. as Self) + (i as Self) * dx;
vec.push(next);
}

Expand All @@ -227,10 +229,18 @@ macro_rules! impl_rand_seq_f {
let remaining_len = len.checked_sub(current_len).unwrap();

for _ in 0..remaining_len {
let n = rng.gen::<$float_ty>();
let n = rng.gen::<Self>();
vec.push(n);
}
assert_eq!(vec.len(), len);

// Duplicate the vector, randomly shuffle it, and
// concatenate it. Otherwise for n-ary functions
// all vectors might have the same values. But
// testing with the same values is also worth doing.
let mut vec2 = vec.clone();
vec2.shuffle(rng);
vec.extend(vec2);
vec
}
}
Expand All @@ -242,15 +252,24 @@ impl_rand_seq_f!(f64);

impl RandSeq for i32 {
fn rand_seq<R: rand::Rng>(rng: &mut R, api_kind: ApiKind, len: usize) -> Vec<Self> {
use rand::seq::SliceRandom;
let mut v = Vec::with_capacity(len);
for _ in 0..len {
let mut r = rng.gen::<i32>();
let mut r = rng.gen::<Self>();
if let ApiKind::Jx = api_kind {
r &= 0xffff;
}
v.push(r);
}
assert_eq!(v.len(), len);

// Duplicate the vector, randomly shuffle it, and
// concatenate it. Otherwise for n-ary functions
// all vectors might have the same values. But
// testing with the same values is also worth doing.
let mut v2 = v.clone();
v2.shuffle(rng);
v.extend(v2);
v
}
}
2 changes: 1 addition & 1 deletion crates/libm-test/tests/system_libm.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Compare the results of the `libm` implementation against the system's libm.
#![cfg(test)]
#![cfg(feature = "system_libm")]
//#![cfg(feature = "system_libm")]

use libm_test::{assert_approx_eq, get_api_kind, Call, RandSeq, TupleVec};

Expand Down
2 changes: 1 addition & 1 deletion crates/libm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! libm in pure Rust
#![deny(warnings)]
//#![no_std]
#![no_std]
#![cfg_attr(
all(target_arch = "wasm32", not(feature = "stable")),
feature(core_intrinsics)
Expand Down
2 changes: 1 addition & 1 deletion crates/libm/src/math/exp2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use super::scalbn;

const TBLSIZE: usize = 256;

#[cfg_attr(rustfmt, rustfmt_skip)]
#[rustfmt::skip]
static TBL: [u64; TBLSIZE * 2] = [
// exp2(z + eps) eps
0x3fe6a09e667f3d5d, 0x3d39880000000000,
Expand Down
36 changes: 36 additions & 0 deletions crates/libm/src/math/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,39 @@
#![allow(
clippy::many_single_char_names,
clippy::similar_names,
clippy::unreadable_literal,
clippy::unseparated_literal_suffix,
clippy::doc_markdown,
clippy::needless_return,
clippy::if_not_else,
clippy::int_plus_one,
clippy::large_digit_groups,
clippy::items_after_statements,
clippy::collapsible_if,
clippy::mixed_case_hex_literals,
clippy::precedence,
clippy::suspicious_else_formatting,
clippy::cast_lossless,
clippy::cast_possible_truncation,
clippy::cast_precision_loss,
clippy::cast_sign_loss,
clippy::cast_possible_wrap,
clippy::excessive_precision,
clippy::range_minus_one,
clippy::cognitive_complexity,
clippy::eq_op,
clippy::shadow_unrelated,
clippy::needless_range_loop,
clippy::float_cmp,
clippy::assign_op_pattern,
clippy::zero_divided_by_zero,
clippy::misrefactored_assign_op,
clippy::if_same_then_else,
clippy::verbose_bit_mask,
clippy::replace_consts,
clippy::used_underscore_binding,
)]

macro_rules! force_eval {
($e:expr) => {
#[allow(unused_unsafe)]
Expand Down

0 comments on commit c4c8dca

Please sign in to comment.