Skip to content

Commit

Permalink
Use partiql_ast::ast::AstTypeMap for LocationMap (#394)
Browse files Browse the repository at this point in the history
Addressing the comment in PR #389, this PR re-uses the `AstTypeMap`
for `LocationMap` which removes a dependency to `HashMap` as `AstTypeMap`
uses `IndexMap`.
  • Loading branch information
am357 authored Jun 14, 2023
1 parent babd7ac commit 004d2c0
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 10 deletions.
5 changes: 3 additions & 2 deletions partiql-ast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ path = "src/lib.rs"
bench = false

[dependencies]
indexmap = "1.9"
indexmap = { version = "1.9", default-features = false }
rust_decimal = { version = "1.25.0", default-features = false, features = ["std"] }
serde = { version = "1.*", features = ["derive"], optional = true }

Expand All @@ -31,7 +31,8 @@ default = []
serde = [
"dep:serde",
"rust_decimal/serde-with-str",
"rust_decimal/serde"
"rust_decimal/serde",
"indexmap/serde",
]

[dependencies.partiql-ast-macros]
Expand Down
4 changes: 1 addition & 3 deletions partiql-parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ use parse::{parse_partiql, AstData, ErrorData};
use partiql_ast::ast;
use partiql_source_map::line_offset_tracker::LineOffsetTracker;
use partiql_source_map::location::BytePosition;

use partiql_ast::ast::NodeId;
use partiql_source_map::metadata::LocationMap;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -82,7 +80,7 @@ pub struct Parsed<'input> {
pub text: &'input str,
pub offsets: LineOffsetTracker,
pub ast: Box<ast::Expr>,
pub locations: LocationMap<NodeId>,
pub locations: LocationMap,
}

/// The output of errors when parsing PartiQL statement strings: an errors and auxiliary data.
Expand Down
4 changes: 2 additions & 2 deletions partiql-parser/src/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crate::parse::parser_state::{IdGenerator, ParserState};
use crate::preprocessor::{PreprocessingPartiqlLexer, BUILT_INS};
use lalrpop_util as lpop;
use partiql_ast::ast;
use partiql_ast::ast::NodeId;
use partiql_source_map::line_offset_tracker::LineOffsetTracker;
use partiql_source_map::location::{ByteOffset, BytePosition, ToLocated};
use partiql_source_map::metadata::LocationMap;
Expand Down Expand Up @@ -41,7 +40,7 @@ type LalrpopErrorRecovery<'input> =
#[derive(Debug, Clone)]
pub(crate) struct AstData {
pub ast: Box<ast::Expr>,
pub locations: LocationMap<NodeId>,
pub locations: LocationMap,
pub offsets: LineOffsetTracker,
}

Expand Down Expand Up @@ -535,6 +534,7 @@ mod tests {

mod set_ops {
use super::*;
use partiql_ast::ast::NodeId;

#[derive(Default)]
pub(crate) struct NullIdGenerator {}
Expand Down
2 changes: 1 addition & 1 deletion partiql-parser/src/parse/parser_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub(crate) struct ParserState<'input, Id: IdGenerator> {
/// Generator for 'fresh' [`NodeId`]s
pub id_gen: Id,
/// Maps AST [`NodeId`]s to the location in the source from which each was derived.
pub locations: LocationMap<NodeId>,
pub locations: LocationMap,
/// Any errors accumulated during parse.
pub errors: ParseErrors<'input>,

Expand Down
2 changes: 2 additions & 0 deletions partiql-source-map/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ edition.workspace = true
bench = false

[dependencies]
partiql-ast = { path = "../partiql-ast", version = "0.5.*" }

smallvec = { version = "1.*" }
serde = { version = "1.*", features = ["derive"], optional = true }

Expand Down
4 changes: 2 additions & 2 deletions partiql-source-map/src/metadata.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::location::{BytePosition, Location};
use std::collections::HashMap;
use partiql_ast::ast::AstTypeMap;

/// Map of `T` to a [`Location<BytePosition>>`]
pub type LocationMap<T> = HashMap<T, Location<BytePosition>>;
pub type LocationMap = AstTypeMap<Location<BytePosition>>;

1 comment on commit 004d2c0

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PartiQL (rust) Benchmark

Benchmark suite Current: 004d2c0 Previous: babd7ac Ratio
parse-1 6627 ns/iter (± 161) 6933 ns/iter (± 847) 0.96
parse-15 65440 ns/iter (± 867) 65659 ns/iter (± 5519) 1.00
parse-30 129684 ns/iter (± 1883) 135387 ns/iter (± 8910) 0.96
compile-1 5852 ns/iter (± 101) 6051 ns/iter (± 361) 0.97
compile-15 41875 ns/iter (± 588) 44369 ns/iter (± 5790) 0.94
compile-30 85142 ns/iter (± 1376) 95681 ns/iter (± 21741) 0.89
plan-1 23148 ns/iter (± 404) 26157 ns/iter (± 2358) 0.88
plan-15 427549 ns/iter (± 5974) 502372 ns/iter (± 30894) 0.85
plan-30 873706 ns/iter (± 11191) 1001031 ns/iter (± 68498) 0.87
eval-1 28031260 ns/iter (± 535227) 27122381 ns/iter (± 1817512) 1.03
eval-15 143519947 ns/iter (± 1527247) 142875254 ns/iter (± 5879075) 1.00
eval-30 269445526 ns/iter (± 2782126) 270865397 ns/iter (± 19224673) 0.99
join 17721 ns/iter (± 204) 17216 ns/iter (± 1123) 1.03
simple 8129 ns/iter (± 68) 8165 ns/iter (± 523) 1.00
simple-no 765 ns/iter (± 7) 737 ns/iter (± 57) 1.04
numbers 171 ns/iter (± 1) 160 ns/iter (± 10) 1.07
parse-simple 883 ns/iter (± 4) 827 ns/iter (± 55) 1.07
parse-ion 3202 ns/iter (± 35) 3026 ns/iter (± 264) 1.06
parse-group 10143 ns/iter (± 71) 10373 ns/iter (± 1067) 0.98
parse-complex 26513 ns/iter (± 79) 27630 ns/iter (± 1303) 0.96
parse-complex-fexpr 41816 ns/iter (± 150) 45491 ns/iter (± 3352) 0.92

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.