-
Notifications
You must be signed in to change notification settings - Fork 0
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
Stronger Map matching and selected map hooks #506
Conversation
Previously, only fully concrete maps (all keys and values identical) would have matched, which is highly unlikely when matching simplification rules. Now we compare the key sets for (syntactic) equality after substituting with the current substitution, and then try to perform matching on the remainder if a solution is at all possible. Most importantly, maps of fully-concrete keys can now be handled, matching the contained values. In addition, the case of matching a single unknown key out of a singleton map (i.e., without opaque rest in the subject map) is now possible. Any ambiguous case is still rejected as `MatchIndeterminate` but some cases can be decided as `MatchFailed` immediately.
As an alternative to modifying rules in `domains.md`, this change implements 3 crucial hooks for internalised `Map`s: * `lookup`: partial function that looks up a value for a given key in a map. Returns no result when the key is not present. * `lookupOrDefault`: total function that looks up a value for a given key in a map. If the key is not present, it returns a given default value instead. The implemented hook won't return any result when the presence of the key cannot be decided. * `in_keys`: predicate that checks whether a given key is present in a map. The implemented hook won't return any result if the presence of the key cannot be decided. All three hooks are conservative, not returning any results when they find unevaluated (parts of the) arguments. These hooks, together with the enhanced `Map`-matching of #502, avoid a fall-back to legacy `kore-rpc` in an issue reported in #498. Alternatively, more suitable rules for `in_keys` could be added to `domains.md`, and the rules for `lookup` and `lookupOrDefault` could be marked as `preserves-definedness` so `booster` will use them.
Regression tests do not show any impact KEVM regression tests
|
Test | EXPERIMENT-selected-MAP-hooks time | master-ac4575c time | (EXPERIMENT-selected-MAP-hooks/master-ac4575c) time |
---|---|---|---|
BytesTypeTest.test_bytes4(bytes4) | 23.3 | 25.16 | 0.9260731319554849 |
BlockParamsTest.testCoinBase() | 26.13 | 27.38 | 0.954346238130022 |
BlockParamsTest.testChainId(uint256) | 30.72 | 31.99 | 0.960300093779306 |
AddrTest.test_notBuiltinAddress_concrete() | 18.36 | 19.03 | 0.9647924330005254 |
StoreTest.testGasLoadWarmUp() | 61.33 | 59.11 | 1.0375570969379124 |
TOTAL | 159.84 | 162.67 | 0.9826028155160754 |
Repeated measurement with
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation and test cases look comprehensive!
I think I would like to have two more things:
- an integration tests that would have failed in
booster-dev
before this change and not succeeds; - a file in the
docs/
directory with a short textual description of the matching algorithm. I find the inline comments in the implementation very insightful, but I also think that we need to document the matching (and unification) algorithms at a higher level.
The second item (docs) could be left for a follow-up PR.
I have added integration tests in
OK, let's do this in a follow-up. We can maybe also document the hook implementation structure (but that's more developer-facing than the matching/unification overview) |
|
||
mapLookupHook :: BuiltinFunction | ||
mapLookupHook args | ||
| [KMap _ pairs _mbRest, key] <- args = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will we eventually have to return something like #bottom
here in case we know this is a fully concrete map?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably that would be the correct way - we know the result is "undefined" so no point trying any equations.
Our types currently do not allow Term
s to be #Bottom
- we would need to add an explicit term-bottom constructor.
Stronger
Map
matchingPreviously, only fully concrete maps (all keys and values identical) would have matched, which is highly unlikely when matching simplification rules.
Now we compare the key sets for (syntactic) equality after substituting with the current substitution, and then try to perform matching on the remainder if a solution is at all possible. Most importantly, maps of fully-concrete keys can now be handled, matching the contained values. In addition, the case of matching a single unknown key out of a singleton map (i.e., without opaque rest in the subject map) is now possible.
Any ambiguous case is still rejected as
MatchIndeterminate
but some cases can be decided asMatchFailed
immediately.Selected hooks for
Map
This change implements 3 crucial hooks for internalised
Map
s:lookup
: partial function that looks up a value for a given key in a map. Returns no result when the key is not present.lookupOrDefault
: total function that looks up a value for a given key in a map. If the key is not present, it returns a given default value instead.The implemented hook won't return any result when the presence of the key cannot be decided.
in_keys
: predicate that checks whether a given key is present in a map. The implemented hook won't return any result if the presence of the key cannot be decided.All three hooks are conservative, not returning any results when they find unevaluated (parts of the) arguments.
These hooks, together with the enhanced
Map
-matching of #502, avoid a fall-back to legacykore-rpc
in an issue reported in #498.Alternatively, more suitable rules for
in_keys
could be added todomains.md
, and the rules forlookup
andlookupOrDefault
could be marked aspreserves-definedness
sobooster
will use them.Fixes #498