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

chore: added rustfmt.toml #137

Merged
merged 2 commits into from
May 22, 2023
Merged
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
4 changes: 3 additions & 1 deletion crates/rsonpath-lib/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ fn main() -> eyre::Result<()> {
}
}

Err(eyre::eyre!("Target architecture is not supported by SIMD features of this crate. Disable the default `simd` feature."))
Err(eyre::eyre!(
"Target architecture is not supported by SIMD features of this crate. Disable the default `simd` feature."
))
}
#[cfg(not(feature = "simd"))]
{
Expand Down
12 changes: 3 additions & 9 deletions crates/rsonpath-lib/src/classification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ pub struct ResumeClassifierBlockState<'a, I: Input + 'a, const N: usize> {
pub idx: usize,
}

impl<'a, I: Input, Q: QuoteClassifiedIterator<'a, I, N>, const N: usize>
ResumeClassifierState<'a, I, Q, N>
{
impl<'a, I: Input, Q: QuoteClassifiedIterator<'a, I, N>, const N: usize> ResumeClassifierState<'a, I, Q, N> {
/// Get the index in the original bytes input at which classification has stopped.
#[inline(always)]
pub fn get_idx(&self) -> usize {
Expand Down Expand Up @@ -118,8 +116,7 @@ impl<'a, I: Input, Q: QuoteClassifiedIterator<'a, I, N>, const N: usize>
_ => {
let blocks_to_advance = (count - remaining_in_block) / N;

let remainder =
(self.block.as_ref().map_or(0, |b| b.idx) + count - blocks_to_advance * N) % N;
let remainder = (self.block.as_ref().map_or(0, |b| b.idx) + count - blocks_to_advance * N) % N;

self.iter.offset(blocks_to_advance as isize);
let next_block = self.iter.next();
Expand All @@ -131,9 +128,6 @@ impl<'a, I: Input, Q: QuoteClassifiedIterator<'a, I, N>, const N: usize>
}
}

debug!(
"offset_bytes({count}) results in idx moved to {}",
self.get_idx()
);
debug!("offset_bytes({count}) results in idx moved to {}", self.get_idx());
}
}
14 changes: 3 additions & 11 deletions crates/rsonpath-lib/src/classification/depth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,13 @@ pub trait DepthBlock<'a>: Sized {

