Skip to content

Upgrade CI (clippy, more targets) #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 57 additions & 44 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,58 +1,71 @@
language: rust
sudo: false
rust: nightly

matrix:
include:
- name: "miri"
rust: nightly
install:
- rustup component add rust-src
- cargo +nightly install --force --git https://github.com/rust-lang/miri miri
- cargo install xargo
script:
- cargo clean
- cargo +nightly miri test
- rust: 1.29.0
- rust: stable
- rust: beta
- rust: nightly
- rust: nightly
env:
- FEATURES='nightly'
env: TARGET=x86_64-unknown-linux-gnu
script: sh ci/miri.sh
- name: "rustfmt/clippy"
env: TARGET=i586-unknown-linux-gnu
script: sh ci/tools.sh
- name: "docs"
env: TARGET=x86_64-unknown-linux-gnu
script: cargo -vv doc --features nightly,serde,rayon
deploy:
provider: pages
skip-cleanup: true
github-token: $GITHUB_TOKEN
local-dir: target/doc
keep-history: false
on:
branch: master
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if you are interested into deploying the docs with the nightly features to github-pages. If not I can just remove the deploy key. Otherwise, you'd need to generate a token and push it to travis as GITHUB_TOKEN.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the only difference is that HashMap::new is const fn on nightly. Not worth a completely separate set of docs IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the serde and rayon features would add more stuff. I'll remove the deploy key then.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! I forgot about those! Yes, please do keep the docs in that case.


# test a target without sse2 for raw/generic.rs
- rust: stable
env:
- TARGET=i586-unknown-linux-gnu
addons:
apt:
packages:
- gcc-multilib
install:
- rustup target add $TARGET
script:
- cargo build --verbose --target $TARGET
- cargo test --verbose --target $TARGET
# Tier 1 targets:
- name: "x86_64-unknown-linux-gnu"
env: TARGET=x86_64-unknown-linux-gnu
- name: "x86_64-unknown-linux-gnu (beta)"
rust: beta
env: TARGET=x86_64-unknown-linux-gnu
- name: "x86_64-unknown-linux-gnu (stable)"
rust: stable
env: TARGET=x86_64-unknown-linux-gnu
- name: "x86_64-unknown-linux-gnu (Rust 1.29.0)"
rust: 1.31.0
env: TARGET=x86_64-unknown-linux-gnu
- name: "i686-unknown-linux-gnu"
env: TARGET=i686-unknown-linux-gnu CROSS=1
- name: "x86_64-apple-darwin"
env: TARGET=x86_64-apple-darwin
os: osx
osx_image: xcode10
- name: "i686-apple-darwin"
env: TARGET=i686-apple-darwin
os: osx
osx_image: xcode10
- name: "x86_64-pc-windows-msvc"
env: TARGET=x86_64-pc-windows-msvc
os: windows
- name: "x86_64-pc-windows-gnu"
env: TARGET=x86_64-pc-windows-gnu CROSS=1
- name: "i686-pc-windows-gnu"
env: TARGET=i686-pc-windows-gnu CROSS=1

# Tier 2/3 targets:
- name: "i586-unknown-linux-gnu (no SSE2)"
env: TARGET=i586-unknown-linux-gnu CROSS=1
- name: "armv7-unknown-linux-gnueabihf"
env: TARGET=armv7-unknown-linux-gnueabihf CROSS=1
- name: "aarch64-unknown-linux-gnu"
env: TARGET=aarch64-unknown-linux-gnu CROSS=1

install: travis_retry rustup target add "${TARGET}"
script: sh ci/run.sh

branches:
# Don't build these branches
except:
# Used by bors
- trying.tmp
- staging.tmp

before_script:
- if [ "$TRAVIS_RUST_VERSION" == "stable" ]; then rustup component add rustfmt; fi

script:
- if [ "$TRAVIS_RUST_VERSION" == "stable" ]; then cargo fmt -- --check; fi

- cargo build --verbose --features "$FEATURES"
- cargo test --verbose --features "$FEATURES"
- if [ "$TRAVIS_RUST_VERSION" == "nightly" ]; then cargo bench --verbose --features "$FEATURES"; fi
- cargo doc --verbose --features "$FEATURES"

- cargo build --verbose --features "$FEATURES serde"
- cargo test --verbose --features "$FEATURES serde"
- if [ "$TRAVIS_RUST_VERSION" == "nightly" ]; then cargo bench --verbose --features "$FEATURES serde"; fi
- cargo doc --verbose --features "$FEATURES serde"
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ rustc-hash = "1.0"
serde_test = "1.0"

[features]
default = []
nightly = []
11 changes: 11 additions & 0 deletions ci/miri.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env sh

set -ex

export CARGO_NET_RETRY=5
export CARGO_NET_TIMEOUT=10

if cargo install --force --git https://github.com/rust-lang/miri miri ; then
cargo miri setup
cargo miri test
fi
38 changes: 38 additions & 0 deletions ci/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env sh

set -ex

: "${TARGET?The TARGET environment variable must be set.}"

FEATURES="rayon,serde"
if [ "${TRAVIS_RUST_VERSION}" = "nightly" ]; then
FEATURES="${FEATURES},nightly"
export RUSTFLAGS="$RUSTFLAGS -D warnings"
fi

CARGO=cargo
if [ "${CROSS}" = "1" ]; then
export CARGO_NET_RETRY=5
export CARGO_NET_TIMEOUT=10

cargo install cross
CARGO=cross
fi

export RUSTFLAGS="$RUSTFLAGS --cfg hashbrown_deny_warnings"

"${CARGO}" -vv test --target="${TARGET}"
"${CARGO}" -vv test --target="${TARGET}" --features "${FEATURES}"

"${CARGO}" -vv test --target="${TARGET}" --release
"${CARGO}" -vv test --target="${TARGET}" --release --features "${FEATURES}"

if [ "${TRAVIS_RUST_VERSION}" = "nightly" ]; then
# Run benchmark on native targets, build them on non-native ones:
NO_RUN=""
if [ "${CROSS}" = "1" ]; then
NO_RUN="--no-run"
fi

"${CARGO}" -vv bench "${NO_RUN}" --features "${FEATURES}"
fi
45 changes: 45 additions & 0 deletions ci/tools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env sh

set -ex

retry() {
result=0
count=1
max=5
while [ "$count" -le 3 ]; do
[ "$result" -ne 0 ] && {
printf "\nRetrying, %d of %d\n" $count $max >&2
}
"$@"
result=$?
[ $result -eq 0 ] && break
count=$(count + 1)
sleep 1
done

[ "$count" -gt 3 ] && {
printf "\nFailed %d times.\n" $max >&2
}

return $result
}


if retry rustup component add rustfmt ; then
cargo fmt --all -- --check
fi

if retry rustup component add clippy ; then
cargo clippy --all -- -D clippy::pedantic
fi

if [ "${TRAVIS_OS_NAME}" = "linux" ]; then
if retry rustup component add clippy ; then
cargo clippy --all --target=i586-unknown-linux-gnu -- -D clippy::pedantic
fi
fi

if command -v shellcheck ; then
shellcheck --version
shellcheck ci/*.sh
fi
1 change: 1 addition & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
doc-valid-idents = [ "CppCon", "SwissTable", "SipHash", "HashDoS" ]
22 changes: 13 additions & 9 deletions src/fx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ pub struct FxHasher {
}

#[cfg(target_pointer_width = "32")]
const K: usize = 0x9e3779b9;
const K: usize = 0x9e37_79b9;
#[cfg(target_pointer_width = "64")]
const K: usize = 0x517cc1b727220a95;
const K: usize = 0x517c_c1b7_2722_0a95;

impl Default for FxHasher {
#[inline]
fn default() -> FxHasher {
FxHasher { hash: 0 }
fn default() -> Self {
Self { hash: 0 }
}
}

Expand All @@ -48,14 +48,16 @@ impl Hasher for FxHasher {
#[inline]
fn write(&mut self, mut bytes: &[u8]) {
#[cfg(target_pointer_width = "32")]
let read_usize = |bytes| NativeEndian::read_u32(bytes);
#[allow(clippy::cast_possible_truncation)]
let read_usize = |bytes| NativeEndian::read_u32(bytes) as usize;
#[cfg(target_pointer_width = "64")]
let read_usize = |bytes| NativeEndian::read_u64(bytes);
#[allow(clippy::cast_possible_truncation)]
let read_usize = |bytes| NativeEndian::read_u64(bytes) as usize;

let mut hash = FxHasher { hash: self.hash };
let mut hash = Self { hash: self.hash };
assert!(size_of::<usize>() <= 8);
while bytes.len() >= size_of::<usize>() {
hash.add_to_hash(read_usize(bytes) as usize);
hash.add_to_hash(read_usize(bytes));
bytes = &bytes[size_of::<usize>()..];
}
if (size_of::<usize>() > 4) && (bytes.len() >= 4) {
Expand All @@ -66,7 +68,7 @@ impl Hasher for FxHasher {
hash.add_to_hash(NativeEndian::read_u16(bytes) as usize);
bytes = &bytes[2..];
}
if (size_of::<usize>() > 1) && bytes.len() >= 1 {
if (size_of::<usize>() > 1) && !bytes.is_empty() {
hash.add_to_hash(bytes[0] as usize);
}
self.hash = hash.hash;
Expand All @@ -89,13 +91,15 @@ impl Hasher for FxHasher {

#[cfg(target_pointer_width = "32")]
#[inline]
#[allow(clippy::cast_possible_truncation)]
fn write_u64(&mut self, i: u64) {
self.add_to_hash(i as usize);
self.add_to_hash((i >> 32) as usize);
}

#[cfg(target_pointer_width = "64")]
#[inline]
#[allow(clippy::cast_possible_truncation)]
fn write_u64(&mut self, i: u64) {
self.add_to_hash(i as usize);
}
Expand Down
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! map, adapted to make it a drop-in replacement for Rust's standard `HashMap`
//! and `HashSet` types.
//!
//! The original C++ version of SwissTable can be found [here], and this
//! The original C++ version of [SwissTable] can be found [here], and this
//! [CppCon talk] gives an overview of how the algorithm works.
//!
//! [SwissTable]: https://abseil.io/blog/20180927-swisstables
Expand All @@ -23,9 +23,11 @@
)
)]
#![warn(missing_docs)]
#![allow(clippy::module_name_repetitions)]

#[cfg(test)]
#[macro_use]
#[allow(unused_imports)]
extern crate std;
#[cfg(test)]
extern crate rand;
Expand Down Expand Up @@ -84,7 +86,7 @@ pub mod hash_set {
pub use map::HashMap;
pub use set::HashSet;

/// Augments `AllocErr` with a CapacityOverflow variant.
/// Augments `AllocErr` with a `CapacityOverflow` variant.
#[derive(Clone, PartialEq, Eq, Debug)]
pub enum CollectionAllocErr {
/// Error due to the computed capacity exceeding the collection's maximum
Expand Down
Loading