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

feat: makes Miri test happy for all codes #112

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 5 additions & 5 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use serde::de::{self, Expected, Unexpected};
use smallvec::SmallVec;

use super::reader::{Reader, Reference};
#[cfg(all(target_feature = "neon", target_arch = "aarch64"))]
#[cfg(all(target_feature = "neon", target_arch = "aarch64", not(miri)))]
use crate::util::simd::bits::NeonBits;
use crate::{
error::{
Expand Down Expand Up @@ -836,9 +836,9 @@ where
&mut self,
buf: &'own mut Vec<u8>,
) -> Result<Reference<'de, 'own, [u8]>> {
#[cfg(all(target_feature = "neon", target_arch = "aarch64"))]
#[cfg(all(target_feature = "neon", target_arch = "aarch64", not(miri)))]
let mut block: StringBlock<NeonBits>;
#[cfg(not(all(target_feature = "neon", target_arch = "aarch64")))]
#[cfg(not(all(target_feature = "neon", target_arch = "aarch64", not(miri))))]
let mut block: StringBlock<u32>;

self.parse_escaped_char(buf)?;
Expand Down Expand Up @@ -910,9 +910,9 @@ where
) -> Result<Reference<'de, 'own, [u8]>> {
// now reader is start after `"`, so we can directly skipstring
let start = self.read.index();
#[cfg(all(target_feature = "neon", target_arch = "aarch64"))]
#[cfg(all(target_feature = "neon", target_arch = "aarch64", not(miri)))]
let mut block: StringBlock<NeonBits>;
#[cfg(not(all(target_feature = "neon", target_arch = "aarch64")))]
#[cfg(not(all(target_feature = "neon", target_arch = "aarch64", not(miri))))]
let mut block: StringBlock<u32>;

while let Some(chunk) = self.read.peek_n(StringBlock::LANES) {
Expand Down
2 changes: 1 addition & 1 deletion src/util/arch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cfg_if::cfg_if! {
if #[cfg(all(target_arch = "x86_64", target_feature = "pclmulqdq", target_feature = "avx2", target_feature = "sse2"))] {
mod x86_64;
pub use x86_64::*;
} else if #[cfg(all(target_feature="neon", target_arch="aarch64"))] {
} else if #[cfg(all(target_feature="neon", target_arch="aarch64", not(miri)))] {
pub(crate) mod fallback;
mod aarch64;
pub use aarch64::*;
Expand Down
2 changes: 1 addition & 1 deletion src/util/simd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ cfg_if::cfg_if! {
if #[cfg(target_feature = "sse2")] {
mod sse2;
use self::sse2::*;
} else if #[cfg(all(target_feature="neon", target_arch="aarch64"))] {
} else if #[cfg(all(target_feature="neon", target_arch="aarch64", not(miri)))] {
pub(crate) mod neon;
use self::neon::*;
} else {
Expand Down
8 changes: 6 additions & 2 deletions src/util/simd/v128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pub struct Mask128([u8; 16]);

impl Simd for Simd128i {
const LANES: usize = 16;

type Element = i8;
type Mask = Mask128;

unsafe fn loadu(ptr: *const u8) -> Self {
Expand All @@ -38,8 +40,8 @@ impl Simd for Simd128i {
Mask128(mask)
}

fn splat(value: u8) -> Self {
Self([value as i8; Self::LANES])
fn splat(value: i8) -> Self {
Self([value; Self::LANES])
}

fn le(&self, rhs: &Self) -> Self::Mask {
Expand All @@ -61,6 +63,8 @@ impl Simd for Simd128i {

impl Simd for Simd128u {
const LANES: usize = 16;

type Element = u8;
type Mask = Mask128;

unsafe fn loadu(ptr: *const u8) -> Self {
Expand Down
2 changes: 1 addition & 1 deletion src/util/simd/v256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl Mask for Mask256 {
#[inline(always)]
fn bitmask(self) -> Self::BitMask {
cfg_if::cfg_if! {
if #[cfg(all(target_feature="neon", target_arch="aarch64"))] {
if #[cfg(all(target_feature="neon", target_arch="aarch64", not(miri)))] {
use std::arch::aarch64::uint8x16_t;
let(v0, v1) = self.0;
unsafe { super::neon::to_bitmask32(v0.0, v1.0) }
Expand Down
2 changes: 1 addition & 1 deletion src/util/simd/v512.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl Mask for Mask512 {
#[inline(always)]
fn bitmask(self) -> Self::BitMask {
cfg_if::cfg_if! {
if #[cfg(all(target_feature="neon", target_arch="aarch64"))] {
if #[cfg(all(target_feature="neon", target_arch="aarch64", not(miri)))] {
use std::arch::aarch64::uint8x16_t;
let (v0, v1) = self.0;
let (m0, m1) = v0.0;
Expand Down
24 changes: 12 additions & 12 deletions src/util/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use std::{
slice::{from_raw_parts, from_raw_parts_mut},
};

#[cfg(not(all(target_feature = "neon", target_arch = "aarch64")))]
#[cfg(not(all(target_feature = "neon", target_arch = "aarch64", not(miri))))]
use crate::util::simd::u8x32;
#[cfg(all(target_feature = "neon", target_arch = "aarch64"))]
#[cfg(all(target_feature = "neon", target_arch = "aarch64", not(miri)))]
use crate::util::simd::{bits::NeonBits, u8x16};
use crate::{
error::ErrorCode::{
Expand Down Expand Up @@ -37,7 +37,7 @@ pub(crate) struct StringBlock<B: BitMask> {
pub(crate) unescaped_bits: B,
}

#[cfg(not(all(target_feature = "neon", target_arch = "aarch64")))]
#[cfg(not(all(target_feature = "neon", target_arch = "aarch64", not(miri))))]
impl StringBlock<u32> {
pub(crate) const LANES: usize = 32;

Expand All @@ -51,7 +51,7 @@ impl StringBlock<u32> {
}
}

#[cfg(all(target_feature = "neon", target_arch = "aarch64"))]
#[cfg(all(target_feature = "neon", target_arch = "aarch64", not(miri)))]
impl StringBlock<NeonBits> {
pub(crate) const LANES: usize = 16;

Expand Down Expand Up @@ -108,9 +108,9 @@ pub(crate) unsafe fn load<V: Simd>(ptr: *const u8) -> V {
pub(crate) unsafe fn parse_string_inplace(
src: &mut *mut u8,
) -> std::result::Result<usize, ErrorCode> {
#[cfg(all(target_feature = "neon", target_arch = "aarch64"))]
#[cfg(all(target_feature = "neon", target_arch = "aarch64", not(miri)))]
let mut block: StringBlock<NeonBits>;
#[cfg(not(all(target_feature = "neon", target_arch = "aarch64")))]
#[cfg(not(all(target_feature = "neon", target_arch = "aarch64", not(miri))))]
let mut block: StringBlock<u32>;

let sdst = *src;
Expand Down Expand Up @@ -513,17 +513,17 @@ fn check_cross_page(ptr: *const u8, step: usize) -> bool {
pub fn format_string(value: &str, dst: &mut [MaybeUninit<u8>], need_quote: bool) -> usize {
assert!(dst.len() >= value.len() * 6 + 32 + 3);

#[cfg(all(target_arch = "aarch64", target_feature = "neon"))]
#[cfg(all(target_arch = "aarch64", target_feature = "neon", not(miri)))]
let mut v: u8x16;
#[cfg(not(all(target_arch = "aarch64", target_feature = "neon")))]
#[cfg(not(all(target_arch = "aarch64", target_feature = "neon", not(miri))))]
let mut v: u8x32;

#[cfg(all(target_arch = "aarch64", target_feature = "neon"))]
#[cfg(all(target_arch = "aarch64", target_feature = "neon", not(miri)))]
const LANES: usize = 16;
#[cfg(not(all(target_arch = "aarch64", target_feature = "neon")))]
#[cfg(not(all(target_arch = "aarch64", target_feature = "neon", not(miri))))]
const LANES: usize = 32;

#[cfg(all(target_arch = "aarch64", target_feature = "neon"))]
#[cfg(all(target_arch = "aarch64", target_feature = "neon", not(miri)))]
#[inline]
fn escaped_mask(v: u8x16) -> NeonBits {
let x1f = u8x16::splat(0x1f); // 0x00 ~ 0x20
Expand All @@ -533,7 +533,7 @@ pub fn format_string(value: &str, dst: &mut [MaybeUninit<u8>], need_quote: bool)
v.bitmask()
}

#[cfg(not(all(target_arch = "aarch64", target_feature = "neon")))]
#[cfg(not(all(target_arch = "aarch64", target_feature = "neon", not(miri))))]
#[inline]
fn escaped_mask(v: u8x32) -> u32 {
let x1f = u8x32::splat(0x1f); // 0x00 ~ 0x20
Expand Down
13 changes: 13 additions & 0 deletions src/util/utf8.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::error::{Error, ErrorCode, Result};

#[cfg(not(miri))]
#[inline(always)]
pub(crate) fn from_utf8(data: &[u8]) -> Result<&str> {
match simdutf8::basic::from_utf8(data) {
Expand All @@ -11,6 +12,18 @@ pub(crate) fn from_utf8(data: &[u8]) -> Result<&str> {
}
}

#[cfg(miri)]
pub(crate) fn from_utf8(data: &[u8]) -> Result<&str> {
match std::str::from_utf8(data) {
Ok(ret) => Ok(ret),
Err(err) => Err(Error::syntax(
ErrorCode::InvalidUTF8,
data,
err.valid_up_to(),
)),
}
}

#[cold]
fn from_utf8_compat(data: &[u8]) -> Result<&str> {
// compat::from_utf8 is slower than basic::from_utf8
Expand Down