Skip to content

Rename expect_fail to should_fail or other phrases. #1197

Closed

Description

@jaisnan

Use Case

expect_fail can be slightly confusing as an expression in some cases. For example, in the case ->

#[kani::proof]
fn main() {
    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 -

  1. should_fail
  2. check_fail
  3. ensure_fail
  4. verify_fail

Note : This could be my personal biases and this might not be an issue for others.

Activity

  1. 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
  2. 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
  3. tedinski commented on May 13, 2022

    @tedinski
    Contributor

    Interesting.

    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...

  4. jaisnan commented on May 18, 2022

    @jaisnan
    ContributorAuthor

    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).

  5. zhassan-aws commented on May 20, 2022

    @zhassan-aws
    Contributor

    Another candidate name is check_satisfiable and the results would be SATISFIABLE and UNSATISFIABLE.

  6. zhassan-aws commented on May 27, 2022

    @zhassan-aws
    Contributor

    Another candidate name is check_satisfiable

    Even better is just satisfy to be in line with other Kani macros/functions, e.g. assert, assume:

    kani::satisfy(x > 5);
    

    Result: Satisfied OR Unsatisfiable

  7. celinval commented on Jun 15, 2022

    @celinval
    Contributor

    Would this be the same as cover (#696)?

  8. zhassan-aws commented on Jun 18, 2022

    @zhassan-aws
    Contributor

    Yes.

  9. celinval commented on Jun 21, 2022

    @celinval
    Contributor

    Can we use cover then. :)

  10. tedinski commented on Jun 21, 2022

    @tedinski
    Contributor

    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?

  11. zhassan-aws commented on Jun 21, 2022

    @zhassan-aws
    Contributor

    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).

  12. celinval commented on Aug 17, 2022

    @celinval
    Contributor

    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.

  13. tedinski commented on Aug 17, 2022

    @tedinski
    Contributor

    fwiw, I slept on it and retracted my opposition to cover

  14. tedinski commented on Aug 17, 2022

    @tedinski
    Contributor

    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 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)

  15. added
    [C] Feature / Enhancement
    and removed on Nov 9, 2022
  16. self-assigned this
    on Dec 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

[C] Feature / Enhancement

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions