-
Notifications
You must be signed in to change notification settings - Fork 41
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
Add proof for Result method check_unwrap_unchecked
#35
Conversation
As shown by the CI run here, this proof fails verification with the following property failure
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally, both Result<u32, u64> and Result<(), ()> trigger the same failure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @jaisnan, let's investigate why this is failing.
let val: Result<u32, u64> = kani::any(); | ||
let ok_variant: Result<u32, u64> = Ok(0); | ||
let copy = unsafe { ok_variant.unwrap_unchecked() }; | ||
assert_eq!(val, Result::Ok(copy)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since val
is a nondeterministic Result
, it's not necessary equal to Result::Ok(0)
(it could also be Result::Err
, or Result::Ok(12)
, etc.).
Instead, I'd write:
pub fn check_unwrap_unchecked() {
let val: u32= kani::any();
let ok_variant: Result<u32, u64> = Ok(val);
let copy = unsafe { ok_variant.unwrap_unchecked() };
assert_eq!(val, copy);
}
which passes verification for me locally.
(I'd also add harnesses for other types besides u32
and for unwrap_err_unchecked
, but I assume you were planning on that).
Adds a simple contract that checks for memory safety in
check_unwrap_unchecked
.Also useful for my secret agenda of testing the PR workflow in production.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.