Skip to content

Commit 5b3bdc7

Browse files
authored
pyk: add node_id to custom_step (#4907)
This PR adds a new parameter that is passed to custom steps in pyk. Specifically, the `node_id` is passed so that it can be used in downstream custom steps. This is required for a downstream PR in kontrol (runtimeverification/kontrol#1131) that adds the node id to console log cheatcode logging, which is implemented by means of a custom step. This PR will require adjustments in some downstream dependencies as well such as kevm. However, not all downstream dependencies make use of custom steps such as, e.g., wasm-semantics and komet.
1 parent 7d503d9 commit 5b3bdc7

4 files changed

Lines changed: 17 additions & 8 deletions

File tree

pyk/src/pyk/kcfg/explore.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def extend_cterm(
220220
module_name: str | None = None,
221221
) -> list[KCFGExtendResult]:
222222

223-
custom_step_result = self.kcfg_semantics.custom_step(_cterm, self.cterm_symbolic)
223+
custom_step_result = self.kcfg_semantics.custom_step(_cterm, self.cterm_symbolic, node_id)
224224
if custom_step_result is not None:
225225
return [custom_step_result]
226226

pyk/src/pyk/kcfg/semantics.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,18 @@ def can_make_custom_step(self, c: CTerm) -> bool: ...
3535
"""Check whether or not the semantics can make a custom step from a given ``CTerm``."""
3636

3737
@abstractmethod
38-
def custom_step(self, c: CTerm, cs: CTermSymbolic) -> KCFGExtendResult | None: ...
39-
40-
"""Implement a custom semantic step."""
38+
def custom_step(self, c: CTerm, cs: CTermSymbolic, node_id: int) -> KCFGExtendResult | None: ...
39+
40+
"""Implement a custom semantic step.
41+
42+
Args:
43+
c: Current constrained term representing the state.
44+
cs: ``CTermSymbolic`` for computing the custom step result.
45+
node_id: Current node id.
46+
47+
Returns:
48+
The ``KCFGExtendResult`` produced by this custom step if this custom step can produce one, ``None`` otherwise.
49+
"""
4150

4251
@abstractmethod
4352
def is_mergeable(self, c1: CTerm, c2: CTerm) -> bool: ...
@@ -61,7 +70,7 @@ def same_loop(self, c1: CTerm, c2: CTerm) -> bool:
6170
def can_make_custom_step(self, c: CTerm) -> bool:
6271
return False
6372

64-
def custom_step(self, c: CTerm, cs: CTermSymbolic) -> KCFGExtendResult | None:
73+
def custom_step(self, c: CTerm, cs: CTermSymbolic, node_id: int) -> KCFGExtendResult | None:
6574
return None
6675

6776
def is_mergeable(self, c1: CTerm, c2: CTerm) -> bool:

pyk/src/tests/integration/proof/test_custom_step.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def can_make_custom_step(self, c: CTerm) -> bool:
7070
and k_cell[0].label.name == 'c_CUSTOM-STEP-SYNTAX_Step'
7171
)
7272

73-
def custom_step(self, c: CTerm, cs: CTermSymbolic) -> KCFGExtendResult | None:
73+
def custom_step(self, c: CTerm, cs: CTermSymbolic, node_id: int) -> KCFGExtendResult | None:
7474
if self.can_make_custom_step(c):
7575
new_cterm = CTerm.from_kast(set_cell(c.kast, 'K_CELL', KSequence(KApply('d_CUSTOM-STEP-SYNTAX_Step'))))
7676
return Step(new_cterm, 1, (), ['CUSTOM-STEP.c.d'], cut=True)
@@ -153,7 +153,7 @@ def test_custom_step_exec(
153153

154154
# When
155155
kcfg_semantics = CustomStepSemanticsWithStep()
156-
actual = kcfg_semantics.custom_step(cterm, cterm_symbolic)
156+
actual = kcfg_semantics.custom_step(cterm, cterm_symbolic, node_id=0)
157157
# Then
158158
assert expected == actual
159159

pyk/src/tests/integration/proof/test_prove_rpc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def same_loop(self, c1: CTerm, c2: CTerm) -> bool:
7171
def can_make_custom_step(self, c: CTerm) -> bool:
7272
return False
7373

74-
def custom_step(self, c: CTerm, cs: CTermSymbolic) -> KCFGExtendResult | None:
74+
def custom_step(self, c: CTerm, cs: CTermSymbolic, node_id: int) -> KCFGExtendResult | None:
7575
return None
7676

7777

0 commit comments

Comments
 (0)