Skip to content

Commit

Permalink
Update dependencies and remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
dyxushuai committed Feb 13, 2024
1 parent ddf2ce5 commit 065584c
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 41 deletions.
13 changes: 0 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions crates/oxc_parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ assert-unchecked = { workspace = true }
bitflags = { workspace = true }
rustc-hash = { workspace = true }
num-bigint = { workspace = true }
once_cell = "1.19.0"
seq-macro = { workspace = true }

memchr = "2.7.1"
concat-arrays = "0.1.2"
memchr = "2.7.1"

[dev-dependencies]
oxc_ast = { workspace = true, features = ["serde"] }
Expand Down
5 changes: 2 additions & 3 deletions crates/oxc_parser/src/lexer/identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use super::{
};
use crate::diagnostics;

use once_cell::sync::Lazy;
use oxc_allocator::String;
use oxc_span::Span;
use oxc_syntax::identifier::{
Expand All @@ -15,10 +14,10 @@ use std::{borrow::Cow, cmp::max};

const MIN_ESCAPED_STR_LEN: usize = 16;

static ASCII_ID_START_TABLE: Lazy<SimdByteMatchTable> =
static ASCII_ID_START_TABLE: SimdByteMatchTable =
simd_byte_match_table!(|b| b.is_ascii_alphabetic() || b == b'_' || b == b'$', false);

static NOT_ASCII_ID_CONTINUE_TABLE: Lazy<SimdByteMatchTable> =
static NOT_ASCII_ID_CONTINUE_TABLE: SimdByteMatchTable =
simd_byte_match_table!(|b| b.is_ascii_alphanumeric() || b == b'_' || b == b'$', true);

#[inline]
Expand Down
15 changes: 8 additions & 7 deletions crates/oxc_parser/src/lexer/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct SimdByteMatchTable(simd::MatchTable);
#[allow(dead_code)]
impl SimdByteMatchTable {
// Create new `SimdByteMatchTable`.
pub fn new(bytes: [bool; 256], reverse: bool) -> Self {
pub const fn new(bytes: [bool; 256], reverse: bool) -> Self {
Self(simd::MatchTable::new(bytes, reverse))
}

Expand All @@ -40,12 +40,13 @@ impl SimdByteMatchTable {
macro_rules! simd_byte_match_table {
(|$byte:ident| $res:expr, $reverse:expr) => {{
use crate::lexer::search::SimdByteMatchTable;
use once_cell::sync::Lazy;
seq_macro::seq!($byte in 0u8..=255 {
// Clippy creates warnings because e.g. `byte_match_table!(|b| b == 0)`
// is expanded to `SafeByteMatchTable([0 == 0, ... ])`
Lazy::new(||SimdByteMatchTable::new([#($res,)*], $reverse))
})
// Clippy creates warnings because e.g. `byte_match_table!(|b| b == 0)`
// is expanded to `SimdByteMatchTable([(0 == 0), ... ])`
#[allow(clippy::eq_op)]
const TABLE: SimdByteMatchTable = seq_macro::seq!($byte in 0u8..=255 {
SimdByteMatchTable::new([ #($res,)* ], $reverse)
});
TABLE
}};
}
pub(crate) use simd_byte_match_table;
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_parser/src/lexer/simd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl MatchTable {
#[cfg(all(not(target_feature = "avx2"), not(target_feature = "neon")))]
pub const ALIGNMENT: usize = 16;

pub fn new(bytes: [bool; 256], reverse: bool) -> Self {
pub const fn new(bytes: [bool; 256], reverse: bool) -> Self {
Self {
#[cfg(target_feature = "avx2")]
table: avx2::MatchTable::new(bytes, reverse),
Expand Down
15 changes: 6 additions & 9 deletions crates/oxc_parser/src/lexer/simd/neon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,18 @@ use core::arch::aarch64::*;

#[derive(Debug)]
pub struct MatchTable {
table: uint8x16_t,
arf: uint8x16_t,
table: [u8; 16],
arf: [u8; 16],
//The result of the match is reversed.
reverse: bool,
}

impl MatchTable {
pub const ALIGNMENT: usize = 16;

pub fn new(bytes: [bool; 256], reverse: bool) -> Self {
pub const fn new(bytes: [bool; 256], reverse: bool) -> Self {
let table = tabulate16(bytes);
let table = unsafe { vld1q_u8(table.as_ptr()) };
let arf = unsafe {
vld1q_u8([1, 2, 4, 8, 16, 32, 64, 128, 1, 2, 4, 8, 16, 32, 64, 128].as_ptr())
};
let arf = [1, 2, 4, 8, 16, 32, 64, 128, 1, 2, 4, 8, 16, 32, 64, 128];
Self { table, arf, reverse }
}

Expand All @@ -41,9 +38,9 @@ impl MatchTable {
unsafe fn match_delimiters(&self, ptr: *const u8) -> Option<usize> {
let data = vld1q_u8(ptr);
let col_idx = vandq_u8(data, vdupq_n_u8(0x8F));
let col = vqtbl1q_u8(self.table, col_idx);
let col = vqtbl1q_u8(vld1q_u8(self.table.as_ptr()), col_idx);
let row_idx = vshrq_n_u8(data, 4);
let row = vqtbl1q_u8(self.arf, row_idx);
let row = vqtbl1q_u8(vld1q_u8(self.arf.as_ptr()), row_idx);
let tmp = vandq_u8(col, row);
let result = vceqq_u8(tmp, row);
offsetz(result, self.reverse)
Expand Down
5 changes: 2 additions & 3 deletions crates/oxc_parser/src/lexer/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ use super::{
Kind, Lexer, LexerContext, Span, Token,
};
use crate::diagnostics;
use once_cell::sync::Lazy;
use oxc_allocator::String;
use std::cmp::max;

const MIN_ESCAPED_STR_LEN: usize = 16;

static DOUBLE_QUOTE_STRING_END_TABLE: Lazy<SimdByteMatchTable> =
static DOUBLE_QUOTE_STRING_END_TABLE: SimdByteMatchTable =
simd_byte_match_table!(|b| matches!(b, b'"' | b'\r' | b'\n' | b'\\'), false);

static SINGLE_QUOTE_STRING_END_TABLE: Lazy<SimdByteMatchTable> =
static SINGLE_QUOTE_STRING_END_TABLE: SimdByteMatchTable =
simd_byte_match_table!(|b| matches!(b, b'\'' | b'\r' | b'\n' | b'\\'), false);

/// Macro to handle a string literal.
Expand Down
3 changes: 1 addition & 2 deletions crates/oxc_parser/src/lexer/whitespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ use super::{
search::{byte_search, simd_byte_match_table, SimdByteMatchTable},
Kind, Lexer,
};
use once_cell::sync::Lazy;

static NOT_REGULAR_WHITESPACE_OR_LINE_BREAK_TABLE: Lazy<SimdByteMatchTable> =
static NOT_REGULAR_WHITESPACE_OR_LINE_BREAK_TABLE: SimdByteMatchTable =
simd_byte_match_table!(|b| matches!(b, b' ' | b'\t' | b'\r' | b'\n'), true);

impl<'a> Lexer<'a> {
Expand Down

0 comments on commit 065584c

Please sign in to comment.