Skip to content

Commit 76a666c

Browse files
committed
dynamic node discriminant computation
1 parent afa89c1 commit 76a666c

5 files changed

Lines changed: 20 additions & 22 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ anyhow = { version = "1.0", default-features = false }
6464
criterion = { version = "0.7.0", features = ["html_reports"] }
6565
either = { version = "1.13", default-features = false }
6666
embedded-io = { version = "0.6.1", features = ["alloc"] }
67+
foldhash = { version = "0.2.0", default-features = false }
6768
hashbrown = "0.16.0"
6869
linfa = "0.7.1"
6970
linfa-linear = "0.7.1"

baselines/benches/models.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use fandango::dynamic::{DynamicNode, DynamicSampler};
88
use fandango::generation::{Generated, InPlaceGenerated};
99
use fandango::lang::FandangoNode;
1010
use fandango::tuple_list::{tuple_list, tuple_list_type};
11-
use fandango::typing::{AsNodeRef, AsStaticNode, Discriminable, Node, Opaque};
11+
use fandango::typing::{AsNode, AsNodeRef, AsStaticNode, Discriminable, Node, Opaque};
1212
use fandango::visitor::assignment::SwapVisitor;
1313
use fandango::visitor::navigation::{Advance, CountNodes, GoTo, GoToMut};
1414
use fandango::visitor::{VisitResult, VisitWith, VisitWithMut, VisitableChildren, Visitor};
@@ -333,27 +333,25 @@ where
333333
let (time, _) = measure(
334334
(generated.clone(), local_sampler.clone()),
335335
|(mutated, sampler)| {
336-
black_box(mutated)
337-
.go_to_mut(idx, black_box(path))
338-
.unwrap()
339-
.generate_in_place(
340-
&mut DynamicSampler::new(
341-
<B::Start as AsStaticNode>::static_root(),
342-
<B::Start as AsStaticNode>::static_definition(),
343-
&nonterminals,
344-
black_box(sampler),
345-
),
346-
&mut generator,
347-
path.len(),
348-
);
336+
let selected = black_box(mutated).go_to_mut(idx, black_box(path)).unwrap();
337+
selected.generate_in_place(
338+
&mut DynamicSampler::new(
339+
<B::Start as AsStaticNode>::static_root(),
340+
selected.definition(),
341+
&nonterminals,
342+
black_box(sampler),
343+
),
344+
&mut generator,
345+
path.len(),
346+
);
349347
},
350348
);
351349
let mut cloned = generated.clone();
352350
let mutated = cloned.go_to_mut(idx, path).unwrap();
353351
mutated.generate_in_place(
354352
&mut DynamicSampler::new(
355353
<B::Start as AsStaticNode>::static_root(),
356-
<B::Start as AsStaticNode>::static_definition(),
354+
mutated.definition(),
357355
&nonterminals,
358356
&mut local_sampler,
359357
),

core/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ authors.workspace = true
77
[dependencies]
88
either = { workspace = true }
99
embedded-io.workspace = true
10+
foldhash.workspace = true
1011
hashbrown = { workspace = true, features = ["serde"] }
1112
mappable-rc.workspace = true
12-
num-integer.workspace = true
13-
num-traits.workspace = true
1413
pest.workspace = true
1514
pest_derive.workspace = true
1615
petgraph = { workspace = true, features = ["graphmap"] }

core/src/dynamic.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ use alloc::vec;
2020
use alloc::vec::Vec;
2121
use core::hash::BuildHasher;
2222
use core::ops::ControlFlow;
23-
use hashbrown::{DefaultHashBuilder, HashMap};
23+
use foldhash::fast::SeedableRandomState;
24+
use hashbrown::HashMap;
2425

2526
type FandangoNode = crate::lang::FandangoNode<'static, 'static>;
2627

@@ -433,13 +434,13 @@ impl AssignFrom<&'_ DynamicNode> for &'_ mut DynamicNode {
433434

434435
impl DiscriminantLookup for &'_ DynamicNode {
435436
fn lookup_discriminant(node: &crate::lang::FandangoNode) -> usize {
436-
DefaultHashBuilder::default().hash_one(node) as usize
437+
SeedableRandomState::fixed().hash_one(node) as usize
437438
}
438439
}
439440

440441
impl DiscriminantLookup for &'_ mut DynamicNode {
441442
fn lookup_discriminant(node: &crate::lang::FandangoNode) -> usize {
442-
DefaultHashBuilder::default().hash_one(node) as usize
443+
SeedableRandomState::fixed().hash_one(node) as usize
443444
}
444445
}
445446

0 commit comments

Comments
 (0)