-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
NodeBuilder
for building ASTs (#476)
- Loading branch information
Showing
8 changed files
with
97 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
use crate::ast; | ||
use crate::ast::{AstNode, NodeId}; | ||
|
||
/// A provider of 'fresh' [`NodeId`]s. | ||
pub trait IdGenerator { | ||
/// Provides a 'fresh' [`NodeId`]. | ||
fn id(&mut self) -> NodeId; | ||
} | ||
|
||
/// Auto-incrementing [`IdGenerator`] | ||
pub struct AutoNodeIdGenerator { | ||
next_id: ast::NodeId, | ||
} | ||
|
||
impl Default for AutoNodeIdGenerator { | ||
fn default() -> Self { | ||
AutoNodeIdGenerator { next_id: NodeId(1) } | ||
} | ||
} | ||
|
||
impl IdGenerator for AutoNodeIdGenerator { | ||
#[inline] | ||
fn id(&mut self) -> NodeId { | ||
let mut next = NodeId(&self.next_id.0 + 1); | ||
std::mem::swap(&mut self.next_id, &mut next); | ||
next | ||
} | ||
} | ||
|
||
/// A provider of [`NodeId`]s that are always `0`; Useful for testing | ||
#[derive(Default)] | ||
pub struct NullIdGenerator {} | ||
|
||
impl IdGenerator for NullIdGenerator { | ||
fn id(&mut self) -> NodeId { | ||
NodeId(0) | ||
} | ||
} | ||
|
||
/// A Builder for [`AstNode`]s that uses a [`IdGenerator`] to assign [`NodeId`]s | ||
pub struct NodeBuilder<Id: IdGenerator> { | ||
/// Generator for 'fresh' [`NodeId`]s | ||
pub id_gen: Id, | ||
} | ||
|
||
impl<Id> NodeBuilder<Id> | ||
where | ||
Id: IdGenerator, | ||
{ | ||
pub fn new(id_gen: Id) -> Self { | ||
Self { id_gen } | ||
} | ||
|
||
pub fn node<T>(&mut self, node: T) -> AstNode<T> { | ||
let id = self.id_gen.id(); | ||
AstNode { id, node } | ||
} | ||
} | ||
|
||
impl<T> Default for NodeBuilder<T> | ||
where | ||
T: IdGenerator + Default, | ||
{ | ||
fn default() -> Self { | ||
Self::new(T::default()) | ||
} | ||
} | ||
|
||
/// A [`NodeBuilder`] whose 'fresh' [`NodeId`]s are Auto-incrementing. | ||
pub type NodeBuilderWithAutoId = NodeBuilder<AutoNodeIdGenerator>; | ||
|
||
/// A [`NodeBuilder`] whose 'fresh' [`NodeId`]s are always `0`; Useful for testing | ||
pub type NodeBuilderWithNullId = NodeBuilder<NullIdGenerator>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,6 @@ pub mod ast; | |
|
||
pub mod pretty; | ||
|
||
pub mod builder; | ||
|
||
pub mod visit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1b22fb6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PartiQL (rust) Benchmark
arith_agg-avg
775078
ns/iter (± 8705
)771998
ns/iter (± 3660
)1.00
arith_agg-avg_distinct
862652
ns/iter (± 6626
)868193
ns/iter (± 32480
)0.99
arith_agg-count
830846
ns/iter (± 7811
)819127
ns/iter (± 13014
)1.01
arith_agg-count_distinct
855765
ns/iter (± 2496
)850385
ns/iter (± 12627
)1.01
arith_agg-min
843309
ns/iter (± 3129
)835124
ns/iter (± 7322
)1.01
arith_agg-min_distinct
871031
ns/iter (± 11411
)864818
ns/iter (± 5042
)1.01
arith_agg-max
840150
ns/iter (± 3401
)826288
ns/iter (± 9355
)1.02
arith_agg-max_distinct
870457
ns/iter (± 1793
)860400
ns/iter (± 3296
)1.01
arith_agg-sum
833829
ns/iter (± 2930
)822396
ns/iter (± 21825
)1.01
arith_agg-sum_distinct
863680
ns/iter (± 2889
)851443
ns/iter (± 4511
)1.01
arith_agg-avg-count-min-max-sum
971146
ns/iter (± 7271
)967909
ns/iter (± 18508
)1.00
arith_agg-avg-count-min-max-sum-group_by
1228144
ns/iter (± 5068
)1261195
ns/iter (± 11052
)0.97
arith_agg-avg-count-min-max-sum-group_by-group_as
1825750
ns/iter (± 17664
)1872671
ns/iter (± 20081
)0.97
arith_agg-avg_distinct-count_distinct-min_distinct-max_distinct-sum_distinct
1171155
ns/iter (± 7797
)1178677
ns/iter (± 10540
)0.99
arith_agg-avg_distinct-count_distinct-min_distinct-max_distinct-sum_distinct-group_by
1475823
ns/iter (± 17342
)1589490
ns/iter (± 19655
)0.93
arith_agg-avg_distinct-count_distinct-min_distinct-max_distinct-sum_distinct-group_by-group_as
2067865
ns/iter (± 12643
)2165888
ns/iter (± 8946
)0.95
parse-1
4149
ns/iter (± 24
)4269
ns/iter (± 15
)0.97
parse-15
39532
ns/iter (± 211
)39638
ns/iter (± 150
)1.00
parse-30
76008
ns/iter (± 562
)77020
ns/iter (± 352
)0.99
compile-1
4432
ns/iter (± 13
)4263
ns/iter (± 10
)1.04
compile-15
35043
ns/iter (± 104
)33192
ns/iter (± 197
)1.06
compile-30
71338
ns/iter (± 331
)67869
ns/iter (± 314
)1.05
plan-1
69546
ns/iter (± 702
)69565
ns/iter (± 234
)1.00
plan-15
1078664
ns/iter (± 86226
)1082605
ns/iter (± 19293
)1.00
plan-30
2153387
ns/iter (± 13338
)2170474
ns/iter (± 56024
)0.99
eval-1
12766894
ns/iter (± 60043
)12909400
ns/iter (± 104669
)0.99
eval-15
86920998
ns/iter (± 1270499
)87331642
ns/iter (± 228299
)1.00
eval-30
167856739
ns/iter (± 489213
)168169555
ns/iter (± 384409
)1.00
join
9891
ns/iter (± 173
)9942
ns/iter (± 344
)0.99
simple
2474
ns/iter (± 27
)2482
ns/iter (± 13
)1.00
simple-no
427
ns/iter (± 2
)428
ns/iter (± 2
)1.00
numbers
57
ns/iter (± 0
)57
ns/iter (± 0
)1
parse-simple
586
ns/iter (± 3
)556
ns/iter (± 9
)1.05
parse-ion
1762
ns/iter (± 4
)1736
ns/iter (± 29
)1.01
parse-group
5772
ns/iter (± 35
)5734
ns/iter (± 257
)1.01
parse-complex
15496
ns/iter (± 188
)14833
ns/iter (± 122
)1.04
parse-complex-fexpr
22579
ns/iter (± 111
)21781
ns/iter (± 130
)1.04
This comment was automatically generated by workflow using github-action-benchmark.