From 744fbcdcd967bbf3124d7385a5ea10d0a56fff72 Mon Sep 17 00:00:00 2001 From: Noah Watson <107630091+nwatson22@users.noreply.github.com> Date: Mon, 18 Sep 2023 03:23:45 -0500 Subject: [PATCH] Make branch extraction more intelligent (#652) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 https://github.com/runtimeverification/evm-semantics/pull/2065 when creating new proofs from branches. --------- Co-authored-by: devops Co-authored-by: Petar Maksimović --- package/version | 2 +- pyproject.toml | 2 +- src/pyk/kcfg/explore.py | 21 +++++++++++++-------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/package/version b/package/version index 5abb16f50..8cc010e6a 100644 --- a/package/version +++ b/package/version @@ -1 +1 @@ -0.1.443 +0.1.444 diff --git a/pyproject.toml b/pyproject.toml index 73447ac3a..7dcb3ba3c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "pyk" -version = "0.1.443" +version = "0.1.444" description = "" authors = [ "Runtime Verification, Inc. ", diff --git a/src/pyk/kcfg/explore.py b/src/pyk/kcfg/explore.py index 0c77167a3..68cf785ef 100644 --- a/src/pyk/kcfg/explore.py +++ b/src/pyk/kcfg/explore.py @@ -377,14 +377,19 @@ def extend( if self._check_abstract(node, kcfg): return - if not kcfg.splits(target_id=node.id): - branches = self.kcfg_semantics.extract_branches(node.cterm) - if branches: - 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 + _branches = self.kcfg_semantics.extract_branches(node.cterm) + branches = [] + for constraint in _branches: + kast = mlAnd(list(node.cterm.constraints) + [constraint]) + kast, _ = self.kast_simplify(kast) + if not CTerm._is_bottom(kast): + branches.append(constraint) + 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 _LOGGER.info(f'Extending KCFG from node {self.id}: {shorten_hashes(node.id)}') _is_vacuous, depth, cterm, next_cterms, next_node_logs = self.cterm_execute(