Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Added MIRI checks and coverage for custom allocator
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao committed Sep 26, 2021
1 parent 1bf9224 commit 0995cbc
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
23 changes: 22 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,25 @@ jobs:
# --skip io: miri can't handle opening of files, so we skip those
run: cargo miri test --features full -- --skip io::parquet --skip io::ipc

miri-checks-custom-allocator:
name: MIRI with custom allocator
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2021-07-09
override: true
- uses: Swatinem/rust-cache@v1
- name: Install Miri
run: |
rustup component add miri
cargo miri setup
- name: Run
# --skip io: miri can't handle opening of files, so we skip those
run: cargo miri test --features full,cache_aligned -- --skip io::parquet --skip io::ipc

coverage:
name: Coverage
runs-on: ubuntu-latest
Expand All @@ -91,7 +110,9 @@ jobs:
- name: Install tarpaulin
run: cargo install cargo-tarpaulin
- name: Run coverage
run: cargo tarpaulin --features full --out Xml
run: |
cargo tarpaulin --features cache_aligned --out Xml
cargo tarpaulin --features full --out Xml
- name: Report coverage
continue-on-error: true
run: bash <(curl -s https://codecov.io/bash)
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ full = [
"merge_sort",
"compute",
# parses timezones used in timestamp conversions
"chrono-tz",
"chrono-tz"
]
merge_sort = ["itertools"]
io_csv = ["io_csv_read", "io_csv_write"]
Expand Down
4 changes: 2 additions & 2 deletions src/buffer/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ impl<T: NativeType> MutableBuffer<T> {
}

/// Shrinks the capacity of the [`MutableBuffer`] to fit its current length.
/// The new capacity will be a multiple of 64 bytes.
/// When the feature `cache_aligned`, the new capacity will be a multiple of 64 bytes.
///
/// # Example
/// ```
Expand All @@ -253,7 +253,7 @@ impl<T: NativeType> MutableBuffer<T> {
/// buffer.push(2);
///
/// buffer.shrink_to_fit();
/// assert!(buffer.capacity() == 2);
/// assert!(buffer.capacity() < 16); // 2 or 8 depending on feature `cache_aligned`
/// ```
pub fn shrink_to_fit(&mut self) {
self.data.shrink_to_fit();
Expand Down
10 changes: 8 additions & 2 deletions src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,21 @@ unsafe fn reallocate<T: NativeType>(
(ptr, new_capacity)
}

/// An interface equivalent to `std::vec::Vec` with an allocator aligned along cache-lines.
pub struct AlignedVec<T: NativeType> {
/// An interface equivalent to `std::vec::Vec` with an allocator aligned along cache lines.
pub(crate) struct AlignedVec<T: NativeType> {
// dangling iff capacity = 0
ptr: NonNull<T>,
// invariant: len <= capacity
len: usize,
capacity: usize,
}

impl<T: NativeType> Drop for AlignedVec<T> {
fn drop(&mut self) {
unsafe { alloc::free_aligned(self.ptr, self.capacity) }
}
}

impl<T: NativeType> AlignedVec<T> {
#[inline]
pub fn new() -> Self {
Expand Down

0 comments on commit 0995cbc

Please sign in to comment.