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

feat: Add pretty printer for expressions. #564

Merged
merged 20 commits into from
Jul 26, 2022
Merged

Conversation

patrickaldis
Copy link

@patrickaldis patrickaldis commented Jul 12, 2022

Need to:

  • Render types - currently only expressions are rendered
  • Increase clarity via:
    • Reduce use of brackets (if possible)
    • Indent based on brackets

@patrickaldis patrickaldis requested a review from a team July 14, 2022 11:46
@patrickaldis patrickaldis force-pushed the georgefst/pretty-expr branch from 5672178 to 56183b2 Compare July 14, 2022 13:40
Copy link
Contributor

@georgefst georgefst left a comment

Choose a reason for hiding this comment

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

The actual important Haskell code in prettyExpr and prettyType is great. And the output is indeed very pretty! Most of the comments above are fairly nitpicky.

I have a few more suggestions related to git. Depending on how comfortable you are with git rebasing, maybe we should save these for when we next meet in person. I'm also happy not to actually fix any of these, and just bear these points in mind as guidance for the future, as long as @dhess feels the same way.

Also CI is currently failing. The reasons can be seen by clicking on one of the red crosses, but to be fair, the output isn't always easy to decipher.

  • The added test is failing. You can see this by running on your local machine: :main -p Pretty fails now that we print types properly. Try :main -p Pretty --accept and commit the new version.
  • Weeder is complaining about the fact that three of the added functions have been removed.
    • We should definitely add prettyPrintExpr and prettyPrintType to the ignoreRoots list in weeder.dhall, since they fit the description in the comment there.
    • On the other hand, not should perhaps just be removed. It was a convenience for exploratory testing, but now that we have actual tests it doesn't serve much purpose. Alternatively, we could utilise not in a new test case in Tests.Pretty. There's something to be said for having a simpler, more legible test case in addition to testing the large (and nonsensical) comprehensive definition.
  • The Cabal file is no longer formatted as we require. This is actually my bad, as I'm the one who added the dependency with a long name (prettyprinter-ansi-terminal). Run cabal-fmt -i primer/primer.cabal.
    • FWIW, I believe the next release of HLS will have support for cabal-fmt, so that we can just use format-on-save as we do for our .hs files.

@dhess
Copy link
Member

dhess commented Jul 18, 2022

Was there any attempt here to align the prettyprinter colors with our frontend tree color scheme? And if not, does it make sense to do so? (We could do it as a later PR — it's not particularly high priority.)

@dhess
Copy link
Member

dhess commented Jul 18, 2022

I have a few more suggestions related to git. Depending on how comfortable you are with git rebasing, maybe we should save these for when we next meet in person. I'm also happy not to actually fix any of these, and just bear these points in mind as guidance for the future, as long as @dhess feels the same way.

Rebasing is a pain and tricky even for experienced developers, and probably not a great use of either your or @patrickaldis's time, so I think we can make an exception in this instance.

@dhess
Copy link
Member

dhess commented Jul 18, 2022

One last thing — don't forget to update the first post to reflect what you want the merge commit to say, as that's what'll appear in the git logs.

@georgefst
Copy link
Contributor

One last thing — don't forget to update the first post to reflect what you want the merge commit to say, as that's what'll appear in the git logs.

That was true with Bors, but not with GitHub's merge queues. See e.g. 5d2cd96.

@georgefst
Copy link
Contributor

Was there any attempt here to align the prettyprinter colors with our frontend tree color scheme?

Yes.

image

@georgefst
Copy link
Contributor

It's only Weeder failing now, so once the new tests I suggested (testing not and prettyType) are added, we'll be good to merge!

@georgefst
Copy link
Contributor

Actually, one final request: could we use different colours for global variables and constructors?

It looks like Blue is our only unused colour (aside from Black, but I'm wary of using that as it clashes with most terminal backgrounds). And with local vars using Cyan that works out nicely, as they should be similar (in fact, it wouldn't bother me if they used the exact same colour, but seeing as we have one spare, we may as well use it).

@patrickaldis patrickaldis force-pushed the georgefst/pretty-expr branch 7 times, most recently from 13611e1 to 7598212 Compare July 25, 2022 10:02
path = "test/outputs/Pretty/" ++ dname ++ "/" ++ hname
bs = case d of
DefPrim _ -> exitFailure
DefAST e -> docToBS (fst h e)
Copy link
Contributor

Choose a reason for hiding this comment

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

Some minor style issues (the kind of thing HLint would pick up, if it were slightly cleverer) with this function:

  • Any particular reason why it isn't written in curried form? i.e. Why isn't the type String -> Def -> PrettyTestHandler -> TestTree?
  • We bind n, then assign it to dname below. Why not just prettyTest (dname ...?

Copy link
Author

Choose a reason for hiding this comment

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

I think the n/dname issue was just because I was writing all the variables in the definition as single letters, and then later changed it when using it in the the where block. I'll change this

I thought in the type signature

(String, Def) -> PrettyTestHandler -> TestTree

The expression name and definition came as a pair, whereas the handler seemed separate. I can make this curried though if this is bad practice.

Copy link
Contributor

Choose a reason for hiding this comment

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

The expression name and definition came as a pair, whereas the handler seemed separate.

Fair enough! Sometimes that distinction does make sense.

@patrickaldis patrickaldis force-pushed the georgefst/pretty-expr branch from db0d123 to 28fe7fa Compare July 25, 2022 13:30
@georgefst georgefst self-requested a review July 25, 2022 15:18
@patrickaldis patrickaldis added this pull request to the merge queue Jul 25, 2022
Patrick Aldis and others added 14 commits July 26, 2022 10:53
This is a temporary state of affairs, in order to satisfy Fourmolu. Even though we have `GHC2022` enabled in our Cabal file, Fourmolu 0.6 doesn't search there for extensions. Note that we have updated to Fourmolu 0.7, which does, in db9d114, but this branch is currently behind `main`.
We ended up with an inconsistency in import styles due to an awkward Git history, and HLS and CLI versions of Fourmolu previously being out of sync.
@dhess dhess removed this pull request from the merge queue due to a manual request Jul 26, 2022
@georgefst georgefst force-pushed the georgefst/pretty-expr branch from 28fe7fa to 79fcea1 Compare July 26, 2022 10:06
@georgefst georgefst enabled auto-merge July 26, 2022 10:06
@georgefst
Copy link
Contributor

Rebased due to conflicts with #563.

@georgefst georgefst added this pull request to the merge queue Jul 26, 2022
Merged via the queue into main with commit b4a5c65 Jul 26, 2022
@georgefst georgefst deleted the georgefst/pretty-expr branch July 26, 2022 10:24
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.

4 participants