Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix UB and run tests with miri #517

Merged
merged 24 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/setup-rust/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ runs:
if: steps.rustup-cache.outputs.cache-hit != 'true'
with:
toolchain: "${{ steps.rust-version.outputs.version }}"
components: clippy, rustfmt
components: clippy, rustfmt, miri

- name: Rust Dependency Cache
uses: Swatinem/rust-cache@v2
Expand Down
27 changes: 26 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ permissions:
actions: read
contents: read

env:
CARGO_TERM_COLOR: always

jobs:
build:
name: 'build'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: ./.github/actions/cleanup

- name: Install Protoc
Expand All @@ -40,9 +42,32 @@ jobs:
run: cargo test --workspace --all-features
- name: Rust Build
run: cargo build --all-features --all-targets

- name: License Check
run: cargo install --locked cargo-deny && cargo deny check
- uses: rustsec/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Pytest - PyVortex
run: rye run pytest --benchmark-disable test/
working-directory: pyvortex/

miri:
name: 'miri'
runs-on: ubuntu-latest
env:
RUST_BACKTRACE: 1
MIRIFLAGS: -Zmiri-strict-provenance -Zmiri-symbolic-alignment-check -Zmiri-backtrace=full
steps:
- uses: actions/checkout@v4

- uses: ./.github/actions/cleanup

- name: Install Protoc
uses: arduino/setup-protoc@v3

- uses: ./.github/actions/setup-rust

- name: Run tests with Miri
run: cargo miri test
12 changes: 0 additions & 12 deletions .github/workflows/rustsec-audit.yml

This file was deleted.

7 changes: 6 additions & 1 deletion encodings/fastlanes/src/bitpacking/compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,13 @@ mod test {
}

