From 2c897b3084be8599dbca574ebce866f26bd60330 Mon Sep 17 00:00:00 2001 From: ur4t <46435411+ur4t@users.noreply.github.com> Date: Mon, 8 Apr 2024 20:35:31 +0800 Subject: [PATCH 1/5] fix lexer for nighly after 2023-12-02 --- pag-lexer/src/lookahead.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pag-lexer/src/lookahead.rs b/pag-lexer/src/lookahead.rs index 52b236d..203b9c6 100644 --- a/pag-lexer/src/lookahead.rs +++ b/pag-lexer/src/lookahead.rs @@ -65,14 +65,15 @@ fn generate_lookahead_routine(intervals: &Intervals, kind: Kind) -> TokenStream mask.#count_act() / 8 }} } else { - quote! { - (#x).to_bitmask().#count_act() - } + quote! {{ + let mask = (#x).to_bitmask() as u16; + mask.#count_act() + }} } }); quote! { for i in input[idx..].array_chunks::<16>() { - use core::simd::*; + use core::simd::prelude::*; let data = u8x16::from_slice(i); let idx_offset = #idx_offset; idx += idx_offset as usize; From d03d7391b59c8591c8818f866af125b622d987c3 Mon Sep 17 00:00:00 2001 From: ur4t <46435411+ur4t@users.noreply.github.com> Date: Mon, 8 Apr 2024 20:41:44 +0800 Subject: [PATCH 2/5] fix some clippy warnings --- pag-lexer/src/regex_tree.rs | 2 +- pag-lexer/src/utilities.rs | 2 +- pag-parser/src/lib.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pag-lexer/src/regex_tree.rs b/pag-lexer/src/regex_tree.rs index b757583..b9d63b5 100644 --- a/pag-lexer/src/regex_tree.rs +++ b/pag-lexer/src/regex_tree.rs @@ -89,7 +89,7 @@ impl RegexTree { match self { Set(intervals) if intervals.is_single_byte() => Some(vec![intervals.representative()]), Concat(children) => { - let init = if let Some(x) = children.get(0) { + let init = if let Some(x) = children.first() { x.as_byte_sequence() } else { return Some(Vec::new()); diff --git a/pag-lexer/src/utilities.rs b/pag-lexer/src/utilities.rs index b14a70d..adb2440 100644 --- a/pag-lexer/src/utilities.rs +++ b/pag-lexer/src/utilities.rs @@ -10,7 +10,7 @@ where } #[cfg(debug_assertions)] { - let mut vec = Vec::from_iter(data.into_iter()); + let mut vec = Vec::from_iter(data); vec.sort_unstable_by_key(_f); vec.into_iter() } diff --git a/pag-parser/src/lib.rs b/pag-parser/src/lib.rs index db02afd..0149fae 100644 --- a/pag-parser/src/lib.rs +++ b/pag-parser/src/lib.rs @@ -88,7 +88,7 @@ impl<'src> Error<'src> { Report::build(ReportKind::Error, input_name, span.start()) .with_message("Format error in grammar definition") .with_label(Label::new((input_name, span.start()..span.end())) - .with_message(format!("{}", message)) + .with_message(message.to_string()) .with_color(Color::Red)) .finish() }, From fde98c46c7dc499b9a7262a7d1e1df6de39bc6cb Mon Sep 17 00:00:00 2001 From: ur4t <46435411+ur4t@users.noreply.github.com> Date: Mon, 8 Apr 2024 20:43:05 +0800 Subject: [PATCH 3/5] update dependencies --- benches/csv/Cargo.toml | 2 +- benches/json/Cargo.toml | 4 ++-- pag-parser/Cargo.toml | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/benches/csv/Cargo.toml b/benches/csv/Cargo.toml index e00dc46..85ca85e 100644 --- a/benches/csv/Cargo.toml +++ b/benches/csv/Cargo.toml @@ -15,7 +15,7 @@ pag-compiler = { path = "../../pag-compiler" } [dev-dependencies] csv = { version = "1" } -criterion = { version = "0.4", features = ["html_reports"] } +criterion = { version = "0.5", features = ["html_reports"] } pest = { version = "2.5.7", features = [ "std", "memchr" ] } pest_derive = "2.5.7" diff --git a/benches/json/Cargo.toml b/benches/json/Cargo.toml index c72e9d6..6ce329f 100644 --- a/benches/json/Cargo.toml +++ b/benches/json/Cargo.toml @@ -15,12 +15,12 @@ pag-compiler = { path = "../../pag-compiler" } lalrpop = "0.20.0" [dev-dependencies] -criterion = { version = "0.4", features = ["html_reports"] } +criterion = { version = "0.5", features = ["html_reports"] } snmalloc-rs = { version = "0.3", features = ["build_cc"] } pest = { version = "2.5.7", features = [ "std", "memchr" ] } pest_derive = "2.5.7" lalrpop-util = { version = "0.20.0", features = ["lexer", "unicode"] } -logos = "0.13.0" +logos = "0.14.0" [[bench]] name = "benchmarks" diff --git a/pag-parser/Cargo.toml b/pag-parser/Cargo.toml index a49e1cb..c3b28f6 100644 --- a/pag-parser/Cargo.toml +++ b/pag-parser/Cargo.toml @@ -31,7 +31,7 @@ pag-lexer = { version = "0.1.0-alpha.1", path = "../pag-lexer" } typed-arena = "2.0.2" quote = "1.0.26" proc-macro2 = "1.0" -ariadne = { version = "0.3", features = ["auto-color"] } +ariadne = { version = "0.4", features = ["auto-color"] } [dev-dependencies] -strip-ansi-escapes = "0.1.1" +strip-ansi-escapes = "0.2.0" From a508e36057f07b1bea1248c613407ca602d56df2 Mon Sep 17 00:00:00 2001 From: ur4t <46435411+ur4t@users.noreply.github.com> Date: Wed, 10 Apr 2024 12:22:02 +0800 Subject: [PATCH 4/5] apply `cargo fmt` --- pag-parser/src/frontend/mod.rs | 4 +++- pag-parser/src/frontend/syntax.rs | 2 +- pag-parser/src/fusion.rs | 4 +++- pag-parser/src/nf.rs | 13 ++++++++++--- pag-parser/src/type_system/fixpoint.rs | 4 +++- pag-parser/src/utilities.rs | 4 +++- 6 files changed, 23 insertions(+), 8 deletions(-) diff --git a/pag-parser/src/frontend/mod.rs b/pag-parser/src/frontend/mod.rs index 8fa04b7..067624e 100644 --- a/pag-parser/src/frontend/mod.rs +++ b/pag-parser/src/frontend/mod.rs @@ -493,7 +493,9 @@ mod test { dbg!(size_of::()); let pairs = GrammarParser::parse(Rule::grammar, TEST).unwrap(); let tree = parse_surface_syntax(pairs, &PRATT_PARSER, TEST).unwrap(); - let Grammar { lexer, parser } = &tree.node else { unreachable!() }; + let Grammar { lexer, parser } = &tree.node else { + unreachable!() + }; println!("\n---------< construct lexer database >----------"); let database = construct_lexer_database(lexer).unwrap(); diff --git a/pag-parser/src/frontend/syntax.rs b/pag-parser/src/frontend/syntax.rs index 6119d92..b1ee998 100644 --- a/pag-parser/src/frontend/syntax.rs +++ b/pag-parser/src/frontend/syntax.rs @@ -71,7 +71,7 @@ pub fn construct_parser<'src, 'arena>( }; let mut errs = Vec::new(); for rule in rules { - let ParserRuleDef { active, name, expr, } = &rule.node else { + let ParserRuleDef { active, name, expr } = &rule.node else { unreachable_branch!("parser should only contain rule definitions") }; match construct_core_syntax_tree(&parser, expr) { diff --git a/pag-parser/src/fusion.rs b/pag-parser/src/fusion.rs index e66e6ca..fe14be6 100644 --- a/pag-parser/src/fusion.rs +++ b/pag-parser/src/fusion.rs @@ -199,7 +199,9 @@ fn generate_children<'src>( .iter() .filter(|x| !matches!(x, NormalForm::Empty(..))) .map(|nf| { - let NormalForm::Sequence { nonterminals, .. } = nf else { unreachable!() }; + let NormalForm::Sequence { nonterminals, .. } = nf else { + unreachable!() + }; let mut add_continue = false; let mut actions = Vec::new(); diff --git a/pag-parser/src/nf.rs b/pag-parser/src/nf.rs index 1b05d52..61d7384 100644 --- a/pag-parser/src/nf.rs +++ b/pag-parser/src/nf.rs @@ -301,7 +301,10 @@ pub fn merge_inactive_rules<'src, 'nf>( let NormalForm::Sequence { terminal, nonterminals, - } = j else { continue }; + } = j + else { + continue; + }; if nonterminals.contains(&Action::Subroutine(tag)) { *j = &*arena.alloc(NormalForm::Sequence { terminal: *terminal, @@ -332,9 +335,13 @@ pub fn remove_unreachable_rules<'src>(nfs: &mut NormalForms<'src, '_>, parser: & return; } visited.insert(current); - let Some(tag) = nfs.entries.get(¤t) else { return }; + let Some(tag) = nfs.entries.get(¤t) else { + return; + }; for i in tag { - let NormalForm::Sequence { nonterminals, .. } = i else { continue }; + let NormalForm::Sequence { nonterminals, .. } = i else { + continue; + }; for i in nonterminals { let Action::Subroutine(x) = i else { continue }; dfs(nfs, *x, visited); diff --git a/pag-parser/src/type_system/fixpoint.rs b/pag-parser/src/type_system/fixpoint.rs index a6e297a..3e4ca85 100644 --- a/pag-parser/src/type_system/fixpoint.rs +++ b/pag-parser/src/type_system/fixpoint.rs @@ -39,7 +39,9 @@ fn find_neighbors( Term::Fix(_, expr) => find_neighbors(expr, neighbors, sym_to_id), Term::ParserRef(symbol) => { // unexisted IDs refer to implicit fixpoints - let Some(&id) = sym_to_id.get(symbol) else { return }; + let Some(&id) = sym_to_id.get(symbol) else { + return; + }; neighbors.push(id); } _ => {} diff --git a/pag-parser/src/utilities.rs b/pag-parser/src/utilities.rs index c1beeca..487e503 100644 --- a/pag-parser/src/utilities.rs +++ b/pag-parser/src/utilities.rs @@ -43,7 +43,9 @@ fn is_ascii_ident_head(x: &u8) -> bool { } fn is_ascii_ident(s: &str) -> bool { - let [x, xs@..] = s.as_bytes() else { return false }; + let [x, xs @ ..] = s.as_bytes() else { + return false; + }; is_ascii_ident_head(x) && xs.iter().all(is_ascii_ident_body) } From 8f843f413febd2f6575d77c3324274e1e6d9c54a Mon Sep 17 00:00:00 2001 From: ur4t <46435411+ur4t@users.noreply.github.com> Date: Wed, 10 Apr 2024 12:22:43 +0800 Subject: [PATCH 5/5] simplify rustfmt.toml --- rustfmt.toml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/rustfmt.toml b/rustfmt.toml index f5343e9..1ac74e9 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,7 +1 @@ -ignore = [ - "/tests/arith-expr/src/parser.rs", - "/tests/sexpr-calculator/src/parser.rs", - "/tests/tokenizer/src/generated/*.rs", - "/benches/csv/src/parser.rs", - "/benches/json/src/parser.rs", -] +format_generated_files = false