Skip to content

Commit

Permalink
Do not add a constraint for the empty tuple. (#1568)
Browse files Browse the repository at this point in the history
  • Loading branch information
chriseth committed Jul 12, 2024
1 parent 3801937 commit e1169a7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
20 changes: 20 additions & 0 deletions executor/src/constant_evaluator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,4 +609,24 @@ mod test {
("F.a".to_string(), convert([14, 15, 16, 17].to_vec()))
);
}

#[test]
fn do_not_add_constraint_for_empty_tuple() {
let input = r#"namespace N(4);
let f: -> () = || ();
let g: col = |i| {
// This returns an empty tuple, we check that this does not lead to
// a call to add_constraints()
f();
i
};
"#;
let analyzed = analyze_string::<GoldilocksField>(input);
assert_eq!(analyzed.degree(), 4);
let constants = generate(&analyzed);
assert_eq!(
constants[0],
("N.g".to_string(), convert([0, 1, 2, 3].to_vec()))
);
}
}
5 changes: 4 additions & 1 deletion pil-analyzer/src/evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,10 @@ impl<'a, 'b, T: FieldElement, S: SymbolLookup<'a, T>> Evaluator<'a, 'b, T, S> {
}
Operation::AddConstraint => {
let result = self.value_stack.pop().unwrap();
self.symbols.add_constraints(result, SourceRef::unknown())?;
match result.as_ref() {
Value::Tuple(t) if t.is_empty() => {}
_ => self.symbols.add_constraints(result, SourceRef::unknown())?,
}
}
};
}
Expand Down

0 comments on commit e1169a7

Please sign in to comment.