-
Notifications
You must be signed in to change notification settings - Fork 59
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
Implement generic assert_eq #247
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really nice to have! Great work @bufferhe4d !
@mimoo might want a round of review |
let's merge this one? |
comparisons.push(Comparison::VarConst(cvar.clone(), cst.clone())); | ||
} | ||
(ConstOrCell::Cell(lhs), ConstOrCell::Cell(rhs)) => { | ||
comparisons.push(Comparison::Vars(lhs.clone(), rhs.clone())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why return a comparisons array btw? Why not just do the constraints right here?
match (lhs_cvar, rhs_cvar) {
// two constants
(ConstOrCell::Const(a), ConstOrCell::Const(b)) => {
if a != b {
Err(Error::new(
"constraint-generation",
ErrorKind::AssertionFailed,
span,
))?
}
}
// a const and a var
(ConstOrCell::Const(cst), ConstOrCell::Cell(cvar))
| (ConstOrCell::Cell(cvar), ConstOrCell::Const(cst)) => {
compiler.backend.assert_eq_const(cvar, *cst, span)
}
(ConstOrCell::Cell(lhs), ConstOrCell::Cell(rhs)) => {
compiler.backend.assert_eq_var(lhs, rhs, span)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delayed reply. I think the reason was that I couldn't figure how to pass the compiler backend recursively. Hence used the table instead. I can look into it again to make it more elegant.
Adds generic assert_eq using #231.
It recursively goes through any nested structure like arrays or structs.