Skip to content

Commit 17bc658

Browse files
Move pyk.prelude into pyk.kast (#4803)
* Move `pyk.prelude` into `pyk.kast` * Eliminate circularity between `pyk.kast.outer`, `pyk.kast.manip` and `pyk.kast.prelude` --------- Co-authored-by: Everett Hildenbrandt <[email protected]>
1 parent fa1dbb0 commit 17bc658

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+128
-132
lines changed

pyk/src/pyk/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
split_config_and_constraints,
3030
)
3131
from .kast.outer import KFlatModule, read_kast_definition
32+
from .kast.prelude.k import GENERATED_TOP_CELL
33+
from .kast.prelude.ml import is_top, mlAnd, mlOr
3234
from .kast.pretty import PrettyPrinter
3335
from .kast.utils import parse_outer
3436
from .kcfg import KCFGExplore
@@ -40,8 +42,6 @@
4042
from .ktool.kprove import KProve
4143
from .ktool.krun import KRun
4244
from .ktool.prove_rpc import ProveRpc
43-
from .prelude.k import GENERATED_TOP_CELL
44-
from .prelude.ml import is_top, mlAnd, mlOr
4545
from .proof.reachability import APRFailureInfo, APRProof
4646
from .proof.show import APRProofNodePrinter, APRProofShow
4747
from .utils import check_file_path, ensure_dir_path, exit_with_process_error

pyk/src/pyk/cterm/cterm.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
split_config_and_constraints,
2222
split_config_from,
2323
)
24-
from ..prelude.k import GENERATED_TOP_CELL, K
25-
from ..prelude.kbool import andBool, orBool
26-
from ..prelude.ml import is_bottom, is_top, mlAnd, mlBottom, mlEquals, mlEqualsTrue, mlImplies, mlTop
24+
from ..kast.prelude.k import GENERATED_TOP_CELL, K
25+
from ..kast.prelude.kbool import andBool, orBool
26+
from ..kast.prelude.ml import is_bottom, is_top, mlAnd, mlBottom, mlEquals, mlEqualsTrue, mlImplies, mlTop
2727
from ..utils import not_none, unique
2828

2929
if TYPE_CHECKING:

pyk/src/pyk/cterm/symbolic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from ..cterm import CSubst, CTerm
99
from ..kast.inner import KApply, KLabel, KRewrite, KToken, KVariable, Subst
1010
from ..kast.manip import flatten_label, is_spurious_constraint, sort_ac_collections
11+
from ..kast.prelude.k import GENERATED_TOP_CELL, K_ITEM
12+
from ..kast.prelude.ml import mlAnd
1113
from ..kast.pretty import PrettyPrinter
1214
from ..konvert import kast_to_kore, kflatmodule_to_kore, kore_to_kast
1315
from ..kore.rpc import (
@@ -21,8 +23,6 @@
2123
UnsatResult,
2224
kore_server,
2325
)
24-
from ..prelude.k import GENERATED_TOP_CELL, K_ITEM
25-
from ..prelude.ml import mlAnd
2626
from ..utils import not_none
2727

2828
if TYPE_CHECKING:

pyk/src/pyk/kast/formatter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from typing import TYPE_CHECKING
44

5-
from ..prelude.k import K_ITEM
5+
from ..kast.prelude.k import K_ITEM
66
from ..utils import intersperse
77
from .att import Atts, Format, KAtt
88
from .inner import KApply, KToken, KVariable, bottom_up

pyk/src/pyk/kast/inner.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -738,8 +738,6 @@ def unapply(self, term: KInner) -> KInner:
738738
@staticmethod
739739
def from_pred(pred: KInner) -> Subst:
740740
"""Given a generic matching logic predicate, attempt to extract a `Subst` from it."""
741-
from .manip import flatten_label
742-
743741
subst: dict[str, KInner] = {}
744742
for conjunct in flatten_label('#And', pred):
745743
match conjunct:

