Skip to content

Commit

Permalink
Add miri to CI, fixup text tape pointer arithmetic
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbabcock committed Dec 15, 2023
1 parent 797c26e commit f3ce1ed
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,14 @@ jobs:
- name: Compile benchmarks
if: matrix.build == 'stable'
run: cargo bench --verbose --no-run $TARGET


- name: Run miri
if: matrix.build == 'nightly'
run: |
rustup toolchain install nightly --component miri
cargo miri setup
MIRIFLAGS="-Zmiri-disable-stacked-borrows" cargo miri test
- name: Compile fuzz
if: matrix.build == 'nightly'
run: |
Expand Down
23 changes: 12 additions & 11 deletions src/text/tape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ fn split_at_scalar(d: &[u8]) -> (Scalar, &[u8]) {
use core::arch::x86_64::*;
let start_ptr = d.as_ptr();
let loop_size = std::mem::size_of::<__m128i>();
let end_ptr = d[d.len()..].as_ptr().sub(loop_size);
let end_ptr = d.as_ptr_range().end.sub(loop_size.min(d.len()));
let mut ptr = start_ptr;

// Here we use SIMD instructions to detect certain bytes.
Expand Down Expand Up @@ -357,7 +357,7 @@ fn split_at_scalar(d: &[u8]) -> (Scalar, &[u8]) {
// { = 0x7b
// } = 0x7d
// * = unknown if boundary character. Can be removed for perf
while ptr <= end_ptr {
while ptr < end_ptr {
let input = _mm_loadu_si128(ptr as *const __m128i);
let t0 = _mm_cmpeq_epi8(input, _mm_set1_epi8(9));
let mut result = t0;
Expand Down Expand Up @@ -439,25 +439,26 @@ impl<'a, 'b> ParserState<'a, 'b> {
#[inline]
fn skip_ws_t(&mut self, data: &'a [u8]) -> Option<&'a [u8]> {
unsafe {
let start_ptr = data.as_ptr();
let end_ptr = start_ptr.add(data.len());

let start_ptr = data.as_ptr_range().start;
let end_ptr = data.as_ptr_range().end;
let mut ptr = start_ptr;
while ptr < end_ptr {
match *ptr {
b' ' | b'\t' | b'\n' | b'\r' | b';' => {}
b'#' => {
ptr = ptr.offset(1);
while ptr < end_ptr && *ptr != b'\n' {
ptr = ptr.offset(1);
b'#' => loop {
ptr = ptr.add(1);
if ptr == end_ptr {
return None;
} else if *ptr == b'\n' {
break;
}
}
},
_ => {
let rest = std::slice::from_raw_parts(ptr, sub(end_ptr, ptr));
return Some(rest);
}
}
ptr = ptr.offset(1);
ptr = ptr.add(1);
}
}

Expand Down

0 comments on commit f3ce1ed

Please sign in to comment.