Skip to content

Commit

Permalink
Use BTreeSet for assignments. (#2343)
Browse files Browse the repository at this point in the history
Machine calls sometimes re-generate the same assignments (especially
when they are already "complete").
  • Loading branch information
chriseth authored Jan 15, 2025
1 parent 7cbf05f commit 968223d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions executor/src/witgen/jit/witgen_inference.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{
collections::{HashMap, HashSet},
collections::{BTreeSet, HashMap, HashSet},
fmt::{Display, Formatter},
};

Expand Down Expand Up @@ -41,7 +41,7 @@ pub struct WitgenInference<'a, T: FieldElement, FixedEval> {
derived_range_constraints: HashMap<Variable, RangeConstraint<T>>,
known_variables: HashSet<Variable>,
/// Internal equality constraints that are not identities from the constraint set.
assignments: Vec<Assignment<'a, T>>,
assignments: BTreeSet<Assignment<'a, T>>,
code: Vec<Effect<T, Variable>>,
}

Expand Down Expand Up @@ -173,7 +173,7 @@ impl<'a, T: FieldElement, FixedEval: FixedEvaluator<T>> WitgenInference<'a, T, F
/// This does not have to be solvable right away, but is always processed as soon as we have progress.
/// Note that all variables in the expression can be unknown and their status can also change over time.
pub fn assign_constant(&mut self, expression: &'a Expression<T>, row_offset: i32, value: T) {
self.assignments.push(Assignment {
self.assignments.insert(Assignment {
lhs: expression,
row_offset,
rhs: VariableOrValue::Value(value),
Expand All @@ -190,7 +190,7 @@ impl<'a, T: FieldElement, FixedEval: FixedEvaluator<T>> WitgenInference<'a, T, F
row_offset: i32,
variable: Variable,
) {
self.assignments.push(Assignment {
self.assignments.insert(Assignment {
lhs: expression,
row_offset,
rhs: VariableOrValue::Variable(variable),
Expand Down Expand Up @@ -496,14 +496,14 @@ impl<'a, T: FieldElement, FixedEval: FixedEvaluator<T>> Evaluator<'a, T, FixedEv

/// An equality constraint between an algebraic expression evaluated
/// on a certain row offset and a variable or fixed constant value.
#[derive(Clone)]
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Debug)]
struct Assignment<'a, T: FieldElement> {
lhs: &'a Expression<T>,
row_offset: i32,
rhs: VariableOrValue<T, Variable>,
}

#[derive(Clone)]
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Debug)]
enum VariableOrValue<T, V> {
Variable(V),
Value(T),
Expand Down

0 comments on commit 968223d

Please sign in to comment.