noir-lang / noir

Noir is a domain specific language for zero knowledge proofs
https://noir-lang.org
Apache License 2.0
887 stars 198 forks source link

Implement && and || #162

Open jfecher opened 2 years ago

jfecher commented 2 years ago

These logical operators are currently unimplemented presumably because they are sugar for if a then b else false and if a then true else b respectively - and if statements are also unimplemented. If keeping lazy evaluation for these operators would be as slow as we believe if will be at runtime - it may be preferable to make these operators strict instead.

jfecher commented 2 years ago

Update: with the approach of preventing side effectful computations in if branches via passing a boolean condition to the side effectful function, we could use that to implement these operators if we want to as well. The naive desugaring to if in my previous comment would automatically benefit from handling side effects this way. Then we can implement it as long as it wouldn't incur a large runtime penalty.

kevaundray commented 1 year ago

@jfecher can this be closed?

jfecher commented 1 year ago

No, it is still a valid design question of whether we want these operators. It could make the Rust -> Noir transition slightly easier for example.

TomAFrench commented 4 months ago

Personally I think this is more of a footgun than a useful feature considering the restrictions of ACIR. We could potentially allow this as a brillig-only feature however.

jfecher commented 4 months ago

I do think the different precedence of && and || would make them a useful addition. I think we should make the change, updating the stdlib to use && and || over their bitwise variants, then see just how many more constraints are generated so that we can have some estimate.