Use local variables for the old state#482
Merged
Merged
Conversation
old expressions are not permitted in function specifications, so no old state setup is required
…oogie state The new encoding is more direct and treats the old state the same as any other normal state (except for the pure state) for the state components (heap and permission modules).
gauravpartha
commented
Dec 14, 2023
marcoeilers
approved these changes
Dec 14, 2023
e2c7dc7 to
7720316
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Before this PR, Carbon used Boogie's old state to model Viper's old state. As a result, Carbon deals with the old state differently compared to other states such as labelled old states. In particular, state components (i.e., the heap and permission modules) must explicitly wrap the currently tracked Boogie variable corresponding to the component with
old, which is reflected as a special case in the code.Moreover, the previous encoding is indirect because Boogie's old state conceptually does not capture Viper's state. The following encoding snippet previously used at the beginning of a method encoding illustrates this:
Viper's old state is the state after inhaling the precondition, while Boogie's old state is the state of the global variables right at the beginning of the Boogie procedure. The two assume statements after inhaling the precondition make sure that the two states are in-sync. The encoding is sound because the Boogie code before the assume statements does not use Boogie's old state at all. Thus, for any relevant Boogie trace, there is a corresponding one where
old(Heap)andold(Mask)match the values ofHeapandMaskright after inhaling the precondition.This pull request addresses both of these problems by introducing local Boogie variables that model the old state. The new encoding corresponding to the one shown above is:
This encoding is more direct. Moreover, this way of modeling the old state is the same as the approach that Carbon takes for other states (e.g., labelled old expressions). As a result, Carbon's state components (i.e., the heap and permission module) do not need to wrap their tracked variables with
old.Another positive consequence is that the Boogie old state does not show up in unexpected places. For example, when inhaling the postcondition
acc(x.f) && x.f == old(x.f)+1as part of a method call, the second conjunct was previously translated to:Here,
PreCallHeaphas the value of the heap right before the call, which thus symbolizes the old heap during the method call. The usage of the Boogieoldwrapper is redundant here sincePreCallHeapis a local variable. The reason Carbon uses theoldwrapper here is because whenever the body of an old expression is evaluated, the state is marked as being an old state, which then leads to the Carbon state components using using theoldwrapper. In the new encoding, the state components do not use theoldwrapper anymore (but the state is still marked as an old state in the Carbon implementation itself).