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

Do not add a constraint for the empty tuple. #1568

Merged
merged 1 commit into from
Jul 12, 2024
Merged
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
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
Loading