Conditional flyweight pattern for terms#692
Merged
Merged
Conversation
…rejects them, dropping MCE macros which lead to additional terms
Contributor
Author
|
I hereby request a review from @mschwerhoff :) |
mschwerhoff
approved these changes
Apr 12, 2023
mschwerhoff
left a comment
Contributor
There was a problem hiding this comment.
A few minor comments, but no objections to merging this PR.
Contributor
Ask, and it shall be given to you 😇 |
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.
This PR implements the flyweight pattern for Silicon terms in a way that can be turned on or off (depending on the value of
Verifier.config.useFlyweight).The motivation is that the flyweight pattern is required to use the Z3 API in a fast way (since translating the same term multiple times slows down the Z3 API massively for large examples with many terms, so they need to be cached, which is too slow unless flyweight is used) but using the flyweight pattern slows down Silicon when using Z3 via StdIO. Thus,
Verifier.config.useFlyweightis set to true nly if Z3 is used via its API.The PR borrows code and ideas from the flyweight pattern implementation by Fabian Bösiger, but does not use Scala macros to avoid IDE issues.
Instead, it uses
ConditionalFlyweightthat is implemented by allTermclasses, which defines equality andhashCodeeither based on reference equality (ifVerifier.config.useFlyweightis set) or otherwise on the values of a fieldequalityDefiningMembers, similar to the existingStructuralEqualitytrait.GeneralCondFlyweightFactory(and some more specific subtraits), to be implemented by companion objects of allTermclasses, which contains aTrieMapto cache all existing instances of the class, and defines functionality for conditionally creating new instances or first checking for existing ones in the cache, again based on the value ofVerifier.config.useFlyweight.(Also, the PR fixes parameter handling in the Z3 API.)