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

Switch from ansi-wl-pprint to the prettyprinter package. #586

Merged
merged 4 commits into from
Dec 1, 2020

Conversation

brianhuffman
Copy link
Contributor

@brianhuffman brianhuffman commented Nov 22, 2020

Note: This PR builds on GaloisInc/what4#77, GaloisInc/saw-core#106, #584, and #585; it will stay in draft status until those PRs are accepted and merged.

EDIT: GaloisInc/saw-core#106, #584, and #585 have all been merged, so we're just waiting on GaloisInc/what4#77.

Copy link
Member

@kquick kquick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In about a half-dozen places you fixed the annotation to (); with the parameterized ann the rest of the time that seems like a shortest-path conversion but doesn't enhance the context for later handling like colorization. If the "shortest-path" assumption is correct, it might be nice to note that in the description of the PR for future reference (as opposed to having a reason for it explicitly being ()).

There were lots of locations that were effectively pretty . show, and you marked a couple but not many of those. It would be great to shorten those to pretty where possible and mark them where not possible with some kind of consistent comment mark for future updating.

Also not a lot of consistency between leveraging IsString and using pretty; if this was mostly a mechanical sed-style change, it might be worth going through and standardizing on the former where possible.

Mostly an eyeball-glazing mechanical set of changes, thanks for doing all of this! I had a few comments above and throughout but nothing significant enough to prevent merging, so feel free to ignore or change as you'd prefer but I think this is a good step forward to get merged.

crucible-llvm/src/Lang/Crucible/LLVM/Errors/MemoryError.hs Outdated Show resolved Hide resolved
crucible-llvm/src/Lang/Crucible/LLVM/Errors/MemoryError.hs Outdated Show resolved Hide resolved
crux-mir/src/Mir/PP.hs Outdated Show resolved Hide resolved
crux-mir/src/Mir/Trans.hs Outdated Show resolved Hide resolved
@brianhuffman
Copy link
Contributor Author

About using () as an annotation in some places: I had some doubts about that. None of the code anywhere used any color, ANSI features or other annotations. So I thought the best choice was to make all the pretty printing code polymorphic in the annotation type as much as possible, to make it easy to combine those pretty printers with ones from other packages.

One stumbling block was that there are a few datatypes that stored Doc values inside. What annotation type should I use for that? One possibility is to add an ann parameter to the datatype, which I did in one or two places in GaloisInc/what4#77 (mostly this was for pretty-printing-related datatypes, where it seemed to make sense). Another possibility would be to use rank-2 polymorphism, with a constructor field of type forall ann. Doc ann, but this seemed like overkill. The last possibility is to use a dummy type that basically signals that you're not using any annotations; I considered both () and Void. Actually Doc Void is probably the right choice semantically, as it basically doesn't allow you to use any annotations, but Doc () seemed to convey the intention better. Other places that use Doc () are mostly just the minimum necessary to get things to typecheck. I may have used Doc () in a couple of other places that use Doc only on input parameters, just to avoid ambiguous types (although, now that I think about it, I don't think GHC even has a problem with this kind of ambiguity if there's no class constraint on the variable, so maybe I can get rid of a few of these).

I'm not sure what we should consider the best practice for handling the Doc-inside-a-datatype thing; I couldn't find any relevant advice in the package documentation.

@brianhuffman
Copy link
Contributor Author

My latest thinking is that we should try to completely avoid pretty (show x), other than to define Pretty instances or custom type-specific pretty printing functions. Every occurrence of pretty (show x) is technical debt, in that we would prefer to get rid of it as soon as possible once other libraries get the required pretty printing support. So we should try to factor out all such occurrences into a small set of top-level functions, to make that later process easier.

@kquick
Copy link
Member

kquick commented Nov 23, 2020

I agree that it's unwanted tech-debt, but it's going to be hard to completely eliminate these due to using external libraries (even our own) that don't have prettyprinter Doc formatting.

One suggestion is to use the prettyprinter viaShow function when we can't eliminate this tech-debt: this function makes it clear that the pretty-printing was generated from a Show instance and is a nice footprint for future search/replace tech-debt reduction.

@brianhuffman
Copy link
Contributor Author

I just came across viaShow and I agree that it would be a good solution to make it easier to find places to fix later. So I think there's really no excuse for using pretty . show at all.

@robdockins
Copy link
Contributor

About using () as an annotation in some places: I had some doubts about that. None of the code anywhere used any color, ANSI features or other annotations. So I thought the best choice was to make all the pretty printing code polymorphic in the annotation type as much as possible, to make it easy to combine those pretty printers with ones from other packages.

One stumbling block was that there are a few datatypes that stored Doc values inside. What annotation type should I use for that? One possibility is to add an ann parameter to the datatype, which I did in one or two places in GaloisInc/what4#77 (mostly this was for pretty-printing-related datatypes, where it seemed to make sense). Another possibility would be to use rank-2 polymorphism, with a constructor field of type forall ann. Doc ann, but this seemed like overkill. The last possibility is to use a dummy type that basically signals that you're not using any annotations; I considered both () and Void. Actually Doc Void is probably the right choice semantically, as it basically doesn't allow you to use any annotations, but Doc () seemed to convey the intention better. Other places that use Doc () are mostly just the minimum necessary to get things to typecheck. I may have used Doc () in a couple of other places that use Doc only on input parameters, just to avoid ambiguous types (although, now that I think about it, I don't think GHC even has a problem with this kind of ambiguity if there's no class constraint on the variable, so maybe I can get rid of a few of these).

I'm not sure what we should consider the best practice for handling the Doc-inside-a-datatype thing; I couldn't find any relevant advice in the package documentation.

I think we should use Void as the annotation type anyplace where we are currently not using annotations. It accurately reflects the intention not to use them, and Void is easily remapped into whatever annotation you like in the places where that becomes necessary.

@brianhuffman brianhuffman force-pushed the prettyprinter branch 2 times, most recently from 427eeba to 72673e0 Compare November 24, 2020 03:15
brianhuffman pushed a commit to GaloisInc/saw-script that referenced this pull request Nov 25, 2020
This commit includes the following submodule PRs:
- GaloisInc/what4#77
- GaloisInc/crucible#586
- GaloisInc/macaw#178

WARNING: Do not merge this commit into master until all of the
above PRs are merged into their respective master branches and
the submodule references of this commit can be patched up.
brianhuffman pushed a commit to GaloisInc/saw-script that referenced this pull request Nov 30, 2020
This commit includes the following submodule PRs:
- GaloisInc/what4#77
- GaloisInc/crucible#586
- GaloisInc/macaw#178

WARNING: Do not merge this commit into master until all of the
above PRs are merged into their respective master branches and
the submodule references of this commit can be patched up.
Brian Huffman added 2 commits November 30, 2020 14:41
The following submodules have been updated to use prettyprinter:
- what4
- saw-core

The following packages have been converted:
- crucible
- crucible-jvm
- crucible-llvm
- crucible-saw
- crucible-server
- crucible-syntax
- crux
- crux-llvm
- crux-mir
Some occurrences have been refactored to avoid `show` altogether.

Using `viaShow` will make it easier to locate and remove this
pattern later when more Pretty class instances are added.
@kquick
Copy link
Member

kquick commented Dec 1, 2020

Re-reviewed with all the updated changes: this looks good to me!

brianhuffman pushed a commit to GaloisInc/macaw that referenced this pull request Dec 1, 2020
This patch relies on the following submodule updates:
- GaloisInc/what4#77
- GaloisInc/elf-edit#20
- GaloisInc/crucible#586

This patch updates the following packages:
- macaw-base
- macaw-symbolic
- macaw-x86
- macaw-x86-symbolic
- macaw-aarch32
- macaw-ppc
- macaw-semmc
- macaw-refinement
@brianhuffman brianhuffman merged commit c1da81f into master Dec 1, 2020
brianhuffman pushed a commit to GaloisInc/saw-script that referenced this pull request Dec 1, 2020
This commit includes the following submodule PRs:
- GaloisInc/what4#77
- GaloisInc/crucible#586
- GaloisInc/macaw#178

