1
- from logging import Logger
2
- from typing import Collection , Iterable , List , Optional , Tuple
1
+ from typing import Collection , Iterable , List
3
2
4
3
from pyk .cterm import CTerm
5
4
from pyk .kast .inner import KApply , KInner , KRewrite , KVariable
6
5
from pyk .kast .manip import (
7
6
abstract_term_safely ,
8
- bool_to_ml_pred ,
9
7
bottom_up ,
10
- flatten_label ,
11
- free_vars ,
12
8
is_anon_var ,
13
- ml_pred_to_bool ,
14
- remove_generated_cells ,
15
9
split_config_and_constraints ,
16
10
split_config_from ,
17
11
substitute ,
18
- undo_aliases ,
19
12
)
20
- from pyk .kast .outer import KClaim , KDefinition , KFlatModule , KImport , KRule
13
+ from pyk .kast .outer import KDefinition , KFlatModule , KImport
21
14
from pyk .kcfg import KCFG
22
- from pyk .ktool import KPrint , KProve
23
- from pyk .prelude .kbool import FALSE
24
- from pyk .prelude .ml import mlAnd
15
+ from pyk .ktool import KPrint
25
16
26
17
27
18
def KDefinition__expand_macros (defn : KDefinition , term : KInner ) -> KInner : # noqa: N802
@@ -82,28 +73,6 @@ def KCFG__replace_node(cfg: KCFG, node_id: str, new_cterm: CTerm) -> KCFG: # no
82
73
return cfg
83
74
84
75
85
- def KProve_prove_claim ( # noqa: N802
86
- kprove : KProve ,
87
- claim : KClaim ,
88
- claim_id : str ,
89
- logger : Logger ,
90
- depth : Optional [int ] = None ,
91
- lemmas : Iterable [KRule ] = (),
92
- ) -> Tuple [bool , KInner ]:
93
- logger .info (f'Proving claim: { claim_id } ' )
94
- prove_args = []
95
- if depth is not None :
96
- prove_args += ['--depth' , str (depth )]
97
- result = kprove .prove_claim (claim , claim_id , args = prove_args , lemmas = lemmas )
98
- failed = False
99
- if type (result ) is KApply and result .label .name == '#Top' :
100
- logger .info (f'Proved claim: { claim_id } ' )
101
- else :
102
- logger .error (f'Failed to prove claim: { claim_id } ' )
103
- failed = True
104
- return failed , result
105
-
106
-
107
76
def KPrint_make_unparsing (_self : KPrint , extra_modules : Iterable [KFlatModule ] = ()) -> KPrint : # noqa: N802
108
77
modules = _self .definition .modules + tuple (extra_modules )
109
78
main_module = KFlatModule ('UNPARSING' , [], [KImport (_m .name ) for _m in modules ])
@@ -125,35 +94,3 @@ def abstract_cell_vars(cterm: KInner, keep_vars: Collection[KVariable] = ()) ->
125
94
if type (subst [s ]) is KVariable and not is_anon_var (subst [s ]) and subst [s ] not in keep_vars :
126
95
subst [s ] = abstract_term_safely (KVariable ('_' ), base_name = s )
127
96
return substitute (config , subst )
128
-
129
-
130
- def sanitize_config (defn : KDefinition , init_term : KInner ) -> KInner :
131
- def _var_name (vname : str ) -> str :
132
- new_vname = vname
133
- while new_vname .startswith ('_' ) or new_vname .startswith ('?' ):
134
- new_vname = new_vname [1 :]
135
- return new_vname
136
-
137
- free_vars_subst = {vname : KVariable (_var_name (vname )) for vname in free_vars (init_term )}
138
-
139
- # TODO: This is somewhat hacky. We shouldn't have to touch the config this much.
140
- # Likely, the frontend should just be giving us initial states with these already in place.
141
- def _remove_cell_map_definedness (_kast : KInner ) -> KInner :
142
- if type (_kast ) is KApply :
143
- if _kast .label .name .endswith ('CellMap:in_keys' ):
144
- return FALSE
145
- elif _kast .label .name .endswith ('CellMapItem' ):
146
- return _kast .args [1 ]
147
- return _kast
148
-
149
- new_term = substitute (init_term , free_vars_subst )
150
- new_term = remove_generated_cells (new_term )
151
- new_term = bottom_up (_remove_cell_map_definedness , new_term )
152
-
153
- if not (type (new_term ) is KApply and new_term .label .name in ['#Top' , '#Bottom' ]):
154
- config , constraint = split_config_and_constraints (new_term )
155
- constraints = [bool_to_ml_pred (ml_pred_to_bool (c , unsafe = True )) for c in flatten_label ('#And' , constraint )]
156
- new_term = mlAnd ([config ] + constraints )
157
- new_term = undo_aliases (defn , new_term )
158
-
159
- return new_term
0 commit comments