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

Commit be26278

Browse files
nwatson22rv-auditorehildenb
authored
Add ability to pass in custom function to KCFGExplore for modifying new nodes (#498)
This PR adds the ability to pass in a function simplify_node: CTerm->CTerm to `KCFGExplore()` which modifies new nodes as they are added during exploration. This is intended to be used to accomplish runtimeverification/evm-semantics#1909. --------- Co-authored-by: devops <devops@runtimeverification.com> Co-authored-by: Everett Hildenbrandt <everett.hildenbrandt@gmail.com>
1 parent f0890ca commit be26278

3 files changed

Lines changed: 22 additions & 3 deletions

File tree

package/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.338
1+
0.1.339

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
66
name = "pyk"
7-
version = "0.1.338"
7+
version = "0.1.339"
88
description = ""
99
authors = [
1010
"Runtime Verification, Inc. <contact@runtimeverification.com>",

src/pyk/proof/reachability.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,16 +257,19 @@ class APRProver:
257257
proof: APRProof
258258
_is_terminal: Callable[[CTerm], bool] | None
259259
_extract_branches: Callable[[CTerm], Iterable[KInner]] | None
260+
_abstract_node: Callable[[CTerm], CTerm] | None
260261

261262
def __init__(
262263
self,
263264
proof: APRProof,
264265
is_terminal: Callable[[CTerm], bool] | None = None,
265266
extract_branches: Callable[[CTerm], Iterable[KInner]] | None = None,
267+
abstract_node: Callable[[CTerm], CTerm] | None = None,
266268
) -> None:
267269
self.proof = proof
268270
self._is_terminal = is_terminal
269271
self._extract_branches = extract_branches
272+
self._abstract_node = abstract_node
270273

271274
def _check_terminal(self, curr_node: KCFG.Node) -> bool:
272275
if self._is_terminal is not None:
@@ -290,6 +293,18 @@ def _check_subsume(self, kcfg_explore: KCFGExplore, node: KCFG.Node) -> bool:
290293
return True
291294
return False
292295

296+
def _check_abstract(self, node: KCFG.Node) -> bool:
297+
if self._abstract_node is None:
298+
return False
299+
300+
new_cterm = self._abstract_node(node.cterm)
301+
if new_cterm == node.cterm:
302+
return False
303+
304+
new_node = self.proof.kcfg.create_node(new_cterm)
305+
self.proof.kcfg.create_cover(node.id, new_node.id)
306+
return True
307+
293308
def advance_proof(
294309
self,
295310
kcfg_explore: KCFGExplore,
@@ -316,6 +331,9 @@ def advance_proof(
316331
if self._check_terminal(curr_node):
317332
continue
318333

334+
if self._check_abstract(curr_node):
335+
continue
336+
319337
if self._extract_branches is not None and len(self.proof.kcfg.splits(target_id=curr_node.id)) == 0:
320338
branches = list(self._extract_branches(curr_node.cterm))
321339
if len(branches) > 0:
@@ -349,8 +367,9 @@ def __init__(
349367
same_loop: Callable[[CTerm, CTerm], bool],
350368
is_terminal: Callable[[CTerm], bool] | None = None,
351369
extract_branches: Callable[[CTerm], Iterable[KInner]] | None = None,
370+
abstract_node: Callable[[CTerm], CTerm] | None = None,
352371
) -> None:
353-
super().__init__(proof, is_terminal=is_terminal, extract_branches=extract_branches)
372+
super().__init__(proof, is_terminal=is_terminal, extract_branches=extract_branches, abstract_node=abstract_node)
354373
self._same_loop = same_loop
355374
self._checked_nodes = []
356375

0 commit comments

Comments
 (0)