Skip to content

Commit 57648d2

Browse files
committed
Lint SIMD code, fix generic expectation failures
1 parent ba0c71f commit 57648d2

4 files changed

Lines changed: 66 additions & 7 deletions

File tree

.github/workflows/rust.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
run: curl -fsSL https://github.com/tamasfe/taplo/releases/latest/download/taplo-linux-x86_64.gz | gzip -d - | install -m 755 /dev/stdin /usr/local/bin/taplo
2222
- env:
2323
TARGET: i586-unknown-linux-gnu
24-
run: sh ci/tools.sh
24+
run: bash ci/tools.sh
2525

2626
basics:
2727
runs-on: ubuntu-latest

ci/tools.sh

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env sh
1+
#!/usr/bin/env bash
22

33
set -ex
44

@@ -36,7 +36,63 @@ if retry rustup component add rustfmt ; then
3636
fi
3737

3838
if retry rustup component add clippy ; then
39-
cargo clippy --all --tests --features serde,rayon -- -D warnings
39+
# we want all targets that have dedicated SIMD implementations,
40+
# plus one that uses the generic implementation,
41+
# since we can't lint cfg-disabled code
42+
TARGETS=()
43+
44+
# associative array of cfgs from rustc
45+
declare -A CFG
46+
for cfg in $(rustc --print cfg); do
47+
# bash is very upset about quotes and equal signs in keys
48+
cfg="${cfg//\"/}"
49+
cfg="${cfg//=/_}"
50+
printf "\n%s\n" "$cfg" >&2
51+
CFG["$cfg"]=1
52+
done
53+
54+
HOST_IS_GENERIC=1
55+
56+
# SSE2
57+
if (( CFG[target_feature_sse2] && (CFG[target_arch_x86] || CFG[target_arch_x86_64]) )); then
58+
printf "\nHost target supports SSE2\n" >&2
59+
TARGETS+=(--target "$(rustc --print host-tuple)")
60+
HOST_IS_GENERIC=0
61+
elif retry rustup target add x86_64-unknown-linux-gnu; then
62+
printf "\nTesting x86_64-unknown-linux-gnu\n" >&2
63+
TARGETS+=(--target x86_64-unknown-linux-gnu)
64+
fi
65+
66+
# NEON
67+
if (( CFG[target_arch_aarch64] && CFG[target_feature_neon] && CFG[target_endian_little] )); then
68+
printf "\nHost target supports NEON\n" >&2
69+
TARGETS+=(--target "$(rustc --print host-tuple)")
70+
HOST_IS_GENERIC=0
71+
elif retry rustup target add aarch64-unknown-linux-gnu; then
72+
printf "\nTesting aarch64-unknown-linux-gnu\n" >&2
73+
TARGETS+=(--target aarch64-unknown-linux-gnu)
74+
fi
75+
76+
# LSX
77+
if (( CFG[target_arch_loongarch64] && CFG[target_feature_lsx] )); then
78+
printf "\nHost target supports LSX\n" >&2
79+
TARGETS+=(--target "$(rustc --print host-tuple)")
80+
HOST_IS_GENERIC=0
81+
elif retry rustup target add loongarch64-unknown-linux-gnu; then
82+
printf "\nTesting loongarch64-unknown-linux-gnu\n" >&2
83+
TARGETS+=(--target loongarch64-unknown-linux-gnu)
84+
fi
85+
86+
# Generic
87+
if (( HOST_IS_GENERIC )); then
88+
printf "\nHost target support is generic\n" >&2
89+
TARGETS+=(--target "$(rustc --print host-tuple)")
90+
elif retry rustup target add i686-unknown-linux-gnu; then
91+
printf "\nTesting i686-unknown-linux-gnu\n" >&2
92+
TARGETS+=(--target i686-unknown-linux-gnu)
93+
fi
94+
95+
cargo clippy --all --tests --features serde,rayon "${TARGETS[@]}" -- -D warnings
4096
fi
4197

4298
if command -v taplo ; then

src/control/group/generic.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ pub(crate) type BitMaskWord = GroupWord;
2424
pub(crate) type NonZeroBitMaskWord = NonZeroGroupWord;
2525
pub(crate) const BITMASK_STRIDE: usize = 8;
2626
// We only care about the highest bit of each tag for the mask.
27-
#[expect(clippy::cast_possible_truncation, clippy::unnecessary_cast)]
2827
const BITMASK_MASK: BitMaskWord = u64::from_ne_bytes([Tag::DELETED.0; 8]) as GroupWord;
2928
pub(crate) const BITMASK_ITER_MASK: BitMaskWord = !0;
3029

@@ -70,15 +69,13 @@ impl Group {
7069

7170
/// Loads a group of tags starting at the given address.
7271
#[inline]
73-
#[expect(clippy::cast_ptr_alignment)] // unaligned load
7472
pub(crate) unsafe fn load(ptr: *const Tag) -> Self {
7573
unsafe { Group(ptr::read_unaligned(ptr.cast())) }
7674
}
7775

7876
/// Loads a group of tags starting at the given address, which must be
7977
/// aligned to `mem::align_of::<Group>()`.
8078
#[inline]
81-
#[expect(clippy::cast_ptr_alignment)]
8279
pub(crate) unsafe fn load_aligned(ptr: *const Tag) -> Self {
8380
debug_assert_eq!(ptr.align_offset(mem::align_of::<Self>()), 0);
8481
unsafe { Group(ptr::read(ptr.cast())) }
@@ -87,7 +84,6 @@ impl Group {
8784
/// Stores the group of tags to the given address, which must be
8885
/// aligned to `mem::align_of::<Group>()`.
8986
#[inline]
90-
#[expect(clippy::cast_ptr_alignment)]
9187
pub(crate) unsafe fn store_aligned(self, ptr: *mut Tag) {
9288
debug_assert_eq!(ptr.align_offset(mem::align_of::<Self>()), 0);
9389
unsafe {

src/control/group/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
// TESTING NOTE:
2+
//
3+
// Because this module uses `cfg(..)` to select an implementation, it will not
4+
// be linted without being run on targets that actually load each of these
5+
// modules. Be sure to edit `ci/tools.sh` to add in the necessary cfgs if you
6+
// change these, so that your implementation gets properly linted.
7+
18
cfg_if! {
29
// Use the SSE2 implementation if possible: it allows us to scan 16 buckets
310
// at once instead of 8. We don't bother with AVX since it would require

0 commit comments

Comments
 (0)