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 25, 2021
1 parent aa007d1 commit 306e57a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
36 changes: 33 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
rustup default stable
rustup component add rustfmt
- name: Setup parquet files
run: |
run: |
apt update && apt install python3-pip python3-venv -y -q
python3 -m venv venv
venv/bin/pip install pip --upgrade
Expand Down Expand Up @@ -158,13 +158,42 @@ jobs:
- name: Run
env:
RUST_BACKTRACE: full
RUST_LOG: 'trace'
RUST_LOG: "trace"
# --skip io: miri can't handle opening of files, so we skip those
run: |
cargo miri setup
cargo clean
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
with:
submodules: true
- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-miri-${{ hashFiles('**/Cargo.lock') }}
- name: Setup toolchain
run: |
rustup toolchain install nightly-2021-07-03
rustup default nightly-2021-07-03
rustup component add rustfmt miri
- name: Run
env:
RUST_BACKTRACE: full
RUST_LOG: "trace"
# --skip io: miri can't handle opening of files, so we skip those
run: |
cargo miri setup
cargo clean
cargo miri test --features full,cache_aligned -- --skip io::parquet --skip io::ipc
coverage:
name: Coverage
runs-on: ubuntu-latest
Expand All @@ -185,7 +214,7 @@ jobs:
# this key is not equal because coverage uses different compilation flags.
key: ${{ runner.os }}-amd64-target-coverage-cache-stable-
- name: Setup parquet files
run: |
run: |
apt update && apt install python3-pip python3-venv -y -q
python3 -m venv venv
venv/bin/pip install pip --upgrade
Expand All @@ -199,6 +228,7 @@ jobs:
# 2020-11-15: There is a cargo-tarpaulin regression in 0.17.0
# see https://github.com/xd009642/tarpaulin/issues/618
cargo install --version 0.16.0 cargo-tarpaulin
cargo tarpaulin --features cache_aligned --out Xml
cargo tarpaulin --features full --out Xml
- name: Report coverage
continue-on-error: true
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 306e57a

Please sign in to comment.