Hint ite statements#266
Conversation
katat
left a comment
There was a problem hiding this comment.
The reason it panics is the example you provided returns none for the ITE branches.
Let's first agree on the grammar on this enhanced ITE statement.
I would suggest to still align with the grammar supported in the constraint code:
let res = if cond {t1} else {t2};
In hint function for now, we would just add the support of return statement.
In your example, we would instead enforce it to be:
hint fn ite(xx: Field , arr: [Field;LEN]) -> Field {
let mut var = 0;
let res = if xx == 10 {
var = xx;
for idx in 0..LEN {
var = var + arr[idx];
}
xx * var // align with the existing grammar
} else {
return xx * xx // or it returns
}
return res;
}
This way aligns with the existing grammar in constraint mode, while avoiding adding too much complexity for this enhancement at this stage.
| .value(self, fn_env) | ||
| .cvars[0] | ||
| .clone(); | ||
| let ret = self.compile_block(fn_env, then_branch)?.unwrap().cvars[0].clone(); |
There was a problem hiding this comment.
why then_branch block isn't handled the same way as the else_branch block?
There was a problem hiding this comment.
shouldn't the fn_env.nest() and fn_env.pop() be called for each compile_block?
|
@katat hey sorry for the delay I am a little busy with some work this week. I will pick this up again after the weekend |
@katat I think I could not explain things in the issue so I have raised a draft pull request. For the example of
if_else.notaken in the pr it works as the blocks early returns but if I change the example to something like this:this causes the then_branch return type to panic. So how can I support these type of statements? moreover what about only if statements?