Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reusing backend information to construct KCFGs more efficiently #4590

Merged
merged 31 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
5630763
different approach
PetarMax Aug 15, 2024
6ff9f37
no changes to .toml
PetarMax Aug 15, 2024
cb9e98c
reverting changes
PetarMax Aug 15, 2024
00d519e
adding predecessor to APRProofStep
PetarMax Aug 15, 2024
f2158a8
correction
PetarMax Aug 15, 2024
733d089
overhaul
PetarMax Aug 15, 2024
33fcde3
Merge branch 'develop' into petar/streamlining-branching
PetarMax Aug 15, 2024
869e7b2
formatting correction
PetarMax Aug 15, 2024
b20e4c6
better logging message
PetarMax Aug 15, 2024
a60b914
further messages
PetarMax Aug 15, 2024
45fd80b
minor further messages
PetarMax Aug 16, 2024
0018b2a
moving logic to APRProof
PetarMax Aug 16, 2024
b0bc50e
corrections
PetarMax Aug 16, 2024
8d4ab1f
documentation and circularity precision
PetarMax Aug 16, 2024
69b3c98
Merge branch 'develop' into petar/streamlining-branching
PetarMax Aug 16, 2024
e865465
second attempt at understanding circularities
PetarMax Aug 16, 2024
12b0fc0
additional precision re circular rules
PetarMax Aug 16, 2024
5ce87e8
correction
PetarMax Aug 16, 2024
68ba0b1
more corrections
PetarMax Aug 16, 2024
3321f48
comments
PetarMax Aug 16, 2024
9c86d7e
formatting
PetarMax Aug 16, 2024
207e325
even more formatting
PetarMax Aug 16, 2024
c19f63d
removing always_check_subsumption, more comments
PetarMax Aug 16, 2024
4d695ad
correction
PetarMax Aug 16, 2024
d3d3cae
Final correction
PetarMax Aug 17, 2024
4d54908
Update pyk/src/pyk/kcfg/explore.py
PetarMax Aug 17, 2024
a661700
Update pyk/src/pyk/kcfg/explore.py
PetarMax Aug 17, 2024
852fba4
minor corrections
PetarMax Aug 19, 2024
76e9f1e
refactoring proof results
PetarMax Aug 19, 2024
c3e6e8d
Update pyk/src/pyk/proof/reachability.py
PetarMax Aug 19, 2024
e60d2be
Update semantics.py
PetarMax Aug 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 25 additions & 20 deletions pyk/src/pyk/kcfg/explore.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,19 +218,20 @@ def extend_cterm(
cut_point_rules: Iterable[str] = (),
terminal_rules: Iterable[str] = (),
module_name: str | None = None,
) -> KCFGExtendResult:
) -> list[KCFGExtendResult]:
PetarMax marked this conversation as resolved.
Show resolved Hide resolved

def log(message: str, *, warning: bool = False) -> None:
_LOGGER.log(logging.WARNING if warning else logging.INFO, f'Extend result for {self.id}: {message}')

custom_step_result = self.kcfg_semantics.custom_step(_cterm)
if custom_step_result is not None:
log(f'custom step node: {node_id}')
return custom_step_result
return [custom_step_result]

abstract_cterm = self.kcfg_semantics.abstract_node(_cterm)
if _cterm != abstract_cterm:
log(f'abstraction node: {node_id}')
return Abstract(abstract_cterm)
return [Abstract(abstract_cterm)]

cterm, next_states, depth, vacuous, next_node_logs = self.cterm_symbolic.execute(
_cterm,
Expand All @@ -240,33 +241,35 @@ def log(message: str, *, warning: bool = False) -> None:
module_name=module_name,
)

extend_results: list[KCFGExtendResult] = []

# Basic block
if depth > 0:
log(f'basic block at depth {depth}: {node_id}')
return Step(cterm, depth, next_node_logs, self._extract_rule_labels(next_node_logs))
extend_results.append(Step(cterm, depth, next_node_logs, self._extract_rule_labels(next_node_logs)))

# Stuck or vacuous
if not next_states:
if vacuous:
log(f'vacuous node: {node_id}', warning=True)
return Vacuous()
log(f'stuck node: {node_id}')
return Stuck()

extend_results.append(Vacuous())
else:
log(f'stuck node: {node_id}')
extend_results.append(Stuck())
# Cut rule
if len(next_states) == 1:
elif len(next_states) == 1:
log(f'cut-rule basic block at depth {depth}: {node_id}')
return Step(
next_states[0].state,
1,
next_node_logs,
self._extract_rule_labels(next_node_logs),
cut=True,
extend_results.append(
Step(
next_states[0].state,
1,
next_node_logs,
self._extract_rule_labels(next_node_logs),
cut=True,
)
)

# Branch
assert len(next_states) > 1
if all(branch_constraint for _, branch_constraint in next_states):
elif all(branch_constraint for _, branch_constraint in next_states):
branch_preds = [flatten_label('#And', not_none(rule_predicate)) for _, rule_predicate in next_states]
common_preds = list(
unique(
Expand All @@ -283,9 +286,11 @@ def log(message: str, *, warning: bool = False) -> None:
)
constraint_strs = [self.pretty_print(ml_pred_to_bool(bc)) for bc in branches]
log(f'{len(branches)} branches: {node_id} -> {constraint_strs}')
return Branch(branches)
extend_results.append(Branch(branches))
else:
# NDBranch
log(f'{len(next_states)} non-deterministic branches: {node_id}')
next_cterms = [cterm for cterm, _ in next_states]
return NDBranch(next_cterms, next_node_logs, self._extract_rule_labels(next_node_logs))
extend_results.append(NDBranch(next_cterms, next_node_logs, self._extract_rule_labels(next_node_logs)))

return extend_results
28 changes: 20 additions & 8 deletions pyk/src/pyk/proof/reachability.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ class APRProver(Prover[APRProof, APRProofStep, APRProofResult]):
direct_subproof_rules: bool
assume_defined: bool
kcfg_explore: KCFGExplore
next_steps: dict[NodeIdLike, KCFGExtendResult]
PetarMax marked this conversation as resolved.
Show resolved Hide resolved

def __init__(
self,
Expand All @@ -698,6 +699,7 @@ def __init__(
self.fast_check_subsumption = fast_check_subsumption
self.direct_subproof_rules = direct_subproof_rules
self.assume_defined = assume_defined
self.next_steps = {}

def close(self) -> None:
self.kcfg_explore.cterm_symbolic._kore_client.close()
Expand Down Expand Up @@ -793,14 +795,24 @@ def step_proof(self, step: APRProofStep) -> list[APRProofResult]:
if step.circularity and not step.nonzero_depth and (execute_depth is None or execute_depth > 1):
execute_depth = 1

extend_result = self.kcfg_explore.extend_cterm(
step.node.cterm,
execute_depth=execute_depth,
cut_point_rules=cut_rules,
terminal_rules=self.terminal_rules,
module_name=step.module_name,
node_id=step.node.id,
)
if step.node.id in self.next_steps:
extend_results = [self.next_steps.pop(step.node.id)]
else:
extend_results = self.kcfg_explore.extend_cterm(
step.node.cterm,
execute_depth=execute_depth,
cut_point_rules=cut_rules,
terminal_rules=self.terminal_rules,
module_name=step.module_name,
node_id=step.node.id,
)

assert len(extend_results) == 1 or len(extend_results) == 2
extend_result = extend_results[0]
if len(extend_results) == 2:
assert step.node.id not in self.next_steps
self.next_steps[step.node.id] = extend_results[1]
PetarMax marked this conversation as resolved.
Show resolved Hide resolved

return [
APRProofExtendResult(
node_id=step.node.id, extend_result=extend_result, prior_loops_cache_update=prior_loops
Expand Down
Loading