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

Commit 7d55264

Browse files
committed
Merge branch 'noah/node-attributes' of https://github.com/runtimeverification/pyk into noah/node-attributes
2 parents 13b0b05 + b7c4c30 commit 7d55264

File tree

7 files changed

+33
-46
lines changed

7 files changed

+33
-46
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.722'
13-
release = '0.1.722'
12+
version = '0.1.724'
13+
release = '0.1.724'
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.722
1+
0.1.724

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

src/pyk/kast/outer.py

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from ..prelude.kbool import TRUE
1616
from ..prelude.ml import ML_QUANTIFIERS
17-
from ..utils import POSet, filter_none, single, unique
17+
from ..utils import FrozenDict, POSet, filter_none, single, unique
1818
from .att import EMPTY_ATT, Atts, Format, KAst, KAtt, WithKAtt
1919
from .inner import (
2020
KApply,
@@ -37,8 +37,6 @@
3737
from os import PathLike
3838
from typing import Any, Final, TypeVar
3939

40-
from ..utils import FrozenDict
41-
4240
RL = TypeVar('RL', bound='KRuleLike')
4341

4442
_LOGGER: Final = logging.getLogger(__name__)
@@ -1001,7 +999,6 @@ class KDefinition(KOuter, WithKAtt, Iterable[KFlatModule]):
1001999

10021000
main_module: InitVar[KFlatModule]
10031001

1004-
_production_for_klabel: dict[KLabel, KProduction]
10051002
_init_config: dict[KSort, KInner]
10061003
_empty_config: dict[KSort, KInner]
10071004

@@ -1027,7 +1024,6 @@ def __init__(
10271024
object.__setattr__(self, 'requires', tuple(requires))
10281025
object.__setattr__(self, 'att', att)
10291026
object.__setattr__(self, 'main_module', main_module)
1030-
object.__setattr__(self, '_production_for_klabel', {})
10311027
object.__setattr__(self, '_init_config', {})
10321028
object.__setattr__(self, '_empty_config', {})
10331029

@@ -1162,28 +1158,6 @@ def sentence_by_unique_id(self) -> dict[str, KSentence]:
11621158
unique_id_map[unique_id] = sent
11631159
return unique_id_map
11641160

1165-
def production_for_klabel(self, klabel: KLabel) -> KProduction:
1166-
"""Returns the original production for a given `KLabel` (failing if 0 or >1 are returned)."""
1167-
if klabel not in self._production_for_klabel:
1168-
prods = [prod for prod in self.productions if prod.klabel and prod.klabel.name == klabel.name]
1169-
_prods = [prod for prod in prods if Atts.UNPARSE_AVOID not in prod.att]
1170-
if len(_prods) < len(prods):
1171-
_LOGGER.warning(
1172-
f'Discarding {len(prods) - len(_prods)} productions with `unparseAvoid` attribute for label: {klabel}'
1173-
)
1174-
prods = _prods
1175-
# Automatically defined symbols like isInt may get multiple
1176-
# definitions in different modules.
1177-
_prods = list({prod.let_att(prod.att.drop_source()) for prod in prods})
1178-
if len(_prods) < len(prods):
1179-
_LOGGER.warning(f'Discarding {len(prods) - len(_prods)} equivalent productions')
1180-
prods = _prods
1181-
try:
1182-
self._production_for_klabel[klabel] = single(prods)
1183-
except ValueError as err:
1184-
raise ValueError(f'Expected a single production for label {klabel}, not: {prods}') from err
1185-
return self._production_for_klabel[klabel]
1186-
11871161
def production_for_cell_sort(self, sort: KSort) -> KProduction:
11881162
"""Returns the production for a given cell-declaration syntax from the cell's declared sort."""
11891163
# Typical cell production has 3 productions:
@@ -1208,11 +1182,11 @@ def module(self, name: str) -> KFlatModule:
12081182

12091183
def return_sort(self, label: KLabel) -> KSort:
12101184
"""Returns the return sort of a given `KLabel` by looking up the production."""
1211-
return self.production_for_klabel(label).sort
1185+
return self.symbols[label.name].sort
12121186

12131187
def argument_sorts(self, label: KLabel) -> list[KSort]:
12141188
"""Returns the argument sorts of a given `KLabel` by looking up the production."""
1215-
return self.production_for_klabel(label).argument_sorts
1189+
return self.symbols[label.name].argument_sorts
12161190

12171191
@cached_property
12181192
def subsort_table(self) -> FrozenDict[KSort, frozenset[KSort]]:
@@ -1224,6 +1198,22 @@ def subsorts(self, sort: KSort) -> frozenset[KSort]:
12241198
"""Return all subsorts of a given `KSort` by inspecting the definition."""
12251199
return self.subsort_table.get(sort, frozenset())
12261200

1201+
@cached_property
1202+
def symbols(self) -> FrozenDict[str, KProduction]:
1203+
symbols: dict[str, KProduction] = {}
1204+
for prod in self.productions:
1205+
if not prod.klabel:
1206+
continue
1207+
symbol = prod.klabel.name
1208+
if symbol in symbols: # Check if duplicate
1209+
other = symbols[symbol]
1210+
if prod.let(att=prod.att.drop_source()) != other.let(att=prod.att.drop_source()):
1211+
prods = [other, prod]
1212+
raise AssertionError(f'Found multiple productions for {symbol}: {prods}')
1213+
continue
1214+
symbols[symbol] = prod
1215+
return FrozenDict(symbols)
1216+
12271217
def sort(self, kast: KInner) -> KSort | None:
12281218
"""Computes the sort of a given term using best-effort simple sorting algorithm, returns `None` on algorithm failure."""
12291219
match kast:
@@ -1238,7 +1228,7 @@ def sort(self, kast: KInner) -> KSort | None:
12381228
case KSequence(_):
12391229
return KSort('K')
12401230
case KApply(label, _):
1241-
prod = self.production_for_klabel(label)
1231+
prod = self.symbols[label.name]
12421232
if prod.sort not in prod.params:
12431233
return prod.sort
12441234
elif len(prod.params) == len(label.params):
@@ -1293,7 +1283,7 @@ def _add_ksequence_under_k_productions(_kast: KInner) -> KInner:
12931283
if type(_kast) is not KApply:
12941284
return _kast
12951285

1296-
prod = self.production_for_klabel(_kast.label)
1286+
prod = self.symbols[_kast.label.name]
12971287
return KApply(
12981288
_kast.label,
12991289
[
@@ -1358,7 +1348,7 @@ def transform(
13581348
del occurrences[var.name]
13591349
return (Subst(subst)(term), occurrences)
13601350
else:
1361-
prod = self.production_for_klabel(term.label)
1351+
prod = self.symbols[term.label.name]
13621352
if len(prod.params) == 0:
13631353
for t, a in zip(prod.argument_sorts, term.args, strict=True):
13641354
if type(a) is KVariable:
@@ -1386,7 +1376,7 @@ def add_sort_params(self, kast: KInner) -> KInner:
13861376

13871377
def _add_sort_params(_k: KInner) -> KInner:
13881378
if type(_k) is KApply:
1389-
prod = self.production_for_klabel(_k.label)
1379+
prod = self.symbols[_k.label.name]
13901380
if len(_k.label.params) == 0 and len(prod.params) > 0:
13911381
sort_dict: dict[KSort, KSort] = {}
13921382
for psort, asort in zip(prod.argument_sorts, map(self.sort, _k.args), strict=True):
@@ -1467,7 +1457,7 @@ def _kdefinition_empty_config(_sort: KSort) -> KApply:
14671457
cell_prod = self.production_for_cell_sort(_sort)
14681458
cell_klabel = cell_prod.klabel
14691459
assert cell_klabel is not None
1470-
production = self.production_for_klabel(cell_klabel)
1460+
production = self.symbols[cell_klabel.name]
14711461
args: list[KInner] = []
14721462
num_nonterminals = 0
14731463
num_freshvars = 0
@@ -1490,8 +1480,8 @@ def instantiate_cell_vars(self, term: KInner) -> KInner:
14901480

14911481
def _cell_vars_to_labels(_kast: KInner) -> KInner:
14921482
if type(_kast) is KApply and _kast.is_cell:
1493-
production = self.production_for_klabel(_kast.label)
1494-
production_arity = [prod_item.sort for prod_item in production.items if type(prod_item) is KNonTerminal]
1483+
production = self.symbols[_kast.label.name]
1484+
production_arity = [item.sort for item in production.non_terminals]
14951485
new_args = []
14961486
for sort, arg in zip(production_arity, _kast.args, strict=True):
14971487
if sort.name.endswith('Cell') and type(arg) is KVariable:

src/pyk/ktool/kprove.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,7 @@ def prove_claim_rpc(
312312
proof: Proof
313313
prover: Prover
314314
lhs_top = extract_lhs(claim.body)
315-
if (
316-
type(lhs_top) is KApply
317-
and self.definition.production_for_klabel(lhs_top.label) in self.definition.functions
318-
):
315+
if type(lhs_top) is KApply and self.definition.symbols[lhs_top.label.name] in self.definition.functions:
319316
proof = EqualityProof.from_claim(claim, self.definition)
320317
prover = ImpliesProver(proof, kcfg_explore)
321318
else:

src/pyk/testing/_kompiler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class KoreClientTest(KompiledTest):
167167
KOMPILE_BACKEND: ClassVar = 'haskell'
168168
LLVM_ARGS: ClassVar[dict[str, Any]] = {}
169169

170-
CLIENT_TIMEOUT: ClassVar = 2000
170+
CLIENT_TIMEOUT: ClassVar = 5000
171171

172172
@pytest.fixture(scope='class', params=['legacy', 'booster'])
173173
def server_type(self, request: FixtureRequest, use_server: UseServer) -> ServerType:

src/tests/profiling/test-data/kast-to-kore/compiled.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)