-
Notifications
You must be signed in to change notification settings - Fork 161
Improvements to show, and new show from disc #4911
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
Draft
mariaKt
wants to merge
6
commits into
develop
Choose a base branch
from
mk/show-from-disk-2
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c008426
Added lazy (generator based) show_iter. show unchanged for now.
mariaKt cc8cb7e
show now use show_iter (materialize generator)
mariaKt 0556f90
stubs for kcfg needed types
mariaKt 34fc00f
Testing for show_iter_from_disc
mariaKt 0275f6a
Removed duplication, instead edit from_dict with lazy param
mariaKt 57ddca4
Code quality
mariaKt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,151 @@ | ||||||||||||||||||||||||||||||||||||
| """Lazy loading stubs for memory-efficient proof display. | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| These stubs duck-type the real KCFG classes, deferring heavy data loading | ||||||||||||||||||||||||||||||||||||
| (node CTerms, cover/split CSubsts) until actually accessed for printing. | ||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| from __future__ import annotations | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| import json | ||||||||||||||||||||||||||||||||||||
| from typing import TYPE_CHECKING | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| if TYPE_CHECKING: | ||||||||||||||||||||||||||||||||||||
| from pathlib import Path | ||||||||||||||||||||||||||||||||||||
| from typing import Any | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| from ..cterm import CSubst, CTerm | ||||||||||||||||||||||||||||||||||||
| from ..kast.inner import KInner | ||||||||||||||||||||||||||||||||||||
| from .kcfg import KCFG | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| class LazyNode: | ||||||||||||||||||||||||||||||||||||
| """Duck-types KCFG.Node. Loads CTerm from disk on first .cterm access.""" | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| id: int | ||||||||||||||||||||||||||||||||||||
| attrs: frozenset | ||||||||||||||||||||||||||||||||||||
| _node_path: Path | ||||||||||||||||||||||||||||||||||||
| _cterm: CTerm | None | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| def __init__(self, id: int, attrs: frozenset, node_path: Path) -> None: | ||||||||||||||||||||||||||||||||||||
| self.id = id | ||||||||||||||||||||||||||||||||||||
| self.attrs = attrs | ||||||||||||||||||||||||||||||||||||
| self._node_path = node_path | ||||||||||||||||||||||||||||||||||||
| self._cterm = None | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| @property | ||||||||||||||||||||||||||||||||||||
| def cterm(self) -> CTerm: | ||||||||||||||||||||||||||||||||||||
| if self._cterm is None: | ||||||||||||||||||||||||||||||||||||
| from ..cterm import CTerm | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| node_dict = json.loads(self._node_path.read_text()) | ||||||||||||||||||||||||||||||||||||
| self._cterm = CTerm.from_dict(node_dict['cterm']) | ||||||||||||||||||||||||||||||||||||
| return self._cterm | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| def evict(self) -> None: | ||||||||||||||||||||||||||||||||||||
| """Release the loaded CTerm from memory.""" | ||||||||||||||||||||||||||||||||||||
| self._cterm = None | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| def __eq__(self, other: object) -> bool: | ||||||||||||||||||||||||||||||||||||
| if isinstance(other, LazyNode): | ||||||||||||||||||||||||||||||||||||
| return self.id == other.id | ||||||||||||||||||||||||||||||||||||
| # Also compare with real KCFG.Node | ||||||||||||||||||||||||||||||||||||
| return hasattr(other, 'id') and self.id == other.id | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+48
to
+52
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would this be equivalent anyway?
Suggested change
Or perhaps the tighter:
Suggested change
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the second one. I think it captures the intention (only LazyNode or Node) better. |
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| def __hash__(self) -> int: | ||||||||||||||||||||||||||||||||||||
| return hash(self.id) | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| def __lt__(self, other: object) -> bool: | ||||||||||||||||||||||||||||||||||||
| if hasattr(other, 'id'): | ||||||||||||||||||||||||||||||||||||
| return self.id < other.id | ||||||||||||||||||||||||||||||||||||
| return NotImplemented | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| def __le__(self, other: object) -> bool: | ||||||||||||||||||||||||||||||||||||
| if hasattr(other, 'id'): | ||||||||||||||||||||||||||||||||||||
| return self.id <= other.id | ||||||||||||||||||||||||||||||||||||
| return NotImplemented | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| class APRProofStub: | ||||||||||||||||||||||||||||||||||||
| """Lightweight stub for APRProof — answers proof-level queries without loading the full proof. | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| Duck-types enough of APRProof for APRProofNodePrinter.node_attrs() to work. | ||||||||||||||||||||||||||||||||||||
| Uses proof.json metadata + the KCFG for graph queries. | ||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| def __init__(self, proof_dict: dict[str, Any], kcfg: KCFG) -> None: | ||||||||||||||||||||||||||||||||||||
| self.init = int(proof_dict['init']) | ||||||||||||||||||||||||||||||||||||
| self.target = int(proof_dict['target']) | ||||||||||||||||||||||||||||||||||||
| self._terminal_ids = set(proof_dict.get('terminal') or []) | ||||||||||||||||||||||||||||||||||||
| self._bounded_ids = set(proof_dict.get('bounded') or []) | ||||||||||||||||||||||||||||||||||||
| self._refuted_ids = {int(k) for k in (proof_dict.get('node_refutations') or {}).keys()} | ||||||||||||||||||||||||||||||||||||
| self.kcfg = kcfg | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| def _resolve(self, node_id: int) -> int: | ||||||||||||||||||||||||||||||||||||
| return node_id | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| def is_init(self, node_id: int) -> bool: | ||||||||||||||||||||||||||||||||||||
| return node_id == self.init | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| def is_target(self, node_id: int) -> bool: | ||||||||||||||||||||||||||||||||||||
| return node_id == self.target | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| def is_terminal(self, node_id: int) -> bool: | ||||||||||||||||||||||||||||||||||||
| return node_id in self._terminal_ids | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| def is_explorable(self, node_id: int) -> bool: | ||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||
| self.kcfg.is_leaf(node_id) | ||||||||||||||||||||||||||||||||||||
| and not self.is_terminal(node_id) | ||||||||||||||||||||||||||||||||||||
| and not self.kcfg.is_stuck(node_id) | ||||||||||||||||||||||||||||||||||||
| and not self.kcfg.is_vacuous(node_id) | ||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| def is_pending(self, node_id: int) -> bool: | ||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||
| self.is_explorable(node_id) | ||||||||||||||||||||||||||||||||||||
| and not self.is_target(node_id) | ||||||||||||||||||||||||||||||||||||
| and not self.is_refuted(node_id) | ||||||||||||||||||||||||||||||||||||
| and not self.is_bounded(node_id) | ||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| def is_refuted(self, node_id: int) -> bool: | ||||||||||||||||||||||||||||||||||||
| return node_id in self._refuted_ids | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| def is_bounded(self, node_id: int) -> bool: | ||||||||||||||||||||||||||||||||||||
| return node_id in self._bounded_ids | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| class LazyCSubst: | ||||||||||||||||||||||||||||||||||||
| """Duck-types CSubst. Loads from a JSON dict on first access.""" | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| _raw: dict[str, Any] | ||||||||||||||||||||||||||||||||||||
| _csubst: CSubst | None | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| def __init__(self, raw_dict: dict[str, Any]) -> None: | ||||||||||||||||||||||||||||||||||||
| self._raw: dict[str, Any] = raw_dict | ||||||||||||||||||||||||||||||||||||
| self._csubst = None | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| def _load(self) -> CSubst: | ||||||||||||||||||||||||||||||||||||
| if self._csubst is None: | ||||||||||||||||||||||||||||||||||||
| from ..cterm import CSubst | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| self._csubst = CSubst.from_dict(self._raw) | ||||||||||||||||||||||||||||||||||||
| return self._csubst | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| @property | ||||||||||||||||||||||||||||||||||||
| def constraints(self) -> tuple: | ||||||||||||||||||||||||||||||||||||
| return self._load().constraints | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| @property | ||||||||||||||||||||||||||||||||||||
| def subst(self) -> object: | ||||||||||||||||||||||||||||||||||||
| return self._load().subst | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| def pred(self, *args: Any, **kwargs: Any) -> KInner: | ||||||||||||||||||||||||||||||||||||
| return self._load().pred(*args, **kwargs) | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| def to_dict(self) -> dict: | ||||||||||||||||||||||||||||||||||||
| return self._load().to_dict() | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| def evict(self) -> None: | ||||||||||||||||||||||||||||||||||||
| """Release the loaded CSubst from memory, keep raw dict for reload.""" | ||||||||||||||||||||||||||||||||||||
| self._csubst = None | ||||||||||||||||||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't actually see where this is used, how does this work? I assume somehow this gets called whenever we're done printing a given node?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I intended to use it in pretty_segments, but missed it. I will address.