-
Notifications
You must be signed in to change notification settings - Fork 21
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
Unfolding of mutable references #671
Comments
This a known issue. We call it unfolding of mutable references. The issue is that unfolding only happens "atomically" within a statement so after checking let a = self.offset;
let b = self.index;
let new_offset = if a <= b {
0
} else {
a - b
};
self.offset = new_offset; We've been postponing this for a while, so it may be time to tackle it. The general case is complicated, but I think it shouldn't be terribly difficult to handle this example. |
Ah, alright. At least there's an easy workaround |
Adding an extra example for this extracted from vtock. #[flux::refined_by(head: int)]
pub struct AssignmentUnsafe {
#[flux::field({usize[head] | head >= 0})]
head: usize,
}
fn set(s: &mut AssignmentUnsafe) {
s.head = 0; // causes assignment might be unsafe, but it shouldn't
} |
The following code is safe, but flux flags that it may integer underflow:
fails with:
This does not happen if the function takes a immutable parameter. The following code passes:
The text was updated successfully, but these errors were encountered: