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

Commit e151952

Browse files
Add module_name method for method name processing (#865)
Addresses runtimeverification/kontrol#337. This PR adds property `module_name` to `APRProof`, which transforms the `proof.id` into a valid module name by escaping illegal characters. It also adds substitution of `[` and `]` with `bkp`. ~This PR adds static method `make_module_name` to `KFlatModule`, which transforms the `proof.id` into a valid module name by escaping illegal characters. It also adds substitution of `[` and `]` with `-bkp-`. It also adds a unit test for `make_module_name`.~ --------- Co-authored-by: devops <[email protected]>
1 parent 03ea742 commit e151952

File tree

5 files changed

+35
-5
lines changed

5 files changed

+35
-5
lines changed

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
project = 'pyk'
1010
author = 'Runtime Verification, Inc'
1111
copyright = '2024, Runtime Verification, Inc'
12-
version = '0.1.617'
13-
release = '0.1.617'
12+
version = '0.1.618'
13+
release = '0.1.618'
1414

1515
# -- General configuration ---------------------------------------------------
1616
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

package/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.617
1+
0.1.618

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.617"
7+
version = "0.1.618"
88
description = ""
99
authors = [
1010
"Runtime Verification, Inc. <[email protected]>",

src/pyk/proof/reachability.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ def __init__(
9292
assert type(subproof) is RefutationProof
9393
self.node_refutations[node_id] = subproof
9494

95+
@property
96+
def module_name(self) -> str:
97+
return self._make_module_name(self.id)
98+
9599
@property
96100
def pending(self) -> list[KCFG.Node]:
97101
return [node for node in self.explorable if self.is_pending(node.id)]
@@ -130,6 +134,12 @@ def prune(self, node_id: NodeIdLike, keep_nodes: Iterable[NodeIdLike] = ()) -> l
130134
pruned_nodes = super().prune(node_id, keep_nodes=list(keep_nodes) + [self.init, self.target])
131135
return pruned_nodes
132136

137+
@staticmethod
138+
def _make_module_name(proof_id: str) -> str:
139+
return 'M-' + re.sub(
140+
r'[\[\]]|[_%().:,]+', lambda match: 'bkt' if match.group(0) in ['[', ']'] else '-', proof_id.upper()
141+
)
142+
133143
@staticmethod
134144
def read_proof(id: str, proof_dir: Path) -> APRProof:
135145
proof_path = proof_dir / f'{hash_str(id)}.json'
@@ -731,7 +741,7 @@ def _inject_module(module_name: str, import_name: str, sentences: list[KRuleLike
731741
dependencies_as_rules.append(apr_subproof.as_rule(priority=20))
732742
circularity_rule = proof.as_rule(priority=20)
733743

734-
module_name = 'M-' + re.sub(r'[_%().:,]+', '-', self.proof.id.upper())
744+
module_name = self.proof.module_name
735745
self.dependencies_module_name = module_name + '-DEPENDS-MODULE'
736746
self.circularities_module_name = module_name + '-CIRCULARITIES-MODULE'
737747
_inject_module(self.dependencies_module_name, self.main_module_name, dependencies_as_rules)

src/tests/unit/test_proof.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
if TYPE_CHECKING:
1717
from pathlib import Path
18+
from typing import Final
1819

1920
from pytest import TempPathFactory
2021

@@ -219,6 +220,25 @@ def test_apr_proof_from_dict_heterogeneous_subproofs(proof_dir: Path) -> None:
219220
assert proof.dict == proof_from_disk.dict
220221

221222

223+
MODULE_NAME_TEST_DATA: Final = (
224+
('sq-bracket', 'TEST-KONTROL-TEST-UINT256-BYTES[]-0', 'M-TEST-KONTROL-TEST-UINT256-BYTESbktbkt-0'),
225+
('underscore', 'TEST_KONTROL_%)_UINT256-1', 'M-TEST-KONTROL-UINT256-1'),
226+
)
227+
228+
229+
@pytest.mark.parametrize(
230+
'test_id,proof_id,expected',
231+
MODULE_NAME_TEST_DATA,
232+
ids=[test_id for test_id, *_ in MODULE_NAME_TEST_DATA],
233+
)
234+
def test_proof_module_name(test_id: str, proof_id: str, expected: str) -> None:
235+
# Given
236+
output = APRProof._make_module_name(proof_id)
237+
238+
# Then
239+
assert output == expected
240+
241+
222242
#### APRBMCProof
223243

224244

0 commit comments

Comments
 (0)