Skip to content

Commit 50f55a2

Browse files
authored
Defers linear weight evaluations (#185)
1 parent c8facc2 commit 50f55a2

1 file changed

Lines changed: 20 additions & 6 deletions

File tree

src/whir/statement.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,22 +255,30 @@ impl<F: Field> Statement<F> {
255255
/// The number of variables in `w(X)` must match `self.num_variables`.
256256
pub fn add_constraint(&mut self, weights: Weights<F>, sum: F) {
257257
assert_eq!(weights.num_variables(), self.num_variables());
258+
let defer_evaluation = match &weights {
259+
Weights::Evaluation { .. } => false,
260+
Weights::Linear { .. } => true,
261+
};
258262
self.constraints.push(Constraint {
259263
weights,
260264
sum,
261-
defer_evaluation: false,
265+
defer_evaluation,
262266
});
263267
}
264268

265269
/// Inserts a constraint `(w(X), s)` at the front of the system.
266270
pub fn add_constraint_in_front(&mut self, weights: Weights<F>, sum: F) {
267271
assert_eq!(weights.num_variables(), self.num_variables());
272+
let defer_evaluation = match &weights {
273+
Weights::Evaluation { .. } => false,
274+
Weights::Linear { .. } => true,
275+
};
268276
self.constraints.insert(
269277
0,
270278
Constraint {
271279
weights,
272280
sum,
273-
defer_evaluation: false,
281+
defer_evaluation,
274282
},
275283
);
276284
}
@@ -282,10 +290,16 @@ impl<F: Field> Statement<F> {
282290
}
283291
self.constraints.splice(
284292
0..0,
285-
constraints.into_iter().map(|(weights, sum)| Constraint {
286-
weights,
287-
sum,
288-
defer_evaluation: false,
293+
constraints.into_iter().map(|(weights, sum)| {
294+
let defer_evaluation = match &weights {
295+
Weights::Evaluation { .. } => false,
296+
Weights::Linear { .. } => true,
297+
};
298+
Constraint {
299+
weights,
300+
sum,
301+
defer_evaluation,
302+
}
289303
}),
290304
);
291305
}

0 commit comments

Comments
 (0)