You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Factor out CTermShow class for simpler node printing (#4808)
~Blocked on: #4819
This is a refactoring to how our display of nodes/KCFGs works, ideally
to make it easier to thread options through to them. We're specifically
trying to capture all the common options for how `CTerm` should be
displayed in one place, and remove those options from other places. This
came about as I was trying to implement some asks from the KMIR team on
changing the display in the TUI viewer, and realized that currently all
the options are threaded through in different ways and controlled at
different points.
This is a breaking change in pyk API, and so corresponding changes into
downstream repos will need to be added to the update-deps PRs.
Another big change that happens here: the `kcfg` directory no longer
needs a `KPrint` because we use a `kast.pretty.PrettyPrinter` directly
instead. Before, it was using `KPrint.pretty_print`, which was just
constructing a `PrettyPrinter` then using it. So we skip the
intermediate class. That means that several classes which took in a
`KPrint` now just take in a `KDefinition`.
Changes in particular:
- A new class `CTermShow` is introduced, which enables printing out
`CTerm` using a `PrettyPrinter`, via `CTermShow.show_config`,
`CTermShow.show_constraints` and `CTermShow.show`. It takes several
options controlling how printing can occur, including:
- `extra_unparsing_modules`, `patch_symbol_table`, `unalias`, and
`sort_ac_collections`: all the same as `PrettyPrinter`.
- `minimize`: collapse unused cell-variables into `...`, and the
recursively collapse the `...` as much as possible in the configuration.
- `break_cell_collections`: enable line-breaking collections (`List`,
`Set`, `Map`) which are stored directly in cells, as usually you want
one item printer per line in this case.
- `omit_labels`: a set of labels to always replace occurrences of with
`...`, so they do not get printed.
- `NodePrinter` (and `APRProofNodePrinter`) now take a `CTermShow`
instead of a `KPrint`, which also means they don't take the options
controlling printing directly (like `minimize`). These options must be
set when building teh `CTermShow` that is passed in for the
`NodePrinter` to use.
- Similarly, `KCFGShow` (and `APRProofShow`) now take a `KDefinition`
instead of a `KPrint` and build a `PrettyPrinter` directly. This means
that the `NodePrinter` (and thus `CTermShow`) is responsible for setting
options related to node printing like `sort_collections` ahead of time.
- The `KCFGViewer` (and `APRProofViewer`) are now taking directly a
`KDefinition` instead of a `KPrint`, and similar to the `*Show`
counterparts offloading decisions about how to print items to how the
`CTermShow` is setup in the client application.
- Tests are updated with the new pattern (of constructing a `CTermShow`
ahead of time and passing it in), which provides an example of what's
needed downstream. In particular, before we were mocking an entire
`KPrint` in the unit tests, but now we only need to mock a `CTermShow`,
which is much more compact. We rename the file from `mock_kprint.py` to
`mock.py`, so it can be for all mocks.
0 commit comments