-
Notifications
You must be signed in to change notification settings - Fork 36
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
Semantic of Multiple Assignments #879
Comments
An interesting example is swap:
This method would fail the disjointness test but, in reality, it's fine for the case when they are the same. Maybe this doesn't matter because we can always code it using a temporary variable. |
NOTES: if I persist with making the assignment atomic, then realistically it will need a disjointness requirement. Otherwise, it doesn't make sense to atomically assign two things to the same variable. I suppose one could argue that we can simply introduce a "race condition" whereby we don't know which it is. But, this seems wrong to me!! |
One reason for making it atomic is to enable the possibility that it compiles down to a single Compare And Swap instruction. For example, this could compile down:
This is not a valid implementation of compare and swap, however, as there is no conditional assignment. I'm not sure whether or not it's enough. |
Curiously enough, it seems that the Whiley verifier already handles this following a non-atomic approach where by the assignments are made in left-to-right order. The following illustrates:
This verifies. However, swapping the right-hand side to |
Another interesting example is the following which, correctly, fails to verify:
|
This should be written up as RFC and added the language specification? |
Migrated to Whiley/RFCs#44 |
An interesting question raised by @utting is what the real semantics for multiple assignments of the form
x,y = e1,e2
are. For example, what about these statements:The question here is: what does it mean when the left-hand sides are not disjoint?
IDEA: One approach here is to require that they are disjoint. This would mean, for example, introducing proof obligations to establish that they are.
NOTES: The general assumption has been that the evaluation order follows left-to-right. Hence, all left-hand sides are evaluated first, then all right-hand sides and, finally, the assignment occurs (atomically).
The text was updated successfully, but these errors were encountered: