Skip to content

Commit e4187d3

Browse files
committed
refactor: upgrade nom to version 8.0.0 and replace the pratt parser with nom_language. Use the first token check to reduce branch traversal in expr_element.
1 parent a6ac9a5 commit e4187d3

File tree

22 files changed

+1927
-1291
lines changed

22 files changed

+1927
-1291
lines changed

โ€ŽCargo.lockโ€Ž

Lines changed: 15 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

โ€ŽCargo.tomlโ€Ž

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -554,9 +554,9 @@ fast-float2 = "0.2.3"
554554
gix = "0.71.0"
555555
indent = "0.1.1"
556556
logos = "0.12.1"
557-
nom = "7.1.1"
558-
nom-rule = "0.4"
559-
pratt = "0.4.0"
557+
nom = "8.0.0"
558+
nom-language = "0.1.0"
559+
nom-rule = "0.5.1"
560560
rspack-codespan-reporting = "0.11"
561561
rustc-demangle = "0.1"
562562
strsim = "0.10"

โ€Žsrc/query/ast/Cargo.tomlโ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ indent = { workspace = true }
1919
itertools = { workspace = true }
2020
logos = { workspace = true }
2121
nom = { workspace = true }
22+
nom-language = { workspace = true }
2223
nom-rule = { workspace = true }
2324
ordered-float = { workspace = true }
2425
percent-encoding = { workspace = true }
25-
pratt = { workspace = true }
2626
pretty_assertions = { workspace = true }
2727
recursive = { workspace = true }
2828
rspack-codespan-reporting = { workspace = true }

โ€Žsrc/query/ast/benches/bench.rsโ€Ž

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ fn main() {
1818

1919
// bench fastest โ”‚ slowest โ”‚ median โ”‚ mean โ”‚ samples โ”‚ iters
2020
// โ•ฐโ”€ dummy โ”‚ โ”‚ โ”‚ โ”‚ โ”‚
21-
// โ”œโ”€ deep_function_call 802.2 ยตs โ”‚ 1.207 ms โ”‚ 842 ยตs โ”‚ 850.6 ยตs โ”‚ 100 โ”‚ 100
22-
// โ”œโ”€ deep_query 242.3 ยตs โ”‚ 426.3 ยตs โ”‚ 254.2 ยตs โ”‚ 257.3 ยตs โ”‚ 100 โ”‚ 100
23-
// โ”œโ”€ large_query 1.104 ms โ”‚ 1.264 ms โ”‚ 1.14 ms โ”‚ 1.142 ms โ”‚ 100 โ”‚ 100
24-
// โ”œโ”€ large_statement 1.097 ms โ”‚ 1.2 ms โ”‚ 1.15 ms โ”‚ 1.148 ms โ”‚ 100 โ”‚ 100
25-
// โ•ฐโ”€ wide_expr 282.4 ยตs โ”‚ 368.6 ยตs โ”‚ 298 ยตs โ”‚ 298.7 ยตs โ”‚ 100 โ”‚ 100
21+
// โ”œโ”€ deep_function_call 242.8 ยตs โ”‚ 525.3 ยตs โ”‚ 258.9 ยตs โ”‚ 262.8 ยตs โ”‚ 100 โ”‚ 100
22+
// โ”œโ”€ deep_query 235.6 ยตs โ”‚ 364.8 ยตs โ”‚ 244.8 ยตs โ”‚ 249.3 ยตs โ”‚ 100 โ”‚ 100
23+
// โ”œโ”€ large_query 362.9 ยตs โ”‚ 451.6 ยตs โ”‚ 376.5 ยตs โ”‚ 379.7 ยตs โ”‚ 100 โ”‚ 100
24+
// โ”œโ”€ large_statement 364.8 ยตs โ”‚ 418.4 ยตs โ”‚ 380.2 ยตs โ”‚ 382.8 ยตs โ”‚ 100 โ”‚ 100
25+
// โ•ฐโ”€ wide_expr 96.97 ยตs โ”‚ 270.2 ยตs โ”‚ 102.8 ยตs โ”‚ 105.3 ยตs โ”‚ 100 โ”‚ 100
2626

2727
#[divan::bench_group(max_time = 0.5)]
2828
mod dummy {

โ€Žsrc/query/ast/src/ast/expr.rsโ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ use derive_visitor::DriveMut;
2020
use educe::Educe;
2121
use enum_as_inner::EnumAsInner;
2222
use ethnum::i256;
23-
use pratt::Affix;
24-
use pratt::Associativity;
2523

2624
use super::ColumnRef;
2725
use super::OrderByExpr;
@@ -32,6 +30,8 @@ use crate::ast::write_dot_separated_list;
3230
use crate::ast::Identifier;
3331
use crate::ast::Indirection;
3432
use crate::ast::Query;
33+
use crate::precedence::Affix;
34+
use crate::precedence::Associativity;
3535
use crate::span::merge_span;
3636
use crate::ParseError;
3737
use crate::Result;

โ€Žsrc/query/ast/src/lib.rsโ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
pub mod ast;
1919
pub mod parser;
2020
mod parser_error;
21+
pub mod precedence;
2122
pub mod span;
2223
mod visitor;
2324

โ€Žsrc/query/ast/src/parser/comment.rsโ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
use nom::Parser;
1516
use nom_rule::rule;
1617

1718
use super::expr::literal_string;
@@ -33,7 +34,7 @@ pub fn comment(i: Input) -> IResult<Statement> {
3334
| #comment_column: "`COMMENT [IF EXISTS] ON COLUMN <table_name>.<column_name> IS '<string_literal>'`"
3435
| #comment_network_policy: "`COMMENT [IF EXISTS] ON NETWORK POLICY <policy_name> IS '<string_literal>'`"
3536
| #comment_password_policy: "`COMMENT [IF EXISTS] ON PASSWORD POLICY <policy_name> IS '<string_literal>'`"
36-
)(i)
37+
).parse(i)
3738
}
3839

3940
fn comment_table(i: Input) -> IResult<Statement> {

0 commit comments

Comments
ย (0)