You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Rename expect_fail to should_fail or other phrases. #1197
expect_fail can be slightly confusing as an expression in some cases. For example, in the case ->
#[kani::proof]fnmain(){let x:i32 = kani::any();
kani::expect_fail(x == 5,"x is not 5!");}
It is unclear whether expect_fail(x == 5) ;- SUCCESS. Failed as Expected here implies that x is equal to 5 or if x is not equal to 5 when it fails. While the developer can leave a description that can help themselves understand the output better, the phrase itself should be enough
Proposed Solution
If we were to rename it to should_fail, it becomes easier to interpret this code as -
"the code should fail as x != 5 . SUCCESS means we can ensure, FAILURE means that we can't ensure."
Alternative titles -
should_fail
check_fail
ensure_fail
verify_fail
Note : This could be my personal biases and this might not be an issue for others.
changed the title [-]Rename `expect_fail` to `should_fail` or other phrases.[/-][+]Rename `expect_fail` to `should_fail` or some other phrase.[/+]on May 13, 2022
changed the title [-]Rename `expect_fail` to `should_fail` or some other phrase.[/-][+]Rename `expect_fail` to `should_fail` or other phrases.[/+]on May 13, 2022
Another wrinkle here is that behavior here isn't that it always fails. For instance, expect_fail(x) is not assert(!x). The behavior difference stem from "all traces through here satisfy this" to "at least one trace through here does not satisfy this". This could also play into the naming question for this feature...
Note :- After discussion, it was decided that the cause for the confusing phrasing was the use of double, triple negatives . When read as a complete statement i.e expect_fail(x == 5) ;- SUCCESS, Failed as Expected. There was also a question raised about the nature of the phrase - if it was existential or universal.
Resolution - We've decided to rename the expression to check_possible(x==5) :- POSSIBLE or check_possible(x==5) :- IMPOSSIBLE which leads to a clearer understanding that there is a trace or there is no trace that satisfies x == 5. Alternate names - assert_possible(x==5).
I worry about confusing users with "cover". Though maybe not, now that I'm thinking again. I guess we'd fail if a cover isn't reachable? So if a user saw cover and wanted to ensure a branch was covered, they'd actually get what they want if they put kani::cover(true) there, right?
I'm OK with either cover or satisfy, although, I recall from our meeting in May that people were slightly opposed to cover, perhaps because it's typically used in the context of line coverage.
Why not use both? (Rust sometimes uses several functions/macros that do the same thing).
I try to think of how users will find and make first use of something or find it as a feature. I think what people will probably want to do here is say "hey can I check that I'm hitting that branch?" Obviously one could put an assert(false) and see failure. But that's slightly inverted thinking. I think people would see putting cover(true) and seeing success as more in line with their intention.
And... that's literally a coverage use case, so... cover as a name choice seems fine. The more advanced notion of "covering a condition" can come after the simpler use of cover(true)
Activity
[-]Rename `expect_fail` to `should_fail` or other phrases.[/-][+]Rename `expect_fail` to `should_fail` or some other phrase.[/+][-]Rename `expect_fail` to `should_fail` or some other phrase.[/-][+]Rename `expect_fail` to `should_fail` or other phrases.[/+]tedinski commentedon May 13, 2022
Interesting.
Another wrinkle here is that behavior here isn't that it always fails. For instance,
expect_fail(x)is notassert(!x). The behavior difference stem from "all traces through here satisfy this" to "at least one trace through here does not satisfy this". This could also play into the naming question for this feature...jaisnan commentedon May 18, 2022
Note :- After discussion, it was decided that the cause for the confusing phrasing was the use of double, triple negatives . When read as a complete statement i.e
expect_fail(x == 5) ;- SUCCESS, Failed as Expected. There was also a question raised about the nature of the phrase - if it was existential or universal.Resolution - We've decided to rename the expression to
check_possible(x==5) :- POSSIBLEorcheck_possible(x==5) :- IMPOSSIBLEwhich leads to a clearer understanding that there is a trace or there is no trace that satisfiesx == 5.Alternate names -assert_possible(x==5).zhassan-aws commentedon May 20, 2022
Another candidate name is
check_satisfiableand the results would beSATISFIABLEandUNSATISFIABLE.zhassan-aws commentedon May 27, 2022
Even better is just
satisfyto be in line with other Kani macros/functions, e.g.assert,assume:Result: Satisfied OR Unsatisfiable
celinval commentedon Jun 15, 2022
Would this be the same as
cover(#696)?zhassan-aws commentedon Jun 18, 2022
Yes.
celinval commentedon Jun 21, 2022
Can we use
coverthen. :)tedinski commentedon Jun 21, 2022
I worry about confusing users with "cover". Though maybe not, now that I'm thinking again. I guess we'd fail if a
coverisn't reachable? So if a user sawcoverand wanted to ensure a branch was covered, they'd actually get what they want if they putkani::cover(true)there, right?zhassan-aws commentedon Jun 21, 2022
I'm OK with either
coverorsatisfy, although, I recall from our meeting in May that people were slightly opposed tocover, perhaps because it's typically used in the context of line coverage.Why not use both? (Rust sometimes uses several functions/macros that do the same thing).
celinval commentedon Aug 17, 2022
In my mind, this does work like branch coverage. :)
That said, I'm ok with either name. I just would really like to handle this properly.
tedinski commentedon Aug 17, 2022
fwiw, I slept on it and retracted my opposition to
covertedinski commentedon Aug 17, 2022
I guess to expand on that...
I try to think of how users will find and make first use of something or find it as a feature. I think what people will probably want to do here is say "hey can I check that I'm hitting that branch?" Obviously one could put an
assert(false)and see failure. But that's slightly inverted thinking. I think people would see puttingcover(true)and seeing success as more in line with their intention.And... that's literally a coverage use case, so...
coveras a name choice seems fine. The more advanced notion of "covering a condition" can come after the simpler use ofcover(true)