/// Trait for depth iterators, i.e. finite iterators returning depth information
/// about JSON documents.
pub trait DepthIterator<'a, I: Input, Q, const N: usize>:
Iterator<Item = Self::Block> + 'a
{
pub trait DepthIterator<'a, I: Input, Q, const N: usize>: Iterator<Item = Self::Block> + 'a {
/// Type of the [`DepthBlock`] implementation used by this iterator.
type Block: DepthBlock<'a>;

/// Resume classification from a state retrieved by a previous
/// [`DepthIterator::stop`] or [`StructuralIterator::stop`](`crate::classification::structural::StructuralIterator::stop`) invocation.
fn resume(
state: ResumeClassifierState<'a, I, Q, N>,
opening: BracketType,
) -> (Option<Self::Block>, Self);
fn resume(state: ResumeClassifierState<'a, I, Q, N>, opening: BracketType) -> (Option<Self::Block>, Self);

/// Stop classification and return a state object that can be used to resume
/// a classifier from the place in which the current one was stopped.
Expand Down Expand Up @@ -165,10 +160,7 @@ cfg_if! {

/// Enrich quote classified blocks with depth information.
#[inline(always)]
pub fn classify_depth<'a, I, Q>(
iter: Q,
opening: BracketType,
) -> impl DepthIterator<'a, I, Q, BLOCK_SIZE>
pub fn classify_depth<'a, I, Q>(iter: Q, opening: BracketType) -> impl DepthIterator<'a, I, Q, BLOCK_SIZE>
where
I: Input + 'a,
Q: QuoteClassifiedIterator<'a, I, BLOCK_SIZE>,
Expand Down
34 changes: 9 additions & 25 deletions crates/rsonpath-lib/src/classification/depth/avx2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ impl<'a, I: Input, Q: QuoteClassifiedIterator<'a, I, 64>> Iterator for VectorIte
}
}

impl<'a, I: Input, Q: QuoteClassifiedIterator<'a, I, 64>> DepthIterator<'a, I, Q, 64>
for VectorIterator<'a, I, Q>
{
impl<'a, I: Input, Q: QuoteClassifiedIterator<'a, I, 64>> DepthIterator<'a, I, Q, 64> for VectorIterator<'a, I, Q> {
type Block = Vector<'a, I>;

fn stop(self, block: Option<Self::Block>) -> ResumeClassifierState<'a, I, Q, 64> {
Expand All @@ -80,10 +78,7 @@ impl<'a, I: Input, Q: QuoteClassifiedIterator<'a, I, 64>> DepthIterator<'a, I, Q
}
}

fn resume(
state: ResumeClassifierState<'a, I, Q, 64>,
opening: BracketType,
) -> (Option<Self::Block>, Self) {
fn resume(state: ResumeClassifierState<'a, I, Q, 64>, opening: BracketType) -> (Option<Self::Block>, Self) {
let classifier = DelimiterClassifierImpl::new(opening);
let first_block = state.block.and_then(|b| {
if b.idx == 64 {
Expand Down Expand Up @@ -116,10 +111,7 @@ impl<'a, I: Input, Q: QuoteClassifiedIterator<'a, I, 64>> DepthIterator<'a, I, Q
/// more quickly than precise depth calculation.
#[cfg_attr(
docsrs,
doc(cfg(all(
target_feature = "avx2",
any(target_arch = "x86", target_arch = "x86_64")
)))
doc(cfg(all(target_feature = "avx2", any(target_arch = "x86", target_arch = "x86_64"))))
)]

pub(crate) struct Vector<'a, I: Input + 'a> {
Expand All @@ -133,10 +125,7 @@ pub(crate) struct Vector<'a, I: Input + 'a> {

impl<'a, I: Input> Vector<'a, I> {
#[inline]
fn new(
bytes: QuoteClassifiedBlock<IBlock<'a, I, 64>, 64>,
classifier: &DelimiterClassifierImpl,
) -> Self {
fn new(bytes: QuoteClassifiedBlock<IBlock<'a, I, 64>, 64>, classifier: &DelimiterClassifierImpl) -> Self {
Self::new_from(bytes, classifier, 0)
}

Expand All @@ -159,20 +148,16 @@ impl<'a, I: Input> Vector<'a, I> {
) -> Self {
let idx_mask = 0xFFFF_FFFF_FFFF_FFFF_u64 << start_idx;
let (first_block, second_block) = bytes.block.halves();
let (first_opening_vector, first_closing_vector) =
classifier.get_opening_and_closing_vectors(first_block);
let (second_opening_vector, second_closing_vector) =
classifier.get_opening_and_closing_vectors(second_block);
let (first_opening_vector, first_closing_vector) = classifier.get_opening_and_closing_vectors(first_block);
let (second_opening_vector, second_closing_vector) = classifier.get_opening_and_closing_vectors(second_block);

let first_opening_mask = _mm256_movemask_epi8(first_opening_vector) as u32;
let first_closing_mask = _mm256_movemask_epi8(first_closing_vector) as u32;
let second_opening_mask = _mm256_movemask_epi8(second_opening_vector) as u32;
let second_closing_mask = _mm256_movemask_epi8(second_closing_vector) as u32;

let combined_opening_mask =
u64::from(first_opening_mask) | (u64::from(second_opening_mask) << 32);
let combined_closing_mask =
u64::from(first_closing_mask) | (u64::from(second_closing_mask) << 32);
let combined_opening_mask = u64::from(first_opening_mask) | (u64::from(second_opening_mask) << 32);
let combined_closing_mask = u64::from(first_closing_mask) | (u64::from(second_closing_mask) << 32);

let opening_mask = combined_opening_mask & (!bytes.within_quotes_mask) & idx_mask;
let closing_mask = combined_closing_mask & (!bytes.within_quotes_mask) & idx_mask;
Expand Down Expand Up @@ -229,8 +214,7 @@ impl<'a, I: Input> DepthBlock<'a> for Vector<'a, I> {

#[inline(always)]
fn depth_at_end(&self) -> isize {
(((self.opening_count as i32) - (self.closing_mask.count_ones() as i32)) + self.depth)
as isize
(((self.opening_count as i32) - (self.closing_mask.count_ones() as i32)) + self.depth) as isize
}

#[inline(always)]
Expand Down
24 changes: 5 additions & 19 deletions crates/rsonpath-lib/src/classification/depth/nosimd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ impl<'a, I: Input, Q, const N: usize> VectorIterator<'a, I, Q, N> {
}
}

impl<'a, I: Input, Q: QuoteClassifiedIterator<'a, I, N>, const N: usize> Iterator
for VectorIterator<'a, I, Q, N>
{
impl<'a, I: Input, Q: QuoteClassifiedIterator<'a, I, N>, const N: usize> Iterator for VectorIterator<'a, I, Q, N> {
type Item = Vector<'a, I, N>;

fn next(&mut self) -> Option<Self::Item> {
Expand Down Expand Up @@ -61,13 +59,8 @@ impl<'a, I: Input, Q: QuoteClassifiedIterator<'a, I, N>, const N: usize> DepthIt
}
}

fn resume(
state: ResumeClassifierState<'a, I, Q, N>,
opening: BracketType,
) -> (Option<Self::Block>, Self) {
let first_block = state
.block
.map(|b| Vector::new_from(b.block, opening, b.idx));
fn resume(state: ResumeClassifierState<'a, I, Q, N>, opening: BracketType) -> (Option<Self::Block>, Self) {
let first_block = state.block.map(|b| Vector::new_from(b.block, opening, b.idx));

(
first_block,
Expand All @@ -91,19 +84,12 @@ pub(crate) struct Vector<'a, I: Input + 'a, const N: usize> {

impl<'a, I: Input, const N: usize> Vector<'a, I, N> {
#[inline]
pub(crate) fn new(
bytes: QuoteClassifiedBlock<IBlock<'a, I, N>, N>,
opening: BracketType,
) -> Self {
pub(crate) fn new(bytes: QuoteClassifiedBlock<IBlock<'a, I, N>, N>, opening: BracketType) -> Self {
Self::new_from(bytes, opening, 0)
}

#[inline]
fn new_from(
bytes: QuoteClassifiedBlock<IBlock<'a, I, N>, N>,
opening: BracketType,
idx: usize,
) -> Self {
fn new_from(bytes: QuoteClassifiedBlock<IBlock<'a, I, N>, N>, opening: BracketType, idx: usize) -> Self {
Self {
quote_classified: bytes,
depth: 0,
Expand Down
4 changes: 1 addition & 3 deletions crates/rsonpath-lib/src/classification/quotes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ cfg_if! {
/// and classify quoted sequences.
#[must_use]
#[inline(always)]
pub fn classify_quoted_sequences<I: Input>(
bytes: &I,
) -> impl QuoteClassifiedIterator<I, BLOCK_SIZE> {
pub fn classify_quoted_sequences<I: Input>(bytes: &I) -> impl QuoteClassifiedIterator<I, BLOCK_SIZE> {
ClassifierImpl::new(bytes)
}
19 changes: 6 additions & 13 deletions crates/rsonpath-lib/src/classification/quotes/avx2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ impl<'a, I: Input> Avx2QuoteClassifier<'a, I> {
}

impl<'a, I: Input> Iterator for Avx2QuoteClassifier<'a, I> {
type Item = QuoteClassifiedBlock<
<<I as Input>::BlockIterator<'a, 64> as InputBlockIterator<'a, 64>>::Block,
64,
>;
type Item = QuoteClassifiedBlock<<<I as Input>::BlockIterator<'a, 64> as InputBlockIterator<'a, 64>>::Block, 64>;

#[inline(always)]
fn next(&mut self) -> Option<Self::Item> {
Expand Down Expand Up @@ -122,11 +119,9 @@ struct BlockClassification {

impl BlockAvx2Classifier {
/// Bitmask selecting bits on even positions when indexing from zero.
const ODD: u64 =
0b0101_0101_0101_0101_0101_0101_0101_0101_0101_0101_0101_0101_0101_0101_0101_0101_u64;
const ODD: u64 = 0b0101_0101_0101_0101_0101_0101_0101_0101_0101_0101_0101_0101_0101_0101_0101_0101_u64;
/// Bitmask selecting bits on odd positions when indexing from zero.
const EVEN: u64 =
0b1010_1010_1010_1010_1010_1010_1010_1010_1010_1010_1010_1010_1010_1010_1010_1010_u64;
const EVEN: u64 = 0b1010_1010_1010_1010_1010_1010_1010_1010_1010_1010_1010_1010_1010_1010_1010_1010_u64;

/// Set the inter-block state based on slash overflow and the quotes mask.
fn update_prev_block_mask(&mut self, set_slash_mask: bool, quotes: u64) {
Expand Down Expand Up @@ -191,8 +186,7 @@ impl BlockAvx2Classifier {

// Masks are combined by shifting the latter block's 32-bit masks left by 32 bits.
// From now on when we refer to a "block" we mean the combined 64 bytes of the input.
let slashes =
u64::from(classification1.slashes) | (u64::from(classification2.slashes) << 32);
let slashes = u64::from(classification1.slashes) | (u64::from(classification2.slashes) << 32);
let quotes = u64::from(classification1.quotes) | (u64::from(classification2.quotes) << 32);

let (escaped, set_prev_slash_mask) = if slashes == 0 {
Expand Down Expand Up @@ -273,9 +267,8 @@ impl BlockAvx2Classifier {
* prev_slash | 00000000 10000000 |
* escaped | 01000000 10000100 |
*/
let escaped = (ends_of_odd_starts & Self::EVEN)
| (ends_of_even_starts & Self::ODD)
| self.get_prev_slash_mask();
let escaped =
(ends_of_odd_starts & Self::EVEN) | (ends_of_even_starts & Self::ODD) | self.get_prev_slash_mask();

(escaped, set_prev_slash_mask)
};
Expand Down
9 changes: 2 additions & 7 deletions crates/rsonpath-lib/src/classification/quotes/nosimd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,9 @@ impl<'a, I: Input, const N: usize> Iterator for SequentialQuoteClassifier<'a, I,
}
}

impl<'a, I: Input, const N: usize> std::iter::FusedIterator
for SequentialQuoteClassifier<'a, I, N>
{
}
impl<'a, I: Input, const N: usize> std::iter::FusedIterator for SequentialQuoteClassifier<'a, I, N> {}

impl<'a, I: Input, const N: usize> QuoteClassifiedIterator<'a, I, N>
for SequentialQuoteClassifier<'a, I, N>
{
impl<'a, I: Input, const N: usize> QuoteClassifiedIterator<'a, I, N> for SequentialQuoteClassifier<'a, I, N> {
fn get_offset(&self) -> usize {
self.offset.unwrap_or(0)
}
Expand Down
16 changes: 3 additions & 13 deletions crates/rsonpath-lib/src/classification/structural.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,7 @@ impl Structural {

/// Trait for classifier iterators, i.e. finite iterators of [`Structural`] characters
/// that hold a reference to the JSON document valid for `'a`.
pub trait StructuralIterator<'a, I: Input, Q, const N: usize>:
Iterator<Item = Structural> + 'a
{
pub trait StructuralIterator<'a, I: Input, Q, const N: usize>: Iterator<Item = Structural> + 'a {
/// Stop classification and return a state object that can be used to resume
/// a classifier from the place in which the current one was stopped.
fn stop(self) -> ResumeClassifierState<'a, I, Q, N>;
Expand Down Expand Up @@ -208,11 +206,7 @@ cfg_if! {
/// Walk through the JSON document represented by `bytes` and iterate over all
/// occurrences of structural characters in it.
#[inline(always)]
pub fn classify_structural_characters<
'a,
I: Input + 'a,
Q: QuoteClassifiedIterator<'a, I, BLOCK_SIZE>,
>(
pub fn classify_structural_characters<'a, I: Input + 'a, Q: QuoteClassifiedIterator<'a, I, BLOCK_SIZE>>(
iter: Q,
) -> impl StructuralIterator<'a, I, Q, BLOCK_SIZE> {
ClassifierImpl::new(iter)
Expand All @@ -221,11 +215,7 @@ pub fn classify_structural_characters<
/// Resume classification using a state retrieved from a previously
/// used classifier via the `stop` function.
#[inline(always)]
pub fn resume_structural_classification<
'a,
I: Input,
Q: QuoteClassifiedIterator<'a, I, BLOCK_SIZE>,
>(
pub fn resume_structural_classification<'a, I: Input, Q: QuoteClassifiedIterator<'a, I, BLOCK_SIZE>>(
state: ResumeClassifierState<'a, I, Q, BLOCK_SIZE>,
) -> impl StructuralIterator<'a, I, Q, BLOCK_SIZE> {
ClassifierImpl::resume(state)
Expand Down
Loading