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

Ssa warn for constraints that will always succeed/fail #231

Closed
jfecher opened this issue Jun 7, 2022 · 2 comments
Closed

Ssa warn for constraints that will always succeed/fail #231

jfecher opened this issue Jun 7, 2022 · 2 comments

Comments

@jfecher
Copy link
Contributor

jfecher commented Jun 7, 2022

It is possible that code like constrain a != 0 can be known to always fail if the ssa pass evaluates a to 0, resulting in constrain 0 != 0. Before, the ssa code would crash with a failed assert that a != b, but PR #223 removed most of these in favor of having the code fail to verify instead.

Can we give better warning messages here that points users to the correct location in the source code?

@jfecher jfecher mentioned this issue Jun 9, 2022
@jfecher
Copy link
Contributor Author

jfecher commented Jun 9, 2022

It would be possible to give better diagnostics if the arguments to a constrain have const types during type checking, letting users know it will either always succeed/fail. We can issue a warning for the always succeed case and an error for the always fail case.

This would trigger the warning not only for things like constrain 0 < 5 but also:

for i in 2..10 {
    let i2 = i / 2;
    constrain i2 >= 1;
}

The main case this would fail to catch are cases using private variables that reduce to the two sides being equivalent:

fn foo(x: Field) {
    let y = x;
    constrain x == y; // no warning...
}

@kevaundray
Copy link
Contributor

The new ssa code contains source location information, so closing this. We can open a new issue if we need the new SSA to improve in its current functionality

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants