Skip to content

Commit

Permalink
Merge pull request #305 from GZTimeWalker/fix/no-std
Browse files Browse the repository at this point in the history
fix(no_std): use `core::slice` in `bitmap_store.rs`
  • Loading branch information
Kerollmops authored Dec 13, 2024
2 parents 00992ee + c175ea6 commit 83017ad
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 77 deletions.
172 changes: 99 additions & 73 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
name: Continuous integration

jobs:
ci:
build:
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -21,101 +21,127 @@ jobs:
- 1.71.1
env:
RUSTFLAGS: "-C target-cpu=native -C opt-level=3"
ROARINGRS_BENCH_OFFLINE: "true"

steps:
- name: Checkout roaring-rs
uses: actions/checkout@v2

- name: Checkout benchmark datasets
uses: actions/checkout@v2
with:
repository: "RoaringBitmap/real-roaring-datasets"
path: "benchmarks/real-roaring-datasets"
uses: actions/checkout@v4

- name: Initialize rust toolchain
uses: actions-rs/toolchain@v1
uses: dtolnay/rust-toolchain@master
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true
components: rustfmt, clippy

- name: Install miri
uses: actions-rs/toolchain@v1
if: matrix.rust == 'nightly'
with:
profile: minimal
toolchain: nightly
override: true
components: miri

- name: miri setup
uses: actions-rs/cargo@v1
- name: Check
# clippy will also do a build check
# so we don't need to run `cargo check` or `cargo build`
# use different features to check if everything is fine
# the incremental compilation will make this faster
run: |
cargo clippy -p roaring --all-targets --no-default-features -- -D warnings
cargo clippy -p roaring --all-targets --features serde -- -D warnings
- name: Check SIMD
if: matrix.rust == 'nightly'
with:
command: miri
args: setup
run: cargo clippy -p roaring --all-targets --all-features -- -D warnings

- name: Fetch
uses: actions-rs/cargo@v1
with:
command: fetch
- name: Check formatting
run: cargo fmt --all -- --check

- name: Build
uses: actions-rs/cargo@v1
with:
command: build
args: --all-targets
test:
runs-on: ubuntu-latest
needs: build
strategy:
matrix:
rust:
- stable
- beta
- nightly
- 1.71.1
features:
- default
- no-std
include:
- rust: nightly
features: simd
env:
RUSTFLAGS: "-C target-cpu=native -C opt-level=3"

- name: Check
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all-targets -- -D warnings
steps:
- name: Checkout roaring-rs
uses: actions/checkout@v4

- name: Check formatting
uses: actions-rs/cargo@v1
- name: Initialize rust toolchain
uses: dtolnay/rust-toolchain@master
with:
command: fmt
args: -- --check
toolchain: ${{ matrix.rust }}

- name: Test
uses: actions-rs/cargo@v1
if: matrix.features == 'default'
run: cargo test -p roaring --features serde

- name: Test no default features
if: matrix.features == 'no-std'
run: cargo test -p roaring --no-default-features

- name: SIMD test
if: matrix.rust == 'nightly' && matrix.features == 'simd'
run: cargo +nightly test -p roaring --features simd

miri:
runs-on: ubuntu-latest
needs: build
env:
# warning: Miri does not support optimizations: the opt-level is ignored.
RUSTFLAGS: "-C target-cpu=native"

steps:
- name: Checkout roaring-rs
uses: actions/checkout@v4

- name: Initialize rust toolchain
uses: dtolnay/rust-toolchain@master
with:
command: test
args: --features serde
toolchain: nightly
components: miri

- name: Setup miri
run: cargo miri setup

- name: Test bit endian
uses: actions-rs/cargo@v1
if: matrix.rust == 'nightly'
with:
command: miri
args: test --target s390x-unknown-linux-gnu --package roaring --lib -- bitmap::serialization::test::test_from_lsb0_bytes
run: cargo miri test --target s390x-unknown-linux-gnu -p roaring --lib -- bitmap::serialization::test::test_from_lsb0_bytes

- name: Test no default features
uses: actions-rs/cargo@v1
with:
command: test
args: --no-default-features
bench:
runs-on: ubuntu-latest
needs: build
strategy:
matrix:
rust:
- stable
- nightly
features:
- default
include:
- rust: nightly
features: simd
env:
RUSTFLAGS: "-C target-cpu=native -C opt-level=3"
ROARINGRS_BENCH_OFFLINE: "true"

- name: Test benchmarks
uses: actions-rs/cargo@v1
with:
command: bench
steps:
- name: Checkout roaring-rs
uses: actions/checkout@v4

- name: SIMD test
if: matrix.rust == 'nightly'
uses: actions-rs/cargo@v1
- name: Checkout benchmark datasets
uses: actions/checkout@v4
with:
toolchain: nightly
command: test
args: --features "simd"
repository: "RoaringBitmap/real-roaring-datasets"
path: "benchmarks/real-roaring-datasets"

- name: SIMD test benchmarks
if: matrix.rust == 'nightly'
uses: actions-rs/cargo@v1
- name: Initialize rust toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly
command: bench
args: --features "simd"
toolchain: ${{ matrix.rust }}

- name: Bench
run: cargo bench --features "${{ matrix.features }}"
4 changes: 2 additions & 2 deletions roaring/src/bitmap/store/array_store/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub fn or(lhs: &[u16], rhs: &[u16], visitor: &mut impl BinaryOperationVisitor) {
if rem == 0 {
visitor.visit_slice(tail_b)
} else {
buffer[..rem as usize].sort_unstable();
buffer[..rem].sort_unstable();
rem = dedup(&mut buffer[..rem]);
scalar::or(&buffer[..rem], tail_b, visitor);
}
Expand Down Expand Up @@ -267,7 +267,7 @@ pub fn xor(lhs: &[u16], rhs: &[u16], visitor: &mut impl BinaryOperationVisitor)
if rem == 0 {
visitor.visit_slice(tail_b)
} else {
buffer[..rem as usize].sort_unstable();
buffer[..rem].sort_unstable();
rem = xor_slice(&mut buffer[..rem]);
scalar::xor(&buffer[..rem], tail_b, visitor);
}
Expand Down
2 changes: 1 addition & 1 deletion roaring/src/bitmap/store/bitmap_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl BitmapStore {
// Safety: It's safe to reinterpret u64s as u8s because u8 has less alignment requirements,
// and has no padding/uninitialized data.
let dst = unsafe {
std::slice::from_raw_parts_mut(bits.as_mut_ptr().cast::<u8>(), BITMAP_BYTES)
core::slice::from_raw_parts_mut(bits.as_mut_ptr().cast::<u8>(), BITMAP_BYTES)
};
let dst = &mut dst[byte_offset..][..bytes.len()];
dst.copy_from_slice(bytes);
Expand Down
2 changes: 1 addition & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
use_small_heuristics = "max"
use_small_heuristics = "Max"

0 comments on commit 83017ad

Please sign in to comment.