Skip to content

Conversation

@jberthold
Copy link
Member

@jberthold jberthold commented Jul 27, 2022

Related to #3119
Part of #3143

Scope:

Rewrite of graph traversal used by Kore.Exec and Kore.Reachability.Prove

New traversal models required functionality in data types rather than using exceptions and monad stack layers to add functionality.

The graphTraversal function operates with a list of "steps" (sequences of "instructions") that take a configuration to a result containing new configurations.
The traversal is parameterised with a specific transition function
([Step instr],config) -> m (TransitionResult ([Step instr],config))
which interprets step results. TransitionResult can indicate to continue with one (Continuing) or more (Branch) new configurations, or that the configuration is final, stuck, or should be stopped.
One reason to stop is when the list of steps runs empty, other reasons could be to stop execuction on the application of certain rules.

The transition function can be constructed from one that operates on the primitive instructions, together with an interpretation function that differs depending on the use case (proving or executing).

Estimate:


Review checklist

The author performs the actions on the checklist. The reviewer evaluates the work and checks the boxes as they are completed.

  • Summary. Write a summary of the changes. Explain what you did to fix the issue, and why you did it. Present the changes in a logical order. Instead of writing a summary in the pull request, you may push a clean Git history.
  • Documentation. Write documentation for new functions. Update documentation for functions that changed, or complete documentation where it is missing.
  • Tests. Write unit tests for every change. Write the unit tests that were missing before the changes. Include any examples from the reported issue as integration tests.
  • Clean up. The changes are already clean. Clean up anything near the changes that you noticed while working. This does not mean only spatially near the changes, but logically near: any code that interacts with the changes!

@github-actions
Copy link

name diff_allocated_bytes diff_max_live_bytes
test/regression-evm/test-lemmas.sh -0.028928 -0.004952
test/regression-evm/test-dsvalue-peek-pass-rough.sh -0.029142 0.003074
test/regression-evm/test-storagevar03.sh -0.040157 0.002428
test/regression-evm/test-totalSupply.sh -0.036058 -0.001498
test/regression-evm/test-addu48u48.sh -0.008692 0.000000
test/regression-evm/test-sum-to-n.sh -0.034909 0.002221
test/regression-wasm/test-memory.sh -0.016476 0
test/regression-wasm/test-wrc20.sh -0.028617 -0.019614
test/regression-wasm/test-simple-arithmetic.sh -0.006978 0
test/regression-wasm/test-locals.sh -0.001667 -0.000001
test/regression-wasm/test-loops.sh -0.017519 0

@github-actions
Copy link

name diff_allocated_bytes diff_max_live_bytes
test/regression-evm/test-lemmas.sh -0.028927 -0.004572
test/regression-evm/test-dsvalue-peek-pass-rough.sh -0.029153 -0.000478
test/regression-evm/test-storagevar03.sh -0.040157 -0.000054
test/regression-evm/test-totalSupply.sh -0.036046 0.000141
test/regression-evm/test-addu48u48.sh -0.008692 0.000000
test/regression-evm/test-sum-to-n.sh -0.034918 -0.005944
test/regression-wasm/test-memory.sh -0.016500 0
test/regression-wasm/test-wrc20.sh -0.028624 -0.012234
test/regression-wasm/test-simple-arithmetic.sh -0.006974 0
test/regression-wasm/test-locals.sh -0.001668 -0.000000
test/regression-wasm/test-loops.sh -0.017522 0

@github-actions
Copy link

name diff_allocated_bytes diff_max_live_bytes
test/regression-evm/test-lemmas.sh -0.028927 -0.000043
test/regression-evm/test-dsvalue-peek-pass-rough.sh -0.029202 0.005311
test/regression-evm/test-storagevar03.sh -0.040158 0.000561
test/regression-evm/test-totalSupply.sh -0.036046 0.003214
test/regression-evm/test-addu48u48.sh -0.008692 -0.000000
test/regression-evm/test-sum-to-n.sh -0.034919 0.006631
test/regression-wasm/test-memory.sh -0.016491 0
test/regression-wasm/test-wrc20.sh -0.028626 0.000506
test/regression-wasm/test-simple-arithmetic.sh -0.006978 0
test/regression-wasm/test-locals.sh -0.001668 0
test/regression-wasm/test-loops.sh -0.017550 0

@github-actions
Copy link

