Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sources of nondeterminism in egglog #439

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ num-integer = "0.1.45"
num-rational = "0.4.1"
num-traits = "0.2.15"
smallvec = "1.11"
foldhash = "0.1.3"

generic_symbolic_expressions = "5.0.4"

Expand Down
2 changes: 1 addition & 1 deletion src/function/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use std::{
use hashbrown::raw::RawTable;

use super::binary_search::binary_search_table_by_key;
use crate::{util::BuildHasher as BH, TupleOutput, Value, ValueVec};
use crate::{util::BuildFxHasher as BH, TupleOutput, Value, ValueVec};

type Offset = usize;

Expand Down
26 changes: 20 additions & 6 deletions src/util.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
#![allow(unused)]

use std::fmt::Display;
use std::{fmt::Display, hash::BuildHasher};

use crate::core::SpecializedPrimitive;
#[allow(unused_imports)]
use crate::*;

pub(crate) type BuildHasher = std::hash::BuildHasherDefault<rustc_hash::FxHasher>;
pub(crate) type BuildFxHasher = std::hash::BuildHasherDefault<rustc_hash::FxHasher>;

pub(crate) type HashMap<K, V> = hashbrown::HashMap<K, V, BuildHasher>;
pub(crate) type HashSet<K> = hashbrown::HashSet<K, BuildHasher>;
#[derive(Debug, Clone, Default)]
pub struct DeterministicHashBuilder;

pub type IndexMap<K, V> = indexmap::IndexMap<K, V, BuildHasher>;
pub type IndexSet<K> = indexmap::IndexSet<K, BuildHasher>;
impl BuildHasher for DeterministicHashBuilder {
type Hasher = foldhash::fast::FoldHasher;
fn build_hasher(&self) -> Self::Hasher {
foldhash::fast::FixedState::with_seed(0).build_hasher()
}
}

/// Use deterministic hasher to make egglog deterministic
/// when rule application order matters.
pub(crate) type HashMap<K, V> = hashbrown::HashMap<K, V, DeterministicHashBuilder>;
pub(crate) type HashSet<K> = hashbrown::HashSet<K, DeterministicHashBuilder>;

/// Index maps don't need deterministic hashing,
/// since iteration order is guaranteed to be insertion order.
pub type IndexMap<K, V> = indexmap::IndexMap<K, V, BuildFxHasher>;
pub type IndexSet<K> = indexmap::IndexSet<K, BuildFxHasher>;

pub(crate) fn concat_vecs<T>(to: &mut Vec<T>, mut from: Vec<T>) {
if to.len() < from.len() {
Expand Down
Loading