#[test]
fn test_compression_roundtrip() {
fn test_compression_roundtrip_fast() {
compression_roundtrip(125);
}

#[test]
#[cfg_attr(miri, ignore)] // This test is too slow on miri
fn test_compression_roundtrip() {
compression_roundtrip(1024);
compression_roundtrip(10_000);
compression_roundtrip(10_240);
Expand Down
1 change: 1 addition & 0 deletions encodings/fastlanes/src/bitpacking/compute/take.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ mod test {
}

#[test]
#[cfg_attr(miri, ignore)] // This test is too slow on miri
fn take_random_indices() {
let num_patches: usize = 128;
let values = (0..u16::MAX as u32 + num_patches as u32).collect::<Vec<_>>();
Expand Down
6 changes: 2 additions & 4 deletions vortex-array/src/array/varbinview/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::array::varbinview::{VarBinViewArray, VIEW_SIZE};
use crate::compute::unary::ScalarAtFn;
use crate::compute::{slice, ArrayCompute, SliceFn};
use crate::validity::ArrayValidity;
use crate::{Array, ArrayDType, IntoArray, IntoArrayData};
use crate::{Array, ArrayDType, IntoArray};

impl ArrayCompute for VarBinViewArray {
fn scalar_at(&self) -> Option<&dyn ScalarAtFn> {
Expand All @@ -32,9 +32,7 @@ impl ScalarAtFn for VarBinViewArray {
impl SliceFn for VarBinViewArray {
fn slice(&self, start: usize, stop: usize) -> VortexResult<Array> {
Ok(Self::try_new(
slice(&self.views(), start * VIEW_SIZE, stop * VIEW_SIZE)?
.into_array_data()
.into_array(),
slice(&self.views(), start * VIEW_SIZE, stop * VIEW_SIZE)?,
(0..self.metadata().data_lens.len())
.map(|i| self.bytes(i))
.collect::<Vec<_>>(),
Expand Down
39 changes: 26 additions & 13 deletions vortex-array/src/array/varbinview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ mod variants;

#[derive(Clone, Copy, Debug)]
#[repr(C, align(8))]
struct Inlined {
pub struct Inlined {
lwwmanning marked this conversation as resolved.
Show resolved Hide resolved
size: u32,
data: [u8; BinaryView::MAX_INLINED_SIZE],
}

impl Inlined {
#[allow(dead_code)]
pub fn new(value: &[u8]) -> Self {
assert!(
value.len() <= BinaryView::MAX_INLINED_SIZE,
Expand All @@ -55,7 +54,7 @@ impl Inlined {

#[derive(Clone, Copy, Debug)]
#[repr(C, align(8))]
struct Ref {
pub struct Ref {
size: u32,
prefix: [u8; 4],
buffer_index: u32,
Expand Down Expand Up @@ -105,7 +104,8 @@ impl Debug for BinaryView {
}
}

pub const VIEW_SIZE: usize = mem::size_of::<BinaryView>();
// reminder: views are 16 bytes with 8-byte alignment
pub(crate) const VIEW_SIZE: usize = mem::size_of::<BinaryView>();

impl_encoding!("vortex.varbinview", 5u16, VarBinView);

Expand Down Expand Up @@ -140,10 +140,9 @@ impl VarBinViewArray {
vortex_bail!("incorrect validity {:?}", validity);
}

let length = views.len() / VIEW_SIZE;

let num_views = views.len() / VIEW_SIZE;
let metadata = VarBinViewMetadata {
validity: validity.to_metadata(views.len() / VIEW_SIZE)?,
validity: validity.to_metadata(num_views)?,
data_lens: data.iter().map(|a| a.len()).collect_vec(),
};

Expand All @@ -154,7 +153,7 @@ impl VarBinViewArray {
children.push(a)
}

Self::try_from_parts(dtype, length, metadata, children.into(), StatsSet::new())
Self::try_from_parts(dtype, num_views, metadata, children.into(), StatsSet::new())
}

fn view_slice(&self) -> &[BinaryView] {
Expand Down Expand Up @@ -195,9 +194,11 @@ impl VarBinViewArray {
))
}

const BUILDER_BLOCK_SIZE: u32 = 16 * 1024;
lwwmanning marked this conversation as resolved.
Show resolved Hide resolved
pub fn from_iter_str<T: AsRef<str>, I: IntoIterator<Item = T>>(iter: I) -> Self {
let iter = iter.into_iter();
let mut builder = StringViewBuilder::with_capacity(iter.size_hint().0);
let mut builder = StringViewBuilder::with_capacity(iter.size_hint().0)
.with_block_size(Self::BUILDER_BLOCK_SIZE);
for s in iter {
builder.append_value(s);
}
Expand All @@ -209,7 +210,8 @@ impl VarBinViewArray {
iter: I,
) -> Self {
let iter = iter.into_iter();
let mut builder = StringViewBuilder::with_capacity(iter.size_hint().0);
let mut builder = StringViewBuilder::with_capacity(iter.size_hint().0)
.with_block_size(Self::BUILDER_BLOCK_SIZE);
builder.extend(iter);

let array_data = ArrayData::from_arrow(&builder.finish(), true);
Expand All @@ -218,7 +220,8 @@ impl VarBinViewArray {

pub fn from_iter_bin<T: AsRef<[u8]>, I: IntoIterator<Item = T>>(iter: I) -> Self {
let iter = iter.into_iter();
let mut builder = BinaryViewBuilder::with_capacity(iter.size_hint().0);
let mut builder = BinaryViewBuilder::with_capacity(iter.size_hint().0)
.with_block_size(Self::BUILDER_BLOCK_SIZE);
for b in iter {
builder.append_value(b);
}
Expand All @@ -230,7 +233,8 @@ impl VarBinViewArray {
iter: I,
) -> Self {
let iter = iter.into_iter();
let mut builder = BinaryViewBuilder::with_capacity(iter.size_hint().0);
let mut builder = BinaryViewBuilder::with_capacity(iter.size_hint().0)
.with_block_size(Self::BUILDER_BLOCK_SIZE);
builder.extend(iter);
let array_data = ArrayData::from_arrow(&builder.finish(), true);
VarBinViewArray::try_from(array_data.into_array()).expect("should be var bin view array")
Expand Down Expand Up @@ -358,7 +362,7 @@ impl<'a> FromIterator<Option<&'a str>> for VarBinViewArray {
mod test {
use vortex_scalar::Scalar;

use crate::array::varbinview::VarBinViewArray;
use crate::array::varbinview::{BinaryView, Inlined, Ref, VarBinViewArray, VIEW_SIZE};
use crate::compute::slice;
use crate::compute::unary::scalar_at;
use crate::{Canonical, IntoArray, IntoCanonical};
Expand Down Expand Up @@ -404,4 +408,13 @@ mod test {
assert_eq!(scalar_at(&var_bin, 0).unwrap(), Scalar::from("string1"));
assert_eq!(scalar_at(&var_bin, 1).unwrap(), Scalar::from("string2"));
}

#[test]
pub fn binary_view_size_and_alignment() {
assert_eq!(std::mem::size_of::<Inlined>(), 16);
assert_eq!(std::mem::size_of::<Ref>(), 16);
assert_eq!(std::mem::size_of::<BinaryView>(), VIEW_SIZE);
assert_eq!(std::mem::size_of::<BinaryView>(), 16);
assert_eq!(std::mem::align_of::<BinaryView>(), 8);
}
}
1 change: 0 additions & 1 deletion vortex-array/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
//! Every data type recognized by Vortex also has a canonical physical encoding format, which
//! arrays can be [canonicalized](Canonical) into for ease of access in compute functions.
//!

use std::fmt::{Debug, Display, Formatter};
use std::future::ready;

Expand Down
2 changes: 2 additions & 0 deletions vortex-buffer/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![feature(allocator_api)]

use std::cmp::Ordering;
use std::ops::{Deref, Range};

Expand Down
2 changes: 2 additions & 0 deletions vortex-datafusion/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ mod test {
}

#[tokio::test]
#[cfg_attr(miri, ignore)]
async fn test_datafusion_pushdown() {
let ctx = SessionContext::new();

Expand Down Expand Up @@ -538,6 +539,7 @@ mod test {
}

#[tokio::test]
#[cfg_attr(miri, ignore)]
async fn test_datafusion_no_pushdown() {
let ctx = SessionContext::new();

Expand Down
1 change: 1 addition & 0 deletions vortex-sampling-compressor/tests/smoketest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use vortex_sampling_compressor::compressors::CompressorRef;
use vortex_sampling_compressor::{CompressConfig, SamplingCompressor};

#[test]
#[cfg_attr(miri, ignore)] // This test is too slow on miri
pub fn smoketest_compressor() {
let compressor = SamplingCompressor::new_with_options(
HashSet::from([
Expand Down
Loading