WARNING: Do not merge this commit into master until all of the
above PRs are merged into their respective master branches and
the submodule references of this commit can be patched up.
brianhuffman pushed a commit to GaloisInc/macaw that referenced this pull request Dec 1, 2020
This patch relies on the following submodule updates:
- GaloisInc/what4#77
- GaloisInc/elf-edit#20
- GaloisInc/crucible#586

This patch updates the following packages:
- macaw-base
- macaw-symbolic
- macaw-x86
- macaw-x86-symbolic
- macaw-aarch32
- macaw-ppc
- macaw-semmc
- macaw-refinement
brianhuffman pushed a commit to GaloisInc/saw-script that referenced this pull request Dec 1, 2020
This commit includes the following submodule PRs:
- GaloisInc/what4#77
- GaloisInc/crucible#586
- GaloisInc/macaw#178

WARNING: Do not merge this commit into master until all of the
above PRs are merged into their respective master branches and
the submodule references of this commit can be patched up.
brianhuffman pushed a commit to GaloisInc/saw-script that referenced this pull request Dec 1, 2020
This commit includes the following submodule PRs:
- GaloisInc/what4#77
- GaloisInc/crucible#586
- GaloisInc/macaw#178
- GaloisInc/elf-edit#20

WARNING: Do not merge this commit into master until all of the
above PRs are merged into their respective master branches and
the submodule references of this commit can be patched up.
brianhuffman pushed a commit to GaloisInc/asl-translator that referenced this pull request Dec 2, 2020
This patch includes and adapts to the following submodule PRs:
- GaloisInc/what4#77 "prettyprinter"
- GaloisInc/crucible#586 "prettyprinter"
brianhuffman pushed a commit to GaloisInc/macaw that referenced this pull request Dec 2, 2020
This patch relies on the following submodule updates:
- GaloisInc/what4#77
- GaloisInc/elf-edit#20
- GaloisInc/crucible#586
- GaloisInc/asl-translator#28

This patch updates the following packages:
- macaw-base
- macaw-symbolic
- macaw-x86
- macaw-x86-symbolic
- macaw-aarch32
- macaw-ppc
- macaw-semmc
- macaw-refinement
brianhuffman pushed a commit to GaloisInc/macaw that referenced this pull request Dec 2, 2020
This patch relies on the following submodule updates:
- GaloisInc/what4#77
- GaloisInc/elf-edit#20
- GaloisInc/crucible#586
- GaloisInc/asl-translator#28

This patch updates the following packages:
- macaw-base
- macaw-symbolic
- macaw-x86
- macaw-x86-symbolic
- macaw-aarch32
- macaw-ppc
- macaw-semmc
- macaw-refinement
brianhuffman pushed a commit to GaloisInc/macaw that referenced this pull request Dec 2, 2020
This patch relies on the following submodule updates:
- GaloisInc/what4#77
- GaloisInc/elf-edit#20
- GaloisInc/crucible#586
- GaloisInc/asl-translator#28

This patch updates the following packages:
- macaw-base
- macaw-symbolic
- macaw-x86
- macaw-x86-symbolic
- macaw-aarch32
- macaw-ppc
- macaw-semmc
- macaw-refinement
brianhuffman pushed a commit to GaloisInc/macaw that referenced this pull request Dec 2, 2020
This patch relies on the following submodule updates:
- GaloisInc/what4#77
- GaloisInc/elf-edit#20
- GaloisInc/crucible#586
- GaloisInc/asl-translator#28

This patch updates the following packages:
- macaw-base
- macaw-symbolic
- macaw-x86
- macaw-x86-symbolic
- macaw-aarch32
- macaw-ppc
- macaw-semmc
- macaw-refinement
brianhuffman pushed a commit to GaloisInc/macaw that referenced this pull request Dec 2, 2020
This patch relies on the following submodule updates:
- GaloisInc/what4#77
- GaloisInc/elf-edit#20
- GaloisInc/crucible#586
- GaloisInc/asl-translator#28

This patch updates the following packages:
- macaw-base
- macaw-symbolic
- macaw-x86
- macaw-x86-symbolic
- macaw-aarch32
- macaw-ppc
- macaw-semmc
- macaw-refinement
brianhuffman pushed a commit to GaloisInc/saw-script that referenced this pull request Dec 3, 2020
@travitch travitch deleted the prettyprinter branch December 16, 2021 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants