Skip to content

Commit

Permalink
Run CI on aarch64 and run clippy on all platforms (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
james7132 authored Mar 20, 2024
1 parent 7507a73 commit 189ddf0
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 43 deletions.
50 changes: 34 additions & 16 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,59 +11,77 @@ env:
CARGO_INCREMENTAL: 0

jobs:
# Ensure the crate builds
# Ensure the crate builds on x86
build_x86_64:
runs-on: ubuntu-latest
strategy:
matrix:
rust: [1.56.0, stable, nightly]
rust: [stable, nightly]
features: ["+avx2", "+sse2"]
env:
RUSTFLAGS: "-C target-feature=${{matrix.features}}"
RUSTFLAGS: "-C target-feature=${{matrix.features}} -D warnings"
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
target: x86_64-unknown-linux-gnu
toolchain: ${{ matrix.rust }}
components: clippy
- name: Tests (x86_64)
run: |
cargo clippy &&
cargo test -v --no-default-features --tests --lib &&
cargo build --verbose --features "$FEATURES" &&
cargo test --verbose --features "$FEATURES" &&
cargo test --verbose --release --features "$FEATURES"
build_aarch64:
# Ensure the crate builds on x86
build_MSRV:
runs-on: ubuntu-latest
strategy:
matrix:
rust: [1.56.0, stable, nightly]
rust: [1.56.0]
features: ["+avx2", "+sse2"]
env:
RUSTFLAGS: "-C target-feature=${{matrix.features}}"
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
target: aarch64-unknown-linux-gnu
target: x86_64-unknown-linux-gnu
toolchain: ${{ matrix.rust }}
- name: Tests (aarch64)
run: cargo check --target aarch64-unknown-linux-gnu
components: clippy
- name: Tests (x86_64)
run: |
cargo clippy &&
cargo test -v --no-default-features --tests --lib &&
cargo build --verbose --features "$FEATURES" &&
cargo test --verbose --features "$FEATURES" &&
cargo test --verbose --release --features "$FEATURES"
# Use clippy to lint for code smells
clippy:
runs-on: ubuntu-latest
# Ensure the crate builds on ARM
build_aarch64:
runs-on: macos-14
strategy:
matrix:
# Run Clippy only on stable
rust: [stable]

rust: [stable, nightly]
features: ["+neon", "-neon"]
env:
RUSTFLAGS: "-C target-feature=${{matrix.features}} -D warnings"
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
target: aarch64-apple-darwin
toolchain: ${{ matrix.rust }}
components: clippy
- name: Run Clippy
- name: Tests (aarch64)
run: |
cargo clippy
cargo clippy &&
cargo test -v --no-default-features --tests --lib &&
cargo build --verbose --features "$FEATURES" &&
cargo test --verbose --features "$FEATURES" &&
cargo test --verbose --release --features "$FEATURES"
# Enforce rustfmt formatting
formatting:
Expand Down
7 changes: 1 addition & 6 deletions src/block/avx2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@
use core::arch::x86::*;
#[cfg(target_arch = "x86_64")]
use core::arch::x86_64::*;
use core::{
cmp::Ordering,
hash::{Hash, Hasher},
iter::Iterator,
ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Not},
};
use core::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Not};

#[derive(Copy, Clone, Debug)]
#[repr(transparent)]
Expand Down
3 changes: 2 additions & 1 deletion src/block/default.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use core::iter::Iterator;
use core::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Not};

#[derive(Copy, Clone, PartialEq, Debug)]
Expand All @@ -8,6 +7,7 @@ pub struct Block(usize);
impl Block {
pub const USIZE_COUNT: usize = 1;
pub const NONE: Self = Block(0);
#[allow(dead_code)]
pub const ALL: Self = Block(!0);
pub const BITS: usize = core::mem::size_of::<Self>() * 8;

Expand All @@ -17,6 +17,7 @@ impl Block {
}

#[inline]
#[allow(dead_code)]
pub const fn from_usize_array(array: [usize; Self::USIZE_COUNT]) -> Self {
Self(array[0])
}
Expand Down
2 changes: 2 additions & 0 deletions src/block/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::undocumented_unsafe_blocks)]

use core::cmp::Ordering;
use core::hash::{Hash, Hasher};

Expand Down
30 changes: 10 additions & 20 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,13 +681,12 @@ impl FixedBitSet {
pub fn union_count(&self, other: &FixedBitSet) -> usize {
let me = self.as_slice();
let other = other.as_slice();
let mut count = Self::batch_count_ones(me.iter().zip(other.iter()).map(|(x, y)| (*x | *y)));
if other.len() > me.len() {
count += Self::batch_count_ones(other[me.len()..].iter().copied());
} else if self.len() > other.len() {
count += Self::batch_count_ones(me[other.len()..].iter().copied());
let count = Self::batch_count_ones(me.iter().zip(other.iter()).map(|(x, y)| (*x | *y)));
match other.len().cmp(&me.len()) {
Ordering::Greater => count + Self::batch_count_ones(other[me.len()..].iter().copied()),
Ordering::Less => count + Self::batch_count_ones(me[other.len()..].iter().copied()),
Ordering::Equal => count,
}
count
}

/// Computes how many bits would be set in the intersection between two bitsets.
Expand Down Expand Up @@ -730,12 +729,10 @@ impl FixedBitSet {
let me = self.as_slice();
let other = other.as_slice();
let count = Self::batch_count_ones(me.iter().zip(other.iter()).map(|(x, y)| (*x ^ *y)));
if other.len() > me.len() {
count + Self::batch_count_ones(other[me.len()..].iter().copied())
} else if me.len() > other.len() {
count + Self::batch_count_ones(me[other.len()..].iter().copied())
} else {
count
match other.len().cmp(&me.len()) {
Ordering::Greater => count + Self::batch_count_ones(other[me.len()..].iter().copied()),
Ordering::Less => count + Self::batch_count_ones(me[other.len()..].iter().copied()),
Ordering::Equal => count,
}
}

Expand Down Expand Up @@ -805,14 +802,8 @@ impl<'a> Iterator for Difference<'a> {
type Item = usize;

#[inline]
#[allow(clippy::manual_find)]
fn next(&mut self) -> Option<Self::Item> {
for nxt in self.iter.by_ref() {
if !self.other.contains(nxt) {
return Some(nxt);
}
}
None
self.iter.by_ref().find(|&nxt| !self.other.contains(nxt))
}

#[inline]
Expand Down Expand Up @@ -875,7 +866,6 @@ impl<'a> Iterator for Intersection<'a> {
type Item = usize; // the bit position of the '1'

#[inline]
#[allow(clippy::manual_find)]
fn next(&mut self) -> Option<Self::Item> {
self.iter.by_ref().find(|&nxt| self.other.contains(nxt))
}
Expand Down

0 comments on commit 189ddf0

Please sign in to comment.