pyk/src/pyk/kast/manip.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
from collections import Counter
55
from typing import TYPE_CHECKING
66

7-
from ..prelude.k import DOTS, GENERATED_TOP_CELL
8-
from ..prelude.kbool import FALSE, TRUE, andBool, impliesBool, notBool, orBool
9-
from ..prelude.ml import is_top, mlAnd, mlBottom, mlEquals, mlEqualsTrue, mlImplies, mlOr, mlTop
7+
from ..kast.prelude.k import DOTS, GENERATED_TOP_CELL
8+
from ..kast.prelude.kbool import FALSE, TRUE, andBool, impliesBool, notBool, orBool
9+
from ..kast.prelude.ml import is_top, mlAnd, mlBottom, mlEquals, mlEqualsTrue, mlImplies, mlOr, mlTop
1010
from ..utils import find_common_items, hash_str, unique
1111
from .att import EMPTY_ATT, Atts, KAtt, WithKAtt
1212
from .inner import (

pyk/src/pyk/kast/outer.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
from itertools import pairwise, product
1414
from typing import TYPE_CHECKING, final, overload
1515

16-
from ..prelude.kbool import TRUE
17-
from ..prelude.ml import ML_QUANTIFIERS
1816
from ..utils import FrozenDict, POSet, filter_none, not_none, single, unique
1917
from .att import EMPTY_ATT, Atts, Format, KAst, KAtt, WithKAtt
2018
from .inner import (
@@ -45,6 +43,10 @@
4543
_LOGGER: Final = logging.getLogger(__name__)
4644

4745

46+
_BOOL: Final = KSort('Bool')
47+
_TRUE: Final = KToken('true', _BOOL)
48+
49+
4850
class KOuter(KAst):
4951
"""Represents K definitions in KAST format.
5052
@@ -628,7 +630,7 @@ class KRule(KRuleLike):
628630
ensures: KInner
629631
att: KAtt
630632

631-
def __init__(self, body: KInner, requires: KInner = TRUE, ensures: KInner = TRUE, att: KAtt = EMPTY_ATT):
633+
def __init__(self, body: KInner, requires: KInner = _TRUE, ensures: KInner = _TRUE, att: KAtt = EMPTY_ATT):
632634
object.__setattr__(self, 'body', body)
633635
object.__setattr__(self, 'requires', requires)
634636
object.__setattr__(self, 'ensures', ensures)
@@ -638,8 +640,8 @@ def __init__(self, body: KInner, requires: KInner = TRUE, ensures: KInner = TRUE
638640
def _from_dict(cls: type[KRule], d: Mapping[str, Any]) -> KRule:
639641
return KRule(
640642
body=KInner.from_dict(d['body']),
641-
requires=KInner.from_dict(d['requires']) if d.get('requires') else TRUE,
642-
ensures=KInner.from_dict(d['ensures']) if d.get('ensures') else TRUE,
643+
requires=KInner.from_dict(d['requires']) if d.get('requires') else _TRUE,
644+
ensures=KInner.from_dict(d['ensures']) if d.get('ensures') else _TRUE,
643645
att=KAtt.from_dict(d['att']) if d.get('att') else EMPTY_ATT,
644646
)
645647

@@ -684,7 +686,7 @@ class KClaim(KRuleLike):
684686
ensures: KInner
685687
att: KAtt
686688

687-
def __init__(self, body: KInner, requires: KInner = TRUE, ensures: KInner = TRUE, att: KAtt = EMPTY_ATT):
689+
def __init__(self, body: KInner, requires: KInner = _TRUE, ensures: KInner = _TRUE, att: KAtt = EMPTY_ATT):
688690
object.__setattr__(self, 'body', body)
689691
object.__setattr__(self, 'requires', requires)
690692
object.__setattr__(self, 'ensures', ensures)
@@ -694,8 +696,8 @@ def __init__(self, body: KInner, requires: KInner = TRUE, ensures: KInner = TRUE
694696
def _from_dict(cls: type[KClaim], d: Mapping[str, Any]) -> KClaim:
695697
return KClaim(
696698
body=KInner.from_dict(d['body']),
697-
requires=KInner.from_dict(d['requires']) if d.get('requires') else TRUE,
698-
ensures=KInner.from_dict(d['ensures']) if d.get('ensures') else TRUE,
699+
requires=KInner.from_dict(d['requires']) if d.get('requires') else _TRUE,
700+
ensures=KInner.from_dict(d['ensures']) if d.get('ensures') else _TRUE,
699701
att=KAtt.from_dict(d['att']) if d.get('att') else EMPTY_ATT,
700702
)
701703

@@ -753,7 +755,7 @@ class KContext(KSentence):
753755
requires: KInner
754756
att: KAtt
755757

756-
def __init__(self, body: KInner, requires: KInner = TRUE, att: KAtt = EMPTY_ATT):
758+
def __init__(self, body: KInner, requires: KInner = _TRUE, att: KAtt = EMPTY_ATT):
757759
object.__setattr__(self, 'body', body)
758760
object.__setattr__(self, 'requires', requires)
759761
object.__setattr__(self, 'att', att)
@@ -762,7 +764,7 @@ def __init__(self, body: KInner, requires: KInner = TRUE, att: KAtt = EMPTY_ATT)
762764
def _from_dict(cls: type[KContext], d: Mapping[str, Any]) -> KContext:
763765
return KContext(
764766
body=KInner.from_dict(d['body']),
765-
requires=KInner.from_dict(d['requires']) if d.get('requires') else TRUE,
767+
requires=KInner.from_dict(d['requires']) if d.get('requires') else _TRUE,
766768
att=KAtt.from_dict(d['att']) if d.get('att') else EMPTY_ATT,
767769
)
768770

@@ -1400,6 +1402,8 @@ def _add_ksequence_under_k_productions(_kast: KInner) -> KInner:
14001402

14011403
def sort_vars(self, kast: KInner, sort: KSort | None = None) -> KInner:
14021404
"""Return the original term with all the variables having the sorts added or specialized, failing if recieving conflicting sorts for a given variable."""
1405+
ml_quantifiers = {'#Exists', '#Forall'}
1406+
14031407
if type(kast) is KVariable and kast.sort is None and sort is not None:
14041408
return kast.let(sort=sort)
14051409

@@ -1422,7 +1426,7 @@ def merge_variables(
14221426
if isinstance(term, KVariable):
14231427
result[term.name].append(term)
14241428
elif isinstance(term, KApply):
1425-
if term.label.name in ML_QUANTIFIERS:
1429+
if term.label.name in ml_quantifiers:
14261430
var = get_quantifier_variable(term)
14271431
result[var.name].append(var)
14281432
return result
@@ -1444,7 +1448,7 @@ def transform(
14441448
occurrences = merge_variables(term, child_variables)
14451449

14461450
if isinstance(term, KApply):
1447-
if term.label.name in ML_QUANTIFIERS:
1451+
if term.label.name in ml_quantifiers:
14481452
var = get_quantifier_variable(term)
14491453
subst: dict[str, KVariable] = {}
14501454
add_var_to_subst(var.name, occurrences[var.name], subst)

pyk/src/pyk/prelude/bytes.py renamed to pyk/src/pyk/kast/prelude/bytes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Final
22

3-
from ..dequote import bytes_decode, bytes_encode, dequote_bytes, enquote_bytes
4-
from ..kast.inner import KSort, KToken
3+
from ...dequote import bytes_decode, bytes_encode, dequote_bytes, enquote_bytes
4+
from ..inner import KSort, KToken
55

66
BYTES: Final = KSort('Bytes')
77

pyk/src/pyk/prelude/collections.py renamed to pyk/src/pyk/kast/prelude/collections.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
from typing import TYPE_CHECKING
44

5-
from ..kast.inner import KApply, KLabel, KSort, build_assoc
5+
from ..inner import KApply, KLabel, KSort, build_assoc
66

77
if TYPE_CHECKING:
88
from collections.abc import Iterable
99
from typing import Final
1010

11-
from ..kast import KInner
11+
from .. import KInner
1212

1313
SET: Final = KSort('Set')
1414
LIST: Final = KSort('List')

pyk/src/pyk/prelude/k.py renamed to pyk/src/pyk/kast/prelude/k.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
from typing import TYPE_CHECKING
44

5-
from ..kast.inner import KApply, KLabel, KSort, KToken
5+
from ..inner import KApply, KLabel, KSort, KToken
66

77
if TYPE_CHECKING:
88
from typing import Final
99

10-
from ..kast import KInner
10+
from .. import KInner
1111

1212

1313
K: Final = KSort('K')

pyk/src/pyk/prelude/kbool.py renamed to pyk/src/pyk/kast/prelude/kbool.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22

33
from typing import TYPE_CHECKING
44

5-
from ..kast.inner import KApply, KLabel, KSort, KToken, build_assoc
6-
from ..utils import unique
5+
from ...utils import unique
6+
from ..inner import KApply, KLabel, KToken, build_assoc
7+
from ..outer import _BOOL, _TRUE
78

89
if TYPE_CHECKING:
910
from collections.abc import Iterable
1011
from typing import Final
1112

12-
from ..kast import KInner
13+
from .. import KInner
1314

14-
BOOL: Final = KSort('Bool')
15-
TRUE: Final = KToken('true', BOOL)
15+
16+
BOOL: Final = _BOOL
17+
TRUE: Final = _TRUE
1618
FALSE: Final = KToken('false', BOOL)
1719

1820

pyk/src/pyk/prelude/kint.py renamed to pyk/src/pyk/kast/prelude/kint.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
from typing import TYPE_CHECKING
44

5-
from ..kast.inner import KApply, KSort, KToken
5+
from ..inner import KApply, KSort, KToken
66

77
if TYPE_CHECKING:
88
from typing import Final
99

10-
from ..kast import KInner
10+
from .. import KInner
1111

1212
INT: Final = KSort('Int')
1313

pyk/src/pyk/prelude/ml.py renamed to pyk/src/pyk/kast/prelude/ml.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,16 @@
22

33
from typing import TYPE_CHECKING
44

5-
from pyk.utils import single
6-
7-
from ..kast.inner import KApply, KLabel, build_assoc, flatten_label
5+
from ...utils import single
6+
from ..inner import KApply, KLabel, build_assoc, flatten_label
87
from .k import GENERATED_TOP_CELL, K_ITEM, K
98
from .kbool import BOOL, FALSE, TRUE
109

1110
if TYPE_CHECKING:
1211
from collections.abc import Iterable
13-
from typing import Final
14-
15-
from ..kast import KInner
16-
from ..kast.inner import KSort, KVariable
17-
1812

19-
ML_QUANTIFIERS: Final = {
20-
'#Exists',
21-
'#Forall',
22-
}
13+
from .. import KInner
14+
from ..inner import KSort, KVariable
2315

2416

2517
def _is_top(term: KInner) -> bool:

pyk/src/pyk/prelude/string.py renamed to pyk/src/pyk/kast/prelude/string.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Final
22

3-
from ..dequote import dequote_string, enquote_string
4-
from ..kast.inner import KSort, KToken
3+
from ...dequote import dequote_string, enquote_string
4+
from ..inner import KSort, KToken
55

66
STRING: Final = KSort('String')
77

pyk/src/pyk/prelude/utils.py renamed to pyk/src/pyk/kast/prelude/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from .string import stringToken
99

1010
if TYPE_CHECKING:
11-
from ..kast.inner import KToken
11+
from ..inner import KToken
1212

1313

1414
def token(x: bool | int | str | bytes) -> KToken:

pyk/src/pyk/kast/pretty.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from functools import cached_property
66
from typing import TYPE_CHECKING
77

8-
from ..prelude.kbool import TRUE
8+
from ..kast.prelude.kbool import TRUE
99
from .att import Atts, KAtt
1010
from .inner import KApply, KAs, KInner, KLabel, KRewrite, KSequence, KSort, KToken, KVariable
1111
from .manip import flatten_label, sort_ac_collections, undo_aliases

pyk/src/pyk/kcfg/explore.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
push_down_rewrites,
1414
replace_rewrites_with_implies,
1515
)
16+
from ..kast.prelude.ml import is_top, mlAnd
1617
from ..kast.pretty import PrettyPrinter
1718
from ..kore.rpc import LogRewrite, RewriteSuccess
18-
from ..prelude.ml import is_top, mlAnd
1919
from ..utils import not_none, shorten_hashes, single, unique
2020
from .kcfg import KCFG, Abstract, Branch, NDBranch, Step, Stuck, Vacuous
2121
from .semantics import DefaultSemantics

pyk/src/pyk/kcfg/kcfg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
sort_ac_collections,
2222
)
2323
from ..kast.outer import KFlatModule
24-
from ..prelude.kbool import andBool
24+
from ..kast.prelude.kbool import andBool
2525
from ..utils import ensure_dir_path, not_none
2626

2727
if TYPE_CHECKING:

pyk/src/pyk/kcfg/show.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
sort_ac_collections,
1818
)
1919
from ..kast.outer import KRule
20-
from ..prelude.k import DOTS
21-
from ..prelude.ml import mlAnd
20+
from ..kast.prelude.k import DOTS
21+
from ..kast.prelude.ml import mlAnd
2222
from ..utils import add_indent, ensure_dir_path
2323
from .kcfg import KCFG
2424

pyk/src/pyk/kcfg/tui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from ..cterm import CTerm
1414
from ..kast.inner import KApply, KRewrite
1515
from ..kast.manip import flatten_label, minimize_term, push_down_rewrites
16-
from ..prelude.kbool import TRUE
16+
from ..kast.prelude.kbool import TRUE
1717
from ..utils import ROOT, shorten_hashes, single
1818
from .kcfg import KCFG
1919
from .show import KCFGShow

pyk/src/pyk/konvert/_kast_to_kore.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
from ..kast.inner import KApply, KLabel, KRewrite, KSequence, KSort, KToken, KVariable, top_down
99
from ..kast.manip import bool_to_ml_pred, extract_lhs, extract_rhs, flatten_label, ml_pred_to_bool, var_occurrences
1010
from ..kast.outer import KRule
11+
from ..kast.prelude.bytes import BYTES, pretty_bytes_str
12+
from ..kast.prelude.k import K_ITEM, K, inj
13+
from ..kast.prelude.kbool import BOOL, TRUE, andBool
14+
from ..kast.prelude.ml import mlAnd
15+
from ..kast.prelude.string import STRING, pretty_string
1116
from ..kore.prelude import BOOL as KORE_BOOL
1217
from ..kore.prelude import SORT_K
1318
from ..kore.prelude import TRUE as KORE_TRUE
@@ -29,11 +34,6 @@
2934
String,
3035
Top,
3136
)
32-
from ..prelude.bytes import BYTES, pretty_bytes_str
33-
from ..prelude.k import K_ITEM, K, inj
34-
from ..prelude.kbool import BOOL, TRUE, andBool
35-
from ..prelude.ml import mlAnd
36-
from ..prelude.string import STRING, pretty_string
3737
from ._utils import munge
3838

3939
if TYPE_CHECKING:

0 commit comments

Comments
 (0)