-
Notifications
You must be signed in to change notification settings - Fork 72
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
Support only GHC 9.0 #357
Support only GHC 9.0 #357
Conversation
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. -- instance-with-data-family-below-method
-- expected
data MyData = Test Int Int
-- actual
data MyData = TestIntInt
-- instance-with-newtype-family-and-deriving
-- expected
newtype Bar () = Baz ()
-- actual
newtype Bar () = Baz() https://github.com/tfausak/brittany/runs/4111574000?check_suite_focus=true#step:12:661 I think |
So 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 $ cat GH357.hs
{-# language TypeFamilies #-}
instance C T where
data X T = X A B C
$ cabal exec -- brittany --exactprint-only GH357.hs
{-# language TypeFamilies #-}
instance C T where
data X T = X A B C
$ cabal exec -- brittany GH357.hs
{-# language TypeFamilies #-}
instance C T where
data X T = XABC |
It looks like something is going wrong when converting the AST to $ cabal exec -- brittany --suppress-output --dump-bridoc-raw GH357.hs Click to see output.---- bridoc raw ----
BDLines []
---- bridoc raw ----
BDLines
[ BDExternal
AnnKey {abstract:RealSrcSpan} (CN "ClsInstD")
fromList
[ AnnKey {abstract:RealSrcSpan} (CN "ClsInstD")
, AnnKey {abstract:RealSrcSpan} (CN "HsTyVar")
, AnnKey {abstract:RealSrcSpan} (CN "Unqual")
, AnnKey {abstract:RealSrcSpan} (CN "HsAppTy")
, AnnKey {abstract:RealSrcSpan} (CN "HsTyVar")
, AnnKey {abstract:RealSrcSpan} (CN "Unqual")
]
False
pack "{-# language TypeFamilies #-}\ninstance C T where"
, BDEnsureIndent
BrIndentRegular
BDIndentLevelPop
BDIndentLevelPushCur
BDLines
[ BDExternal
AnnKey {abstract:RealSrcSpan} (CN "DataFamInstDecl")
fromList
[ AnnKey {abstract:RealSrcSpan} (CN "DataFamInstDecl")
, AnnKey {abstract:RealSrcSpan} (CN "Unqual")
, AnnKey {abstract:RealSrcSpan} (CN "HsTyVar")
, AnnKey {abstract:RealSrcSpan} (CN "Unqual")
, AnnKey {abstract:RealSrcSpan} (CN "Unqual")
, AnnKey {abstract:RealSrcSpan} (CN "ConDeclH98")
, AnnKey {abstract:RealSrcSpan} (CN "HsTyVar")
, AnnKey {abstract:RealSrcSpan} (CN "Unqual")
, AnnKey {abstract:RealSrcSpan} (CN "HsTyVar")
, AnnKey {abstract:RealSrcSpan} (CN "Unqual")
, AnnKey {abstract:RealSrcSpan} (CN "HsTyVar")
, AnnKey {abstract:RealSrcSpan} (CN "Unqual")
, AnnKey {abstract:RealSrcSpan} (CN "False")
, AnnKey {abstract:RealSrcSpan} (CN "[]")
]
False
pack "data X T = XABC"
]
] |
This was implied, but to make it explicit: The latest version of Brittany pretty prints that file without issue. $ brittany --version
brittany version 0.13.1.2
Copyright (C) 2016-2019 Lennart Spitzner
Copyright (C) 2019 PRODA LTD
There is NO WARRANTY, to the extent permitted by law.
$ brittany GH357.hs
{-# language TypeFamilies #-}
instance C T where
data X T = X A B C Click to see raw BriDoc output. It's the same except for the source spans.
|
Here's an even simpler failing test case: data instance A B = C D As it stands on this branch, Brittany removes the space between
|
Hmm, this is puzzling. I wrote a script to parse a module with Click to see script.import qualified GHC.Utils.Error
import qualified GHC.Utils.Outputable
import qualified Language.Haskell.GHC.ExactPrint
import qualified Language.Haskell.GHC.ExactPrint.Utils
main :: IO ()
main = do
parseResult <- Language.Haskell.GHC.ExactPrint.parseModule "TestFakeFileName.hs"
(anns, parsedSource) <- either
( fail
. GHC.Utils.Outputable.showSDocUnsafe
. GHC.Utils.Outputable.sep
. GHC.Utils.Error.pprErrMsgBagWithLoc
)
pure
parseResult
putStrLn ">>> showSDocUnsafe"
putStrLn
. GHC.Utils.Outputable.showSDocUnsafe
$ GHC.Utils.Outputable.ppr parsedSource
putStrLn ">>> showSDocDebug_"
putStrLn
. Language.Haskell.GHC.ExactPrint.Utils.showSDocDebug_
$ GHC.Utils.Outputable.ppr parsedSource
putStrLn ">>> exactPrint"
putStr $ Language.Haskell.GHC.ExactPrint.exactPrint parsedSource anns
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 |
Dang this just keeps getting more confusing. Changing Here's the difference between the "bad" annotations from this branch and the "good" annotations from the script I posted earlier (#357 (comment)): 2a3,11
> ({ TestFakeFileName.hs:1:1 }
> Just (Ann (DP (0,0)) [] [] [(AnnEofPos,DP (1,0))] Nothing Nothing)
> (HsModule
> (VirtualBraces
> (1))
> (Nothing)
> (Nothing)
> []
> [
66c75,77
< []))))))))
---
> []))))))))]
> (Nothing)
> (Nothing))) The It does live on as a field on But that doesn't explain how it shows up in |
I narrowed it down to these lines: brittany/src/Language/Haskell/Brittany/Internal.hs Lines 465 to 466 in 42cf56b
If I comment out the second line, then Brittany correctly prints type families. Unfortunately a bunch of other things break. |
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 |
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. |
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. |
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.