adds context variables to the knowledge base #1341
Merged
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.
Context variables are regular state variables and are introduced to enable stateful analyses. They are not stored in the knowledge base nor they are persistent. They are also not involved in the fixed point computation. At the same time, the data type of a stateful variable is not required to have the domain structure or even be ordered. Anything could be stored in the state.
Many analyses require a regular, non-monotonic and unordered, state. A good example, is an optimization analysis or a variable desugaring analysis that will come in one of the next pull requests. We may also find it useful and much more efficient to store some state of the analysis, like the current target or theory, in the context, rather than in the knowledge base or in the temporal promise.
Previously, if we needed to implement a stateful analysis we have to wrap the knowledge monad into the state monad, e.g., this is what we are doing in the Primus interpreter. It is however a little bit tedious and comes with some performance penalty. Essentially since it is superfluous, as the knowledge monad is already having the state. Another option to add an arbitrary state to the analysis is to cheat with the domain ordering and implement a timed data structure with the chain structure (i.e., where a more recent version is considered to have more informational content than the previous, despite the actual content). This approach is rather artificial and again comes with some unnecessary performance cost.