name diff_allocated_bytes diff_max_live_bytes
test/regression-evm/test-lemmas.sh -0.028932 -0.003921
test/regression-evm/test-dsvalue-peek-pass-rough.sh -0.029188 0.008492
test/regression-evm/test-storagevar03.sh -0.040161 -0.000028
test/regression-evm/test-totalSupply.sh -0.036046 -0.000962
test/regression-evm/test-addu48u48.sh -0.008694 -0.012474
test/regression-evm/test-sum-to-n.sh -0.034923 0.001440
test/regression-wasm/test-memory.sh -0.016490 0
test/regression-wasm/test-wrc20.sh -0.028641 -0.001397
test/regression-wasm/test-simple-arithmetic.sh -0.006971 0
test/regression-wasm/test-locals.sh -0.001668 0
test/regression-wasm/test-loops.sh -0.017529 0

@github-actions
Copy link

name diff_allocated_bytes diff_max_live_bytes
test/regression-evm/test-lemmas.sh -0.028928 0.000386
test/regression-evm/test-dsvalue-peek-pass-rough.sh -0.029149 0.005383
test/regression-evm/test-storagevar03.sh -0.040157 0.001865
test/regression-evm/test-totalSupply.sh -0.036046 0.001227
test/regression-evm/test-addu48u48.sh -0.008693 -0.000000
test/regression-evm/test-sum-to-n.sh -0.034924 -0.000509
test/regression-wasm/test-memory.sh -0.016492 0
test/regression-wasm/test-wrc20.sh -0.028634 -0.001108
test/regression-wasm/test-simple-arithmetic.sh -0.006958 0
test/regression-wasm/test-locals.sh -0.001668 0.000000
test/regression-wasm/test-loops.sh -0.017527 -0.000000

@github-actions
Copy link

name diff_allocated_bytes diff_max_live_bytes
test/regression-evm/test-lemmas.sh -0.028932 0.000400
test/regression-evm/test-dsvalue-peek-pass-rough.sh -0.029147 0.003966
test/regression-evm/test-storagevar03.sh -0.040162 -0.000216
test/regression-evm/test-totalSupply.sh -0.036063 -0.002928
test/regression-evm/test-addu48u48.sh -0.008692 -0.000000
test/regression-evm/test-sum-to-n.sh -0.034923 -0.000550
test/regression-wasm/test-memory.sh -0.016503 0
test/regression-wasm/test-wrc20.sh -0.028628 -0.013173
test/regression-wasm/test-simple-arithmetic.sh -0.006970 0
test/regression-wasm/test-locals.sh -0.001668 0
test/regression-wasm/test-loops.sh -0.017574 0

New traversal models required functionality in data types rather than
using exceptions and monad stack layers to add functionality.

The `graphTraversal` function operates with a list of "steps"
(sequences of "instructions") that take a configuration to a result
containing new configurations.

The traversal is parameterised with a specific transition function
`([Step instr],config) -> m (TransitionResult ([Step instr],config))`
which interprets step results. `TransitionResult` can indicate to
continue with one (`Continuing`) or more (`Branch`) new
configurations, or that the configuration is final, stuck, or should
be stopped.

One reason to stop is when the list of steps runs empty, other reasons
could be to stop execuction on the application of certain rules.

The transition function can be constructed from one that operates on
the primitive instructions, together with an interpretation function
that differs depending on the use case (proving or executing).
@jberthold jberthold force-pushed the 3119-rewrite-graph-traversal-output-unexplored-leaves branch from 466f594 to 1662e72 Compare July 28, 2022 12:38
@jberthold jberthold changed the title #3119 rewrite graph traversal + output unexplored leaves #3143 rewrite graph traversal + output unexplored leaves Jul 28, 2022
@jberthold jberthold marked this pull request as ready for review July 28, 2022 12:41
@github-actions
Copy link

name diff_allocated_bytes diff_max_live_bytes
test/regression-evm/test-lemmas.sh -0.028928 0.000416
test/regression-evm/test-dsvalue-peek-pass-rough.sh -0.029169 -0.001355
test/regression-evm/test-storagevar03.sh -0.040152 -0.002895
test/regression-evm/test-totalSupply.sh -0.036046 0.000458
test/regression-evm/test-addu48u48.sh -0.008691 0.000000
test/regression-evm/test-sum-to-n.sh -0.034921 -0.001203
test/regression-wasm/test-memory.sh -0.016501 0
test/regression-wasm/test-wrc20.sh -0.028630 -0.018141
test/regression-wasm/test-simple-arithmetic.sh -0.006962 0
test/regression-wasm/test-locals.sh -0.001668 0
test/regression-wasm/test-loops.sh -0.017503 0

Copy link
Contributor

@ana-pantilie ana-pantilie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach is definitely friendlier than the old one, but I think it's still a bit hard to understand just by reading the code, so my suggestions currently concern readability.

I also noticed that allocation has decreased a bit. Should we expect some performance improvements as well? That would be amazing. 😁

import Kore.Simplify.Data (Simplifier)
import Prelude.Kore
import Pretty

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this module would benefit from some extra documentation. My first thought was, how do TransitionResult, StepResult and TraversalResult all relate to eachother?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added documentation that describes all these types together, in a haddock comment on graphTraversal. Is this what you had in mind?

-- execution is not a generic tree, but a cofree comonad with exactly the
-- branching structure described by the strategy algebra.
data Strategy prim where
-- The recursive arguments of these constructors are /intentionally/ lazy to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably out of scope for this PR, but we should probably keep in mind that we'd like to get rid of this type in the near future. Maybe a subsequent PR could take care of that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this type (and maybe even the whole module Strategy) is on the list of things to remove. I would think we lift everything worth keeping into the new GraphTraversal module.
Currently the Prove module still uses Strategy for the single-step function, and the repl uses the computation graph directly. Removing this and consolidating the parts we need from Strategy into GraphTraversal would be follow-up work in a new ticket and PR.

@jberthold
Copy link
Member Author

I also noticed that allocation has decreased a bit. Should we expect some performance improvements as well? That would be amazing.

The new version is a bit faster, yes. My experiment PR had some KEVM timing comparisons - around 3% faster overall, most of it probably because of using Simplifier instead of MonadSimplify. Other optimisations landed at the same time, so it is hard to tell...

Comment on lines +101 to +105
"flake-utils_2": {
"locked": {
"lastModified": 1642700792,
"narHash": "sha256-XqHrk7hFb+zBvRg6Ghl+AZDq03ov6OshJLiSWOoX5es=",
"owner": "numtide",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes here were auto-generated from running command nix run .#update-cabal-ghc9 (as instructed by @goodlyrottenapple )

@github-actions
Copy link

name diff_allocated_bytes diff_max_live_bytes
test/regression-evm/test-lemmas.sh -0.028928 0.004876
test/regression-evm/test-dsvalue-peek-pass-rough.sh -0.029158 0.006755
test/regression-evm/test-storagevar03.sh -0.040155 -0.002898
test/regression-evm/test-totalSupply.sh -0.036046 -0.002259
test/regression-evm/test-addu48u48.sh -0.008691 -0.009433
test/regression-evm/test-sum-to-n.sh -0.034919 -0.006403
test/regression-wasm/test-memory.sh -0.016493 0
test/regression-wasm/test-wrc20.sh -0.028630 -0.004296
test/regression-wasm/test-simple-arithmetic.sh -0.006978 0
test/regression-wasm/test-locals.sh -0.001668 0
test/regression-wasm/test-loops.sh -0.017547 0

@github-actions
Copy link

name diff_allocated_bytes diff_max_live_bytes
test/regression-evm/test-lemmas.sh -0.028937 -0.001322
test/regression-evm/test-dsvalue-peek-pass-rough.sh -0.029139 -0.000677
test/regression-evm/test-storagevar03.sh -0.040150 -0.002086
test/regression-evm/test-totalSupply.sh -0.036038 0.000451
test/regression-evm/test-addu48u48.sh -0.008690 0.000007
test/regression-evm/test-sum-to-n.sh -0.034919 -0.000518
test/regression-wasm/test-memory.sh -0.016493 0.000000
test/regression-wasm/test-wrc20.sh -0.028633 0.005457
test/regression-wasm/test-simple-arithmetic.sh -0.006966 -0.000000
test/regression-wasm/test-locals.sh -0.001669 -0.000171
test/regression-wasm/test-loops.sh -0.017612 0

Copy link
Contributor

@ana-pantilie ana-pantilie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 🎉

@github-actions
Copy link

name diff_allocated_bytes diff_max_live_bytes
test/regression-evm/test-lemmas.sh -0.032323 -0.001320
test/regression-evm/test-dsvalue-peek-pass-rough.sh -0.032151 0.001156
test/regression-evm/test-storagevar03.sh -0.044222 0.000889
test/regression-evm/test-totalSupply.sh -0.040038 0.000609
test/regression-evm/test-addu48u48.sh -0.009559 0.012531
test/regression-evm/test-sum-to-n.sh -0.038767 0.005520
test/regression-wasm/test-memory.sh -0.018192 -0.000000
test/regression-wasm/test-wrc20.sh -0.031526 -0.013809
test/regression-wasm/test-simple-arithmetic.sh -0.007759 0
test/regression-wasm/test-locals.sh -0.001872 0.000000
test/regression-wasm/test-loops.sh -0.019409 0

@rv-jenkins rv-jenkins merged commit f2aad03 into master Jul 29, 2022
@rv-jenkins rv-jenkins deleted the 3119-rewrite-graph-traversal-output-unexplored-leaves branch July 29, 2022 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants