Skip to content

Commit 1cccdc0

Browse files
authored
Remove unused code (#752)
Fixes #748
1 parent 51a716a commit 1cccdc0

File tree

6 files changed

+4
-383
lines changed

6 files changed

+4
-383
lines changed

kmir/src/kmir/__main__.py

Lines changed: 1 addition & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@
99

1010
from pyk.cli.args import KCLIArgs
1111
from pyk.cterm.show import CTermShow
12-
from pyk.kast.outer import KFlatModule, KImport
1312
from pyk.kast.pretty import PrettyPrinter
14-
from pyk.proof.reachability import APRProof, APRProver
13+
from pyk.proof.reachability import APRProof
1514
from pyk.proof.show import APRProofShow
1615
from pyk.proof.tui import APRProofViewer
1716

@@ -20,17 +19,14 @@
2019
from .kmir import KMIR, KMIRAPRNodePrinter
2120
from .linker import link
2221
from .options import (
23-
GenSpecOpts,
2422
InfoOpts,
2523
LinkOpts,
26-
ProveRawOpts,
2724
ProveRSOpts,
2825
PruneOpts,
2926
RunOpts,
3027
ShowOpts,
3128
ViewOpts,
3229
)
33-
from .parse.parser import parse_json
3430
from .smir import SMIRInfo, Ty
3531
from .utils import render_leaf_k_cells, render_rules, render_statistics
3632

@@ -71,55 +67,6 @@ def _kmir_prove_rs(opts: ProveRSOpts) -> None:
7167
sys.exit(1)
7268

7369

74-
def _kmir_gen_spec(opts: GenSpecOpts) -> None:
75-
kmir = KMIR(HASKELL_DEF_DIR, LLVM_LIB_DIR)
76-
77-
parse_result = parse_json(kmir.definition, opts.input_file, 'Pgm')
78-
if parse_result is None:
79-
print('Parse error!', file=sys.stderr)
80-
sys.exit(1)
81-
82-
smir_info = SMIRInfo.from_file(opts.input_file).reduce_to(opts.start_symbol)
83-
apr_proof = kmir.apr_proof_from_smir(
84-
str(opts.input_file.stem.replace('_', '-')),
85-
smir_info,
86-
start_symbol=opts.start_symbol,
87-
sort='KmirCell',
88-
)
89-
claim = apr_proof.as_claim()
90-
91-
output_file = opts.output_file
92-
if output_file is None:
93-
suffixes = ''.join(opts.input_file.suffixes)
94-
base = opts.input_file.name.removesuffix(suffixes).replace('_', '-')
95-
output_file = Path(f'{base}-spec.k')
96-
97-
module_name = output_file.stem.upper().replace('_', '-')
98-
spec_module = KFlatModule(module_name, (claim,), (KImport('KMIR'),))
99-
100-
output_file.write_text(kmir.pretty_print(spec_module))
101-
102-
103-
def _kmir_prove_raw(opts: ProveRawOpts) -> None:
104-
kmir = KMIR(HASKELL_DEF_DIR, LLVM_LIB_DIR, bug_report=opts.bug_report)
105-
claim_index = kmir.get_claim_index(opts.spec_file)
106-
labels = claim_index.labels(include=opts.include_labels, exclude=opts.exclude_labels)
107-
for label in labels:
108-
print(f'Proving {label}')
109-
claim = claim_index[label]
110-
if not opts.reload and opts.proof_dir is not None and APRProof.proof_data_exists(label, opts.proof_dir):
111-
_LOGGER.info(f'Reading proof from disc: {opts.proof_dir}, {label}')
112-
proof = APRProof.read_proof_data(opts.proof_dir, label)
113-
else:
114-
_LOGGER.info(f'Constructing initial proof: {label}')
115-
proof = APRProof.from_claim(kmir.definition, claim, {}, proof_dir=opts.proof_dir)
116-
with kmir.kcfg_explore(label) as kcfg_explore:
117-
prover = APRProver(kcfg_explore, execute_depth=opts.max_depth)
118-
prover.advance_proof(proof, max_iterations=opts.max_iterations)
119-
summary = proof.summary
120-
print(f'{summary}')
121-
122-
12370
def _kmir_view(opts: ViewOpts) -> None:
12471
kmir = KMIR(HASKELL_DEF_DIR, LLVM_LIB_DIR)
12572
proof = APRProof.read_proof_data(opts.proof_dir, opts.id)
@@ -212,12 +159,8 @@ def kmir(args: Sequence[str]) -> None:
212159
match opts:
213160
case RunOpts():
214161
_kmir_run(opts)
215-
case GenSpecOpts():
216-
_kmir_gen_spec(opts)
217162
case InfoOpts():
218163
_kmir_info(opts)
219-
case ProveRawOpts():
220-
_kmir_prove_raw(opts)
221164
case ViewOpts():
222165
_kmir_view(opts)
223166
case ShowOpts():
@@ -248,15 +191,6 @@ def _arg_parser() -> ArgumentParser:
248191
)
249192
run_parser.add_argument('--haskell-backend', action='store_true', help='Run with the haskell backend')
250193

251-
gen_spec_parser = command_parser.add_parser(
252-
'gen-spec', help='Generate a k spec from a SMIR json', parents=[kcli_args.logging_args]
253-
)
254-
gen_spec_parser.add_argument('input_file', metavar='FILE', help='MIR program to generate a spec for')
255-
gen_spec_parser.add_argument('--output-file', metavar='FILE', help='Output file')
256-
gen_spec_parser.add_argument(
257-
'--start-symbol', type=str, metavar='SYMBOL', default='main', help='Symbol name to begin execution from'
258-
)
259-
260194
info_parser = command_parser.add_parser(
261195
'info', help='Show information about a SMIR JSON file', parents=[kcli_args.logging_args]
262196
)
@@ -276,17 +210,6 @@ def _arg_parser() -> ArgumentParser:
276210
proof_args.add_argument('id', metavar='PROOF_ID', help='The id of the proof to view')
277211
proof_args.add_argument('--proof-dir', metavar='DIR', help='Proof directory')
278212

279-
prove_raw_parser = command_parser.add_parser(
280-
'prove', help='Utilities for working with proofs over SMIR', parents=[kcli_args.logging_args, prove_args]
281-
)
282-
prove_raw_parser.add_argument('input_file', metavar='FILE', help='K File with the spec module')
283-
prove_raw_parser.add_argument(
284-
'--include-labels', metavar='LABELS', help='Comma separated list of claim labels to include'
285-
)
286-
prove_raw_parser.add_argument(
287-
'--exclude-labels', metavar='LABELS', help='Comma separated list of claim labels to exclude'
288-
)
289-
290213
display_args = ArgumentParser(add_help=False)
291214
display_args.add_argument(
292215
'--full-printer',
@@ -394,22 +317,8 @@ def _parse_args(ns: Namespace) -> KMirOpts:
394317
start_symbol=ns.start_symbol,
395318
haskell_backend=ns.haskell_backend,
396319
)
397-
case 'gen-spec':
398-
return GenSpecOpts(input_file=Path(ns.input_file), output_file=ns.output_file, start_symbol=ns.start_symbol)
399320
case 'info':
400321
return InfoOpts(smir_file=Path(ns.smir_file), types=ns.types)
401-
case 'prove':
402-
proof_dir = Path(ns.proof_dir)
403-
return ProveRawOpts(
404-
spec_file=Path(ns.input_file),
405-
proof_dir=ns.proof_dir,
406-
include_labels=ns.include_labels,
407-
exclude_labels=ns.exclude_labels,
408-
bug_report=ns.bug_report,
409-
max_depth=ns.max_depth,
410-
reload=ns.reload,
411-
max_iterations=ns.max_iterations,
412-
)
413322
case 'show':
414323
return ShowOpts(
415324
proof_dir=Path(ns.proof_dir),

kmir/src/kmir/kdist/mir-semantics/kmir-ast.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,5 @@ module KMIR-AST
3333
3434
syntax TypeMappings ::= List{TypeMapping, ""} [group(mir-list), symbol(TypeMappings::append), terminator-symbol(TypeMappings::empty)]
3535
36-
syntax KItem ::= #init( Pgm )
37-
3836
endmodule
39-
```
37+
```

kmir/src/kmir/kdist/mir-semantics/kmir.md

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

33
```k
44
requires "kmir-ast.md"
5-
requires "symbolic/kmir-symbolic-locals.md"
65
requires "rt/data.md"
76
requires "rt/configuration.md"
87
requires "lemmas/kmir-lemmas.md"
@@ -31,7 +30,6 @@ module KMIR-CONTROL-FLOW
3130
imports MAP
3231
imports K-EQUAL
3332
34-
imports KMIR-AST
3533
imports MONO
3634
imports TYPES
3735
@@ -45,146 +43,7 @@ function map and the initial memory have to be set up.
4543

4644
All of this is done in the client code so we omit the initialisation code which was historically placed here.
4745

48-
```
49-
// #init step, assuming a singleton in the K cell
50-
rule <k> #init(_NAME:Symbol _ALLOCS:GlobalAllocs FUNCTIONS:FunctionNames _ITEMS:MonoItems _TYPES:TypeMappings _MACHINE:MachineInfo)
51-
=>
52-
#execFunction(#findItem(ITEMS, FUNCNAME), FUNCTIONS)
53-
</k>
54-
```
55-
56-
The `Map` of types is static information used for decoding constants and allocated data into `Value`s.
57-
It maps `Ty` IDs to `TypeInfo` that can be supplied to decoding and casting functions as well as operations involving `Aggregate` values (related to `struct`s and `enum`s).
58-
59-
```
60-
syntax Map ::= #mkTypeMap ( Map, TypeMappings ) [function, total, symbol("mkTypeMap")]
61-
62-
rule #mkTypeMap(ACC, .TypeMappings) => ACC
63-
64-
// build map of Ty -> RigidTy from suitable pairs
65-
rule #mkTypeMap(ACC, TypeMapping(TY, TYPEINFO) MORE:TypeMappings)
66-
=>
67-
#mkTypeMap(ACC[TY <- TYPEINFO], MORE)
68-
requires notBool TY in_keys(ACC)
69-
[preserves-definedness] // key collision checked
70-
71-
// skip anything that causes a key collision
72-
rule #mkTypeMap(ACC, _OTHERTYKIND:TypeMapping MORE:TypeMappings)
73-
=>
74-
#mkTypeMap(ACC, MORE)
75-
[owise]
76-
```
77-
78-
The `Map` of `functions` is constructed from the lookup table of `FunctionNames`,
79-
composed with a secondary lookup of `Item`s via `symbolName`. This composed map will
80-
only be populated for `MonoItemFn` items that are indeed _called_ in the code (i.e.,
81-
they are callee in a `Call` terminator within an `Item`).
82-
83-
The function _names_ and _ids_ are not relevant for calls and therefore dropped.
84-
85-
```
86-
syntax Map ::= #mkFunctionMap ( FunctionNames, MonoItems ) [ function, total, symbol("mkFunctionMap") ]
87-
| #accumFunctions ( Map, Map, FunctionNames ) [ function, total ]
88-
| #accumItems ( Map, MonoItems ) [ function, total ]
89-
90-
rule #mkFunctionMap(Functions, Items)
91-
=>
92-
#accumFunctions(#mainIsMinusOne(Items), #accumItems(.Map, Items), Functions)
93-
//////////////////// ^^^^^^^^^^^^^^^^^^^^^^ HACK Adds "main" as function with ty(-1)
94-
syntax Map ::= #mainIsMinusOne(MonoItems) [function]
95-
rule #mainIsMinusOne(ITEMS) => ty(-1) |-> monoItemKind(#findItem(ITEMS, symbol("main")))
96-
////////////////////////////////////////////////////////////////
97-
98-
// accumulate map of symbol_name -> function (MonoItemFn), discarding duplicate IDs
99-
rule #accumItems(Acc, .MonoItems) => Acc
100-
101-
rule #accumItems(Acc, monoItem(SymName, monoItemFn(_, _, _) #as Function) Rest:MonoItems)
102-
=>
103-
#accumItems(Acc (SymName |-> Function), Rest)
104-
requires notBool (SymName in_keys(Acc))
105-
[ preserves-definedness ] // key collisions checked
106-
107-
// discard other items and duplicate symbolNames
108-
rule #accumItems(Acc, _:MonoItem Rest:MonoItems)
109-
=>
110-
#accumItems(Acc, Rest)
111-
[ owise ]
112-
113-
// accumulate composed map of Ty -> MonoItemFn, using item map from before and function names
114-
rule #accumFunctions(Acc, _, .List) => Acc
115-
116-
rule #accumFunctions(Acc, ItemMap, ListItem(functionName(TyIdx, functionNormalSym(SymName))) Rest )
117-
=>
118-
#accumFunctions(Acc (TyIdx |-> ItemMap[SymName]), ItemMap, Rest)
119-
requires SymName in_keys(ItemMap)
120-
andBool notBool (TyIdx in_keys(Acc))
121-
[preserves-definedness]
12246

123-
// TODO handle NoOpSym and IntrinsicSym cases here
124-
125-
// discard anything else:
126-
// - duplicate Ty mappings (impossible by construction in stable-mir-json)
127-
// - unknown symbol_name (impossible by construction in stable-mir-json)
128-
rule #accumFunctions(Acc, ItemMap, ListItem(_) Rest)
129-
=>
130-
#accumFunctions(Acc, ItemMap, Rest)
131-
[ owise ]
132-
133-
```
134-
135-
Executing a given named function means to create the `currentFrame` data
136-
structure from its function body and then execute the first basic
137-
block of the body. The function's `Ty` index in the `functions` map must
138-
be known to populate the `currentFunc` field.
139-
140-
```
141-
// find function through its MonoItemFn.name
142-
syntax MonoItem ::= #findItem ( MonoItems, Symbol ) [ function ]
143-
144-
rule #findItem( (monoItem(_, monoItemFn(N, _, _)) #as ITEM) _REST, NAME )
145-
=>
146-
ITEM
147-
requires N ==K NAME
148-
rule #findItem( _:MonoItem REST:MonoItems, NAME )
149-
=>
150-
#findItem(REST, NAME)
151-
[owise]
152-
// rule #findItem( .MonoItems, _NAME) => error!
153-
154-
syntax KItem ::= #execFunction ( MonoItem, FunctionNames )
155-
156-
rule <k> #execFunction(
157-
monoItem(
158-
SYMNAME,
159-
monoItemFn(_, _, someBody(body((FIRST:BasicBlock _) #as BLOCKS,LOCALS, _, _, _, _)))
160-
),
161-
FUNCTIONNAMES
162-
)
163-
=>
164-
#execBlock(FIRST)
165-
...
166-
</k>
167-
<currentFunc> _ => #tyFromName(SYMNAME, FUNCTIONNAMES) </currentFunc>
168-
<currentFrame>
169-
<currentBody> _ => toKList(BLOCKS) </currentBody>
170-
<caller> _ => ty(-1) </caller> // no caller
171-
<dest> _ => place(local(-1), .ProjectionElems)</dest>
172-
<target> _ => noBasicBlockIdx </target>
173-
<unwind> _ => unwindActionUnreachable </unwind>
174-
<locals> _ => #reserveFor(LOCALS) </locals>
175-
</currentFrame>
176-
177-
// This function performs a reverse lookup in the functions table (looks up a `Ty` by name)
178-
// It defaults to `Ty(-1)` which is currently what `main` gets (`main` is not in the functions table)
179-
syntax Ty ::= #tyFromName( Symbol, FunctionNames ) [function, total]
180-
181-
rule #tyFromName(NAME, ListItem(functionName(TY, functionNormalSym(FNAME))) _) => TY
182-
requires NAME ==K FNAME
183-
rule #tyFromName(NAME, ListItem(_) REST:List) => #tyFromName(NAME, REST)
184-
[owise]
185-
186-
rule #tyFromName(_, .List) => ty(-1) // HACK see #mainIsMinusOne above
187-
```
18847
#### Function Execution
18948

19049

@@ -677,8 +536,7 @@ The top-level module `KMIR` includes both the control flow constructs (and trans
677536

678537
```k
679538
module KMIR
539+
imports KMIR-AST // Necessary for the external Python parser
680540
imports KMIR-CONTROL-FLOW
681541
imports KMIR-LEMMAS
682-
// imports KMIR-SYMBOLIC-LOCALS
683-
684542
endmodule

kmir/src/kmir/kdist/mir-semantics/rt/configuration.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ Besides the `caller` (to return to) and `dest` and `target` to specify where the
1717
requires "./value.md"
1818
1919
module KMIR-CONFIGURATION
20-
imports KMIR-AST
2120
imports INT-SYNTAX
2221
imports BOOL-SYNTAX
2322
imports RT-VALUE-SYNTAX
@@ -32,7 +31,7 @@ module KMIR-CONFIGURATION
3231
locals:List) // return val, args, local variables
3332
3433
configuration <kmir>
35-
<k> #init($PGM:Pgm) </k>
34+
<k> $PGM:KItem </k>
3635
<retVal> noReturn </retVal>
3736
<currentFunc> ty(-1) </currentFunc> // to retrieve caller
3837
// unpacking the top frame to avoid frequent stack read/write operations

0 commit comments

Comments
 (0)