Support only GHC 9.0 #357
No reviewers
Labels
No Label
blocked: dependency
blocked: info-needed
bug
duplicate
enhancement
fixed in HEAD
help wanted
hs:arrows
hs:brackets
hs:classes
hs:comments
hs:do-notation
hs:guards
hs:lists
hs:operators
hs:patterns
hs:records
hs:types
invalid
language extension support
layouting
needs confirmation
priority: high
priority: low
question
revisit before next release
wontfix
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: hexagoxel/brittany#357
Loading…
Reference in New Issue
There is no content yet.
Delete Branch "main"
Deleting a branch is permanent. Although the deleted branch may exist for a short time before cleaning up, in most cases it CANNOT be undone. Continue?
This fixes #352. It is an alternative to #356.
This pull request adds support for GHC 9.0 but drops support for all other versions of GHC. Since I am not really familiar with the Brittany codebase, it was challenging for me to deal with that and CPP at the same time.
These changes mostly work, but I'm having some trouble with spaces. Somehow final newlines went away, and spaces between arguments to constructors are mysteriously missing.
Unfortunately this doesn't really work. And it definitely won't work (for a while) if I upgrade to GHC 9.2.
I need to revert this change.
I'm not sure if this change makes sense.
AnnEofPos
went away.This function returns a "bad" real source span when a "good" one isn't available. Perhaps that messes up sorting somehow? Note that regular source spans can't be compared.
https://hackage.haskell.org/package/ghc-exactprint-1.2.0/docs/Language-Haskell-GHC-ExactPrint-Utils.html#v:rs
https://downloads.haskell.org/~ghc/9.0.1/docs/html/libraries/ghc-9.0.1/GHC-Hs-Type.html#v:hsScaledThing
I initially flagged this because I thought the test failures were for data declarations and thought this might be the cause. However I think this is both unrelated to the test failures and overall harmless.
There are two failing test cases. They're both for type class instances that contain data (or newtype) declarations. The problem is that they're not inserting spaces between constructor arguments.
https://github.com/tfausak/brittany/runs/4111574000?check_suite_focus=true#step:12:661
I think
layoutDataFamInstDecl
is ultimately responsible for this. Removing the call tostripWhitespace
changes the output, but it doesn't fix the constructor arguments.So
layoutDataFamInstDecl
just hands things off tobriDocByExactNoComment
, which seemingly works fine in other contexts. And also there's not a lot of room for things to go wrong there, assuming thatghc-exactprint
is working correctly. I'm going to work on checking that assumption.Perhaps it's possible that this is a GHC bug? I know there are a few gnarly ones in GHC 9.0.1. Unfortunately there's not yet a GHC 9.0.2 to test against.
Well at least
ghc-exactprint
seems to be doing the right thing:It looks like something is going wrong when converting the AST to
BriDoc
. That probably sounds obvious, but I feel it at least narrows things down. This isn't a problem with outputting theBriDoc
, it's a problem with generating theBriDoc
in the first place.Click to see output.
This was implied, but to make it explicit: The latest version of Brittany pretty prints that file without issue.
Click to see raw BriDoc output. It's the same except for the source spans.
Here's an even simpler failing test case:
As it stands on this branch, Brittany removes the space between
C
andD
. Adding some tracing todocExt
suggests that this is indeed a problem withexactPrint
:Hmm, this is puzzling. I wrote a script to parse a module with
ghc-exactprint
and print it back out withexactPrint
. I expected the same output as from Brittany's test suite, but it worked fine.Click to see script.
I thought maybe the annotations were different, but I printed those out too and they looked fine.
Maybe eyeballing the annotations wasn't sufficient 😆
Changing
anns
toaddAnnotationsForPretty [] x anns
fixes this problem but breaks a bunch of other test cases. So it looks like this case is failing because the annotations are wrong for some reason.Dang this just keeps getting more confusing.
Changing
layoutDataFamInstDecl
to useaddAnnotationsForPretty
, either building from the existinganns
or starting frommempty
, does not change the output. That suggests the annotations on theDataFamInstDecl
are fine but some annotations outside of it are problematic? I'm not entirely sure.Here's the difference between the "bad" annotations from this branch and the "good" annotations from the script I posted earlier (https://github.com/lspitzner/brittany/pull/357#issuecomment-962451071):
The
AnnEofPos
is strange. I thought it went away? https://github.com/lspitzner/brittany/pull/357#discussion_r740990692It does live on as a field on
ApiAnns
: https://downloads.haskell.org/~ghc/9.0.1/docs/html/libraries/ghc-9.0.1/GHC-Parser-Annotation.html#v:apiAnnEofPosBut that doesn't explain how it shows up in
ghc-exactprint
's output.I narrowed it down to these lines:
42cf56b106/src/Language/Haskell/Brittany/Internal.hs (L465-L466)
If I comment out the second line, then Brittany correctly prints type families. Unfortunately a bunch of other things break.
Aha!
AnnEofPos
does still exist. It's no longer anAnnKeywordId
defined byghc
. Rather it's aKeywordId
defined byghc-exactprint
. I was confused by the documentation, which doesn't show it as a constructor. However looking at the source reveals it behind CPP.Both #198 and
9236673d66
seem relevant to this problem.These unused comment errors were only showing up in tests for me. If I copy-pasted the test case into a source file and ran the
brittany
executable against it, I got no warnings or errors.I couldn't tell you why this is necessary, but it does in fact solve the problem I was having.
Now that this works for GHC 9.0, I need to decide if it's reasonable to also support GHC 8.10 (and earlier). In other words, can these changes be applied to #356?
I tested this against my work codebase, which was previously formatted with Brittany 0.13.1.2. This branch didn't change anything, which is great! Everything seems to be working as expected.
73 commits later, here’s where this stands:
In short: mission accomplished.
I would merge this PR, but I don’t have admin access to this repo. That means I can’t add secrets, which means I can’t automatically release new versions through GitHub Actions. I have all the set up on my fork, so I will probably continue developing it there. We’ll see how that plays out moving forward.
My next goal is to get Brittany building with GHC 9.2. Unfortunately many dependencies don’t yet build with 9.2, so that’s going to be challenging. Although I haven’t looked too closely yet, I suspect my overall plan will involve trying to reduce the number of dependencies. For example I think
butcher
could be dropped for something likeoptparse-applicative
or evenSystem.Console.GetOpt
.https://github.com/tfausak/brittany/releases/tag/0.14.0.0
Thank you for the work! Supporting a single compiler version looks like the right move, it's a bit sad that maintaining compatibility for multiple GHC API versions is so hard right now.
@tfausak many thanks for your work with this, hls will be able to enable brittany for ghc-9.0.1 thanks to.
Sadly the new hackage version 0.14 mixed two important breaking changes: support for aeson >= 2.0 (only) and ghc == 9.0.1.
Due to that combination we can't jump in hls to aeson 2.0 for ghc < 9.0.1 and we will have to keep compatibility for aeson < 2.0 until we drop support for ghc 8.10, so for a long time (or droping the brittany plugin)
Any chance to release a intermmediate version with support for ghc < 9.0.1 and aeson-2.0? thanks!
I'll have to see what changes I'd need to make to support Aeson 2. From what I remember there wasn't too much to do there.