Skip to content
This repository has been archived by the owner on Apr 25, 2024. It is now read-only.

Make branch extraction more intelligent #652

Merged
merged 14 commits into from
Sep 18, 2023
Merged

Conversation

nwatson22
Copy link
Member

@nwatson22 nwatson22 commented Sep 13, 2023

Closes #632.

Before introducing a branch, simplify each of the would-be new nodes and see if they simplify to bottom
If there are more than 1 non-bottom node, add all these simplified nodes to the CFG, creating a split/branch. If not, simply continue straight-line execution.

This should reduce eliminate some infeasible branching by simplifying earlier in the process.

Also should eliminate repeated branching encountered in runtimeverification/evm-semantics#2065 when creating new proofs from branches.

@nwatson22 nwatson22 self-assigned this Sep 13, 2023
src/pyk/kcfg/explore.py Outdated Show resolved Hide resolved
@@ -377,14 +377,24 @@ def extend(
if self._check_abstract(node, kcfg):
return

if not kcfg.splits(target_id=node.id):
Copy link
Contributor

Choose a reason for hiding this comment

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

This check is no longer relevant?

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, as I understand, it was the check preventing us from branching over and over again. But by simplifying before branching when it tries to branch a second time without having made an execution step, one of the branches will now simplify to bottom and it won't branch.

Copy link
Contributor

Choose a reason for hiding this comment

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

What do you mean by 'over and over again', when can that happen? As part of looping code?

src/pyk/kcfg/explore.py Outdated Show resolved Hide resolved
src/pyk/kcfg/explore.py Outdated Show resolved Hide resolved

for constraint in branches:
cterm = node.cterm.add_constraint(constraint)
cterm, _ = self.cterm_simplify(cterm)
Copy link
Contributor

Choose a reason for hiding this comment

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

...and here use kast_simplify?

Copy link
Contributor

Choose a reason for hiding this comment

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

and maybe put the constraint back into the cterm if that's what's easier for branch later on...

Copy link
Member Author

Choose a reason for hiding this comment

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

Using kast_simplify. I removed for now the adding of the already simplified term as the new branch nodes.

Copy link
Member

Choose a reason for hiding this comment

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

Why kast_simplify instead of cterm_simplify?

Copy link
Member

Choose a reason for hiding this comment

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

I guess the argument is performance. Have we checked on KEVM that it solves the problems we had there?

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 don't myself know if it makes an appreciable difference to performance, but if it doesn't make any difference to have the configuration in there, it's just simpler.
I have checked and it does solve my issue with repeated branching. I'm not sure if there was a specific problem that prompted #632 or just a general observation. @PetarMax, do you have a KEVM example where this was causing problems that I could test this against?

@nwatson22 nwatson22 marked this pull request as ready for review September 15, 2023 23:39
Comment on lines +387 to +392
if len(branches) > 1:
kcfg.split_on_constraints(node.id, branches)
_LOGGER.info(
f'Found {len(branches)} branches using heuristic for node {node.id}: {shorten_hashes(node.id)}: {[self.kprint.pretty_print(bc) for bc in branches]}'
)
return
Copy link
Contributor

@PetarMax PetarMax Sep 18, 2023

Choose a reason for hiding this comment

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

In this case, will the unsimplified constraint be added to the configuration or will the Haskell backend simplify it? The problem that we had was that the booster was not able to simplify a given constraint. Perhaps just checking for #Bottom will be enough.

I will try to run this on an appropriate test from the engagement in question.

Copy link
Member

Choose a reason for hiding this comment

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

The unsimplified contsraint will be added, but that should be enough to make it only take the one branch on subsequent execute call.

Copy link
Member

Choose a reason for hiding this comment

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

If the backend can't simplify a constraint, then it needs more lemmas to do so, or is a bug in the backend.

@PetarMax PetarMax merged commit 744fbcd into master Sep 18, 2023
10 checks passed
@PetarMax PetarMax deleted the noah/extract-branches-fix branch September 18, 2023 08:23
Baltoli pushed a commit to runtimeverification/k that referenced this pull request Apr 9, 2024
Closes #632.

Before introducing a branch, simplify each of the would-be new nodes and
see if they simplify to bottom
If there are more than 1 non-bottom node, add all these simplified nodes
to the CFG, creating a split/branch. If not, simply continue
straight-line execution.

This should reduce eliminate some infeasible branching by simplifying
earlier in the process.

Also should eliminate repeated branching encountered in
runtimeverification/evm-semantics#2065 when
creating new proofs from branches.

---------

Co-authored-by: devops <[email protected]>
Co-authored-by: Petar Maksimović <[email protected]>
Baltoli pushed a commit to runtimeverification/k that referenced this pull request Apr 9, 2024
Closes #632.

Before introducing a branch, simplify each of the would-be new nodes and
see if they simplify to bottom
If there are more than 1 non-bottom node, add all these simplified nodes
to the CFG, creating a split/branch. If not, simply continue
straight-line execution.

This should reduce eliminate some infeasible branching by simplifying
earlier in the process.

Also should eliminate repeated branching encountered in
runtimeverification/evm-semantics#2065 when
creating new proofs from branches.

---------

Co-authored-by: devops <[email protected]>
Co-authored-by: Petar Maksimović <[email protected]>
Baltoli pushed a commit to runtimeverification/k that referenced this pull request Apr 10, 2024
Closes #632.

Before introducing a branch, simplify each of the would-be new nodes and
see if they simplify to bottom
If there are more than 1 non-bottom node, add all these simplified nodes
to the CFG, creating a split/branch. If not, simply continue
straight-line execution.

This should reduce eliminate some infeasible branching by simplifying
earlier in the process.

Also should eliminate repeated branching encountered in
runtimeverification/evm-semantics#2065 when
creating new proofs from branches.

---------

Co-authored-by: devops <[email protected]>
Co-authored-by: Petar Maksimović <[email protected]>
Baltoli pushed a commit to runtimeverification/k that referenced this pull request Apr 10, 2024
Closes #632.

Before introducing a branch, simplify each of the would-be new nodes and
see if they simplify to bottom
If there are more than 1 non-bottom node, add all these simplified nodes
to the CFG, creating a split/branch. If not, simply continue
straight-line execution.

This should reduce eliminate some infeasible branching by simplifying
earlier in the process.

Also should eliminate repeated branching encountered in
runtimeverification/evm-semantics#2065 when
creating new proofs from branches.

---------

Co-authored-by: devops <[email protected]>
Co-authored-by: Petar Maksimović <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Branch handling improvements
3 participants