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

Optimize pyk.kast.inner.collect #4708

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Changes from all commits
Commits
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
14 changes: 6 additions & 8 deletions pyk/src/pyk/kast/inner.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,20 +877,18 @@ def _var_occurence(_term: KInner) -> None:
return _var_occurrences


# TODO replace by method that does not reconstruct the AST
def collect(callback: Callable[[KInner], None], kinner: KInner) -> None:
"""Collect information about a given term traversing it bottom-up using a function with side effects.
"""Collect information about a given term traversing it top-down using a function with side effects.

Args:
callback: Function with the side effect of collecting desired information at each AST node.
kinner: The term to traverse.
"""

def f(kinner: KInner) -> KInner:
callback(kinner)
return kinner

bottom_up(f, kinner)
subterms = [kinner]
while subterms:
term = subterms.pop()
subterms.extend(reversed(term.terms))
callback(term)


def build_assoc(unit: KInner, label: str | KLabel, terms: Iterable[KInner]) -> KInner:
Expand Down
Loading