Skip to content

Commit

Permalink
Merge pull request #406 from oflatt/oflatt-determinism-bug
Browse files Browse the repository at this point in the history
Fix determinism bug from new combined ruleset code
  • Loading branch information
oflatt authored Aug 8, 2024
2 parents ecc3be5 + 1e6daea commit a5b61ab
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ impl Display for Id {
#[derive(Clone, Debug)]
/// The egglog internal representation of already compiled rules
pub(crate) enum Ruleset {
Rules(Symbol, HashMap<Symbol, CompiledRule>),
/// Represents a ruleset with a set of rules.
/// Use an [`IndexMap`] to ensure egglog is deterministic.
/// Rules added to the [`IndexMap`] first apply their
/// actions first.
Rules(Symbol, IndexMap<Symbol, CompiledRule>),
/// A combined ruleset may contain other rulesets.
Combined(Symbol, Vec<Symbol>),
}

Expand Down
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1100,8 +1100,10 @@ impl EGraph {
match rules {
Ruleset::Rules(_, rules) => {
match rules.entry(name) {
Entry::Occupied(_) => panic!("Rule '{name}' was already present"),
Entry::Vacant(e) => e.insert(compiled_rule),
indexmap::map::Entry::Occupied(_) => {
panic!("Rule '{name}' was already present")
}
indexmap::map::Entry::Vacant(e) => e.insert(compiled_rule),
};
Ok(name)
}
Expand Down

0 comments on commit a5b61ab

Please sign in to comment.