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

iex #385

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft

iex #385

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
19 changes: 9 additions & 10 deletions .github/workflows/quality.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ on:
branches:
- main


jobs:
clippy_check:
strategy:
Expand All @@ -19,48 +18,48 @@ jobs:
steps:
- uses: actions/checkout@v3

- uses: dtolnay/rust-toolchain@1.72 # do clippy chekcs with the minimum supported version
- uses: dtolnay/rust-toolchain@1.80 # do clippy chekcs with the minimum supported version
with:
components: rustfmt, clippy

- name: Validate cargo format
run: cargo fmt -- --check

- name: Run tests
- name: Run tests
env:
RUSTFLAGS: "-C target-cpu=native ${{ matrix.rustflags }}"
run: cargo clippy

- name: Run tests (no-default-features)
env:
RUSTFLAGS: "-C target-cpu=native ${{ matrix.rustflags }}"
run: cargo clippy

- name: Run tests (value-no-dup-keys)
env:
RUSTFLAGS: "-C target-cpu=native ${{ matrix.rustflags }}"
run: cargo clippy --features value-no-dup-keys

- name: Run tests (known-key)
env:
RUSTFLAGS: "-C target-cpu=native ${{ matrix.rustflags }}"
run: cargo clippy --features known-key

- name: Run tests (128bit)
env:
RUSTFLAGS: "-C target-cpu=native ${{ matrix.rustflags }}"
run: cargo clippy --features 128bit

- name: Run tests (beef)
env:
RUSTFLAGS: "-C target-cpu=native ${{ matrix.rustflags }}"
run: cargo clippy --features beef

- name: Run tests (arraybackend)
env:
RUSTFLAGS: "-C target-cpu=native ${{ matrix.rustflags }}"
run: cargo clippy --features arraybackend

- name: Run tests (approx-number-parsing)
env:
RUSTFLAGS: "-C target-cpu=native ${{ matrix.rustflags }}"
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ description = "High performance JSON parser based on a port of simdjson"
repository = "https://github.com/simd-lite/simd-json"
readme = "README.md"
documentation = "https://docs.rs/simd-json"
rust-version = "1.64"
rust-version = "1.80"

[target.'cfg(target_family = "wasm")'.dependencies]
getrandom = { version = "0.2", features = ["js"] }
Expand All @@ -34,6 +34,7 @@ colored = { version = "2.0", optional = true }
getopts = { version = "0.2", optional = true }
jemallocator = { version = "0.5", optional = true }
perfcnt = { version = "0.8", optional = true }
iex = { version = "0.2", optional = false }

ref-cast = "1.0"

Expand Down
3 changes: 2 additions & 1 deletion src/impls/avx2/deser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ use crate::{
Deserializer, Result, SillyWrapper,
};

#[target_feature(enable = "avx2")]
#[allow(
clippy::if_not_else,
clippy::cast_possible_wrap,
clippy::too_many_lines
)]
#[cfg_attr(not(feature = "no-inline"), inline)]
#[iex::iex]
#[target_feature(enable = "avx2")]
pub(crate) unsafe fn parse_str<'invoke, 'de>(
input: SillyWrapper<'de>,
data: &'invoke [u8],
Expand Down
1 change: 1 addition & 0 deletions src/impls/native/deser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{
};

#[allow(clippy::cast_possible_truncation)]
#[iex::iex]
pub(crate) unsafe fn parse_str<'invoke, 'de>(
input: SillyWrapper<'de>,
data: &'invoke [u8],
Expand Down
12 changes: 6 additions & 6 deletions src/impls/neon/deser.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use iex::Outcome;

use crate::error::ErrorType;
use crate::impls::neon::stage1::bit_mask;
use crate::safer_unchecked::GetSaferUnchecked;
Expand Down Expand Up @@ -42,6 +44,7 @@ fn find_bs_bits_and_quote_bits(v0: uint8x16_t, v1: uint8x16_t) -> (u32, u32) {

#[allow(clippy::if_not_else, clippy::too_many_lines)]
#[cfg_attr(not(feature = "no-inline"), inline)]
#[iex::iex]
pub(crate) fn parse_str<'invoke, 'de>(
input: SillyWrapper<'de>,
data: &'invoke [u8],
Expand Down Expand Up @@ -168,14 +171,11 @@ pub(crate) fn parse_str<'invoke, 'de>(
// within the unicode codepoint handling code.
src_i += bs_dist as usize;
dst_i += bs_dist as usize;
let (o, s) = if let Ok(r) =
let (o, s) =
handle_unicode_codepoint(unsafe { src.get_kinda_unchecked(src_i..) }, unsafe {
buffer.get_kinda_unchecked_mut(dst_i..)
}) {
r
} else {
return Err(Deserializer::error_c(src_i, 'u', InvalidUnicodeCodepoint));
};
})
.map_err(|_| Deserializer::error_c(src_i, 'u', InvalidUnicodeCodepoint))?;
if o == 0 {
return Err(Deserializer::error_c(src_i, 'u', InvalidUnicodeCodepoint));
};
Expand Down
1 change: 1 addition & 0 deletions src/impls/portable/deser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::{
};

#[cfg_attr(not(feature = "no-inline"), inline)]
#[iex::iex]
pub(crate) unsafe fn parse_str<'invoke, 'de>(
input: SillyWrapper<'de>,
data: &'invoke [u8],
Expand Down
1 change: 1 addition & 0 deletions src/impls/simd128/deser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::{
clippy::too_many_lines
)]
#[cfg_attr(not(feature = "no-inline"), inline)]
#[iex::iex]
pub(crate) fn parse_str<'invoke, 'de>(
input: SillyWrapper<'de>,
data: &'invoke [u8],
Expand Down
1 change: 1 addition & 0 deletions src/impls/sse42/deser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use arch::{
#[target_feature(enable = "sse4.2")]
#[allow(clippy::if_not_else, clippy::cast_possible_wrap)]
#[cfg_attr(not(feature = "no-inline"), inline)]
#[iex::iex]
pub(crate) unsafe fn parse_str<'invoke, 'de>(
input: SillyWrapper<'de>,
data: &'invoke [u8],
Expand Down
31 changes: 21 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ mod numberparse;
mod safer_unchecked;
mod stringparse;

use iex::Outcome;
use safer_unchecked::GetSaferUnchecked;
use stage2::StackState;

Expand Down Expand Up @@ -225,7 +226,9 @@ pub fn to_tape(s: &mut [u8]) -> Result<Tape> {
/// Will return `Err` if `s` is invalid JSON.
#[cfg_attr(not(feature = "no-inline"), inline)]
pub fn to_tape_with_buffers<'de>(s: &'de mut [u8], buffers: &mut Buffers) -> Result<Tape<'de>> {
Deserializer::from_slice_with_buffers(s, buffers).map(Deserializer::into_tape)
Deserializer::from_slice_with_buffers(s, buffers)
.into_result()
.map(Deserializer::into_tape)
}

/// Fills a already existing tape from the input for later consumption
Expand All @@ -235,7 +238,7 @@ pub fn to_tape_with_buffers<'de>(s: &'de mut [u8], buffers: &mut Buffers) -> Res
#[cfg_attr(not(feature = "no-inline"), inline)]
pub fn fill_tape<'de>(s: &'de mut [u8], buffers: &mut Buffers, tape: &mut Tape<'de>) -> Result<()> {
tape.0.clear();
Deserializer::fill_tape(s, buffers, &mut tape.0)
Deserializer::fill_tape(s, buffers, &mut tape.0).into_result()
}

pub(crate) trait Stage1Parse {
Expand Down Expand Up @@ -547,6 +550,7 @@ impl<'de> Deserializer<'de> {
feature = "runtime-detection",
any(target_arch = "x86_64", target_arch = "x86"),
))]
#[iex::iex]
pub(crate) unsafe fn parse_str_<'invoke>(
input: *mut u8,
data: &'invoke [u8],
Expand Down Expand Up @@ -606,6 +610,7 @@ impl<'de> Deserializer<'de> {
target_feature = "simd128",
target_arch = "aarch64",
)))]
#[iex::iex]
pub(crate) unsafe fn parse_str_<'invoke>(
input: *mut u8,
data: &'invoke [u8],
Expand All @@ -620,6 +625,7 @@ impl<'de> Deserializer<'de> {
}
#[cfg_attr(not(feature = "no-inline"), inline)]
#[cfg(all(feature = "portable", not(feature = "runtime-detection")))]
#[iex::iex]
pub(crate) unsafe fn parse_str_<'invoke>(
input: *mut u8,
data: &'invoke [u8],
Expand All @@ -639,6 +645,7 @@ impl<'de> Deserializer<'de> {
not(feature = "portable"),
not(feature = "runtime-detection"),
))]
#[iex::iex]
pub(crate) unsafe fn parse_str_<'invoke>(
input: *mut u8,
data: &'invoke [u8],
Expand All @@ -656,6 +663,7 @@ impl<'de> Deserializer<'de> {
not(feature = "runtime-detection"),
not(feature = "portable"),
))]
#[iex::iex]
pub(crate) unsafe fn parse_str_<'invoke>(
input: *mut u8,
data: &'invoke [u8],
Expand All @@ -668,6 +676,7 @@ impl<'de> Deserializer<'de> {

#[cfg_attr(not(feature = "no-inline"), inline)]
#[cfg(all(target_arch = "aarch64", not(feature = "portable")))]
#[iex::iex]
pub(crate) unsafe fn parse_str_<'invoke>(
input: *mut u8,
data: &'invoke [u8],
Expand All @@ -679,6 +688,7 @@ impl<'de> Deserializer<'de> {
}
#[cfg_attr(not(feature = "no-inline"), inline)]
#[cfg(all(target_feature = "simd128", not(feature = "portable")))]
#[iex::iex]
pub(crate) unsafe fn parse_str_<'invoke>(
input: *mut u8,
data: &'invoke [u8],
Expand Down Expand Up @@ -842,7 +852,7 @@ impl<'de> Deserializer<'de> {

let mut buffer = Buffers::new(len);

Self::from_slice_with_buffers(input, &mut buffer)
Self::from_slice_with_buffers(input, &mut buffer).into_result()
}

/// Fills the tape without creating a serializer, this function poses
Expand All @@ -854,6 +864,7 @@ impl<'de> Deserializer<'de> {
/// Will return `Err` if `input` is invalid JSON.
#[allow(clippy::uninit_vec)]
#[cfg_attr(not(feature = "no-inline"), inline)]
#[iex::iex(captures = "'de")]
fn fill_tape(
input: &'de mut [u8],
buffer: &mut Buffers,
Expand Down Expand Up @@ -905,7 +916,8 @@ impl<'de> Deserializer<'de> {
&buffer.structural_indexes,
&mut buffer.stage2_stack,
tape,
)
)?;
Ok(())
}

/// Creates a serializer from a mutable slice of bytes using a temporary
Expand All @@ -914,6 +926,7 @@ impl<'de> Deserializer<'de> {
/// # Errors
///
/// Will return `Err` if `s` is invalid JSON.
#[iex::iex]
pub fn from_slice_with_buffers(input: &'de mut [u8], buffer: &mut Buffers) -> Result<Self> {
let mut tape: Vec<Node<'de>> = Vec::with_capacity(buffer.structural_indexes.len());

Expand Down Expand Up @@ -1113,16 +1126,14 @@ impl AlignedBuf {
/// Creates a new buffer that is aligned with the simd register size
#[must_use]
pub fn with_capacity(capacity: usize) -> Self {
let layout = match Layout::from_size_align(capacity, SIMDJSON_PADDING) {
Ok(layout) => layout,
Err(_) => Self::capacity_overflow(),
let Ok(layout) = Layout::from_size_align(capacity, SIMDJSON_PADDING) else {
Self::capacity_overflow()
};
if mem::size_of::<usize>() < 8 && capacity > isize::MAX as usize {
Self::capacity_overflow()
}
let inner = match unsafe { NonNull::new(alloc(layout)) } {
Some(ptr) => ptr,
None => handle_alloc_error(layout),
let Some(inner) = NonNull::new(unsafe { alloc(layout) }) else {
handle_alloc_error(layout)
};
Self {
layout,
Expand Down
13 changes: 0 additions & 13 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1298,19 +1298,6 @@ macro_rules! static_cast_u64 {
};
}

/// FROM serde-json
/// We only use our own error type; no need for From conversions provided by the
/// standard library's try! macro. This reduces lines of LLVM IR by 4%.
#[macro_export]
macro_rules! stry {
($e:expr) => {
match $e {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => return ::std::result::Result::Err(err),
}
};
}

#[cfg(test)]
mod test {
use crate::prelude::*;
Expand Down
4 changes: 4 additions & 0 deletions src/numberparse/approx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ impl<'de> Deserializer<'de> {
clippy::cast_precision_loss,
clippy::too_many_lines
)]
#[iex::iex]
fn parse_float(idx: usize, p: &[u8], negative: bool) -> Result<StaticNode> {
let mut digitcount = usize::from(negative);
let mut i: f64;
Expand Down Expand Up @@ -222,6 +223,7 @@ impl<'de> Deserializer<'de> {
#[cfg(not(feature = "128bit"))]
#[inline(never)]
#[allow(clippy::cast_possible_wrap)]
#[iex::iex]
fn parse_large_integer(idx: usize, buf: &[u8], negative: bool) -> Result<StaticNode> {
let mut digitcount = usize::from(negative);
let mut i: u64;
Expand Down Expand Up @@ -283,6 +285,7 @@ impl<'de> Deserializer<'de> {
#[cfg(feature = "128bit")]
#[inline(never)]
#[allow(clippy::cast_possible_wrap)]
#[iex::iex]
fn parse_large_integer(idx: usize, buf: &[u8], negative: bool) -> Result<StaticNode> {
let mut digitcount = usize::from(negative);
let mut i: u128;
Expand Down Expand Up @@ -358,6 +361,7 @@ impl<'de> Deserializer<'de> {
clippy::cast_possible_wrap,
clippy::too_many_lines
)]
#[iex::iex]
pub(crate) fn parse_number(idx: usize, buf: &[u8], negative: bool) -> Result<StaticNode> {
let buf = unsafe { buf.get_kinda_unchecked(idx..) };
let mut byte_count = usize::from(negative);
Expand Down
Loading
Loading