Compare commits

..

45 Commits

Author SHA1 Message Date
Lennart Spitzner 3f9e9d9bcb Respect and Fix disable-next-binding/decl 2023-05-02 12:12:54 +00:00
Lennart Spitzner 414baca643 Hardcode more precedences 2023-05-02 09:56:39 +00:00
Lennart Spitzner 884c7da97c Allow special layout for HsApp with HsDo/HsSpiceE args 2023-05-02 09:56:39 +00:00
Lennart Spitzner ab67a794db Fix retaining newlines between do statements 2023-05-02 09:56:39 +00:00
Lennart Spitzner b6001e9ecc Bump version to 92.1.0.0
The 92 indicates that this version is based on ghc-9.2.*.
Given that we support a single GHC version at a time
(and avoid any CPP mess) I thought this might be appropriate.
This also allows bug-fix releases to different "branches",
i.e. publishing 92.x.x.(n+1) together with 94.y.y.(n+1) to
address some bug that affects both the ghc-9.2.* branch
and the ghc-9.4 branch. From a PVP perspective it might not
be ideal that we regularly bump major versions when the
API does not actually change much, if at all, but given that
brittany primarily is an executable and will probably have
a small set of reverse-dependencies this seems acceptable.
2023-05-02 09:56:39 +00:00
Phil Hazelden 52bde7910f Support promoted type applications.
Closes #370.

Up to GHC 8.10,

    foo @ 'Bar

was a valid type application. In GHC 9 it's not, which means brittany
needs to allow

    foo @'Bar

which it now does.

The reason the space was needed was to allow a promoted type variable at
the head of a type-level list. That is,

    '['Foo]

is invalid syntax, because it initially parses as the character `'['`.
So the promoted type variable was always given a separator at the
beginning, and we'd get

    '[ 'Foo]

which was valid. Now we handle this case by specifically examining the
head of a type-level list; if it's promoted we introduce spaces, so

    '[ 'Foo ]
    '[Foo]

I've added tests for this and some related cases. In doing so I noticed
that unnecessary spaces get added in front of commas in these lists; I
believe that's a separate bug, and I've written a comment explaining why
it happens, but I haven't tried to fix it.

I'm not sure when the first alternates in the `FirstLastSingleton`
and `FirstLast` branches would ever be hit, so I'm not entirely sure if
the separators are necessary there. But since `docSeparator` disappears
at the end of a line and merges with adjacent separators, they should be
harmless.
2023-05-02 09:56:39 +00:00
Lennart Spitzner e11188eb16 Respect newlines after block-comments 2023-05-02 09:56:39 +00:00
Lennart Spitzner 556bc896a6 Refactor WriteBriDoc FlushCommentsPrior code slightly 2023-05-02 09:56:39 +00:00
Lennart Spitzner d2a48ba559 Fixup misspelled data-type name 2023-05-02 09:56:39 +00:00
Lennart Spitzner 7ab6a207ae Update OpApp layouting options
- Allow par-spacing for single-operator 1+n-line layout
- Tweak when to flatten operators, i.e. when to allow a flat one-line-each
  layout for the operator sequence "$ $ $ + +".
2023-05-02 09:16:44 +00:00
Lennart Spitzner 99e5aacb5e Discard special case for non-nested OpApp 2023-05-02 09:16:04 +00:00
Lennart Spitzner 52e4658314 Minor comment updates and cleanup 2023-05-02 09:16:04 +00:00
Lennart Spitzner 56e7d6b5b9 Simplify/Optimize Decl:layoutPatternBindFinal 2023-05-02 09:16:04 +00:00
Lennart Spitzner 156b5cf407 setParSpacing for operator-expression ending in par 2023-05-02 09:16:04 +00:00
Lennart Spitzner d29303d4cd Improve one HsLet layout
- Allow parSpacing for single-clause layout
- Allow par/sl layout when no where-clause was present
  (not sure why this was disabled in the first place)
2023-05-02 09:16:04 +00:00
Lennart Spitzner 5563cd4d93 Dont flatten operators without surrounding parens 2023-05-02 09:16:04 +00:00
Lennart Spitzner 09ec59eaf9 Fix comment-after-context 2023-05-02 09:16:04 +00:00
Lennart Spitzner b24379d104 Fix restore-position after block comment 2023-05-02 09:16:04 +00:00
Lennart Spitzner 2fef44559e Fix comments moving after "where" 2023-05-02 09:16:04 +00:00
Lennart Spitzner ebe85a5949 Use dependency-injection for ToBriDoc modules
I assume this makes inlining impossible, but it enables
parallel compilation of all these modules. In my tests
this reduce wall clock time to 92%, and with more cores
the benefit should be higher.
2023-05-02 09:16:04 +00:00
Lennart Spitzner 736c2a8d46 Fix retain comments on matches (lambda rhs etc.) 2023-05-02 09:16:04 +00:00
Lennart Spitzner 0a76fe952c Refactor s/rec/go for extension compat 2023-05-02 09:16:03 +00:00
Lennart Spitzner dc4e59f2a1 Fix BDLines getSpacing computation 2023-05-02 09:16:03 +00:00
Lennart Spitzner 412c5460aa Do not count warnings for considering exactprint fallback 2023-05-02 09:16:03 +00:00
Lennart Spitzner dd4367c6e8 Fixup annotation on error-fallback 2023-05-02 09:16:03 +00:00
Lennart Spitzner 676695a609 Implement fixity-aware-ops feature 2023-05-02 09:16:03 +00:00
Lennart Spitzner 75d17b961c Fix double-printing of comments on certain data-decls 2023-05-02 09:16:03 +00:00
Lennart Spitzner f13a82964a Partially restore retaining-empty-lines behaviour
Currently works for do blocks, multi-line list literals, and
lambda-case cases (apart from top-level blank lines that
never got ignored).
2023-05-02 09:16:03 +00:00
Lennart Spitzner 05270ecb45 Improve block-comment behaviour (newlines after or not) 2023-05-02 09:16:03 +00:00
Lennart Spitzner 7c329d391b Make if-then-layout layout more consistent 2023-05-02 09:16:03 +00:00
Lennart Spitzner 5bee3fa93d Fix missing comment for MG 2023-05-02 09:16:03 +00:00
Lennart Spitzner 83b13d61a0 Change behaviour: Less par-spacing for function application 2023-05-02 09:16:03 +00:00
Lennart Spitzner 3121ccacfe Behaviour addition: Allow par-spacing on HsApp 2023-05-02 09:16:03 +00:00
Lennart Spitzner d9373ec80e Implement extension support - OverloadedRecordDot 2023-05-02 09:16:03 +00:00
Lennart Spitzner 72c9e4c3ab Fix block-comment delta position special case 2023-05-02 09:16:03 +00:00
Lennart Spitzner b116529005 Replace BriDoc+BriDocF with single BriDocW + type family 2023-05-02 09:16:03 +00:00
Lennart Spitzner ee2814e3a8 Reintroduce BDAnnotationKW in the form of BDEntryDelta 2023-05-02 09:16:03 +00:00
Lennart Spitzner 7d3490b80a Clean up WriteBriDoc monad state handling 2023-05-02 09:16:03 +00:00
Lennart Spitzner 847e01cc30 Clean up unused WriteBriDoc operators 2023-05-02 09:16:03 +00:00
Lennart Spitzner d11141d34d Refactor+Rewrite+Adaptation for ghc-9.2 support 2023-05-02 09:16:03 +00:00
Lennart Spitzner dedeab61e2 Ignore missing kind signatures and unused imports for now 2023-05-02 09:16:03 +00:00
Lennart Spitzner 84669034b5 Unhide warning 2023-05-02 09:16:03 +00:00
Lennart Spitzner 7f4730858e Pass ghc -fhide-source-paths by default 2023-05-02 09:16:03 +00:00
Lennart Spitzner bff9bfb312 Support and use nested file structure for tests 2023-05-02 09:16:03 +00:00
Lennart Spitzner 4e397441b9 Revert "Split tests into individual files"
This reverts commit 21e86adf6e.
2023-05-02 09:16:00 +00:00
2 changed files with 10 additions and 7 deletions

View File

@ -22,7 +22,6 @@ import GHC.Parser.Annotation ( EpaCommentTok
) )
) )
import qualified UI.Butcher.Monadic as Butcher import qualified UI.Butcher.Monadic as Butcher
-- import qualified Language.Haskell.GHC.ExactPrint.Utils as ExactPrint.Utils
import Control.Monad.Trans.Except import Control.Monad.Trans.Except
import Language.Haskell.Brittany.Internal.Config.Config import Language.Haskell.Brittany.Internal.Config.Config
@ -31,6 +30,8 @@ import Language.Haskell.Brittany.Internal.Util.AST
import Language.Haskell.Brittany.Internal.Config.Types.Instances1 () import Language.Haskell.Brittany.Internal.Config.Types.Instances1 ()
import Language.Haskell.Brittany.Internal.Config.Types.Instances2 () import Language.Haskell.Brittany.Internal.Config.Types.Instances2 ()
-- import Language.Haskell.Brittany.Internal.Utils -- import Language.Haskell.Brittany.Internal.Utils
-- import qualified Language.Haskell.GHC.ExactPrint.Utils as ExactPrint.Utils
-- import Data.Data(toConstr)
@ -39,6 +40,7 @@ data InlineConfigTarget
| InlineConfigTargetNextDecl -- really only next in module | InlineConfigTargetNextDecl -- really only next in module
| InlineConfigTargetNextBinding -- by name | InlineConfigTargetNextBinding -- by name
| InlineConfigTargetBinding String | InlineConfigTargetBinding String
deriving Show
extractCommentConfigs extractCommentConfigs
:: (String -> IO ()) :: (String -> IO ())
@ -116,13 +118,13 @@ extractCommentConfigs _putErrorLn modul = do
] ]
let perSpan = Map.fromListWith let perSpan = Map.fromListWith
(<>) (<>)
[ (srcSpan, conf) [ (declSpan, conf)
| (srcSpan, target, conf) <- lineConfigs | (srcSpan, target, conf) <- lineConfigs
, let perBindRes = Map.lookupGT srcSpan declMap , Just (declSpan, names) <- [Map.lookupGT srcSpan declMap]
, case target of , case target of
InlineConfigTargetNextDecl -> True InlineConfigTargetNextDecl -> True
InlineConfigTargetNextBinding | Nothing <- perBindRes -> True InlineConfigTargetNextBinding -> null names
_ -> False _ -> False
] ]
pure pure

View File

@ -218,7 +218,8 @@ ppToplevelDecl decl immediateAfterComms = do
declConfig & _conf_roundtrip_exactprint_only & confUnpack declConfig & _conf_roundtrip_exactprint_only & confUnpack
bd <- fmap fst $ if exactprintOnly bd <- fmap fst $ if exactprintOnly
then briDocMToPPM layouters then briDocMToPPM layouters
$ docSeq (briDocByExact decl : map commentToDoc immediateAfterComms) $ docSeq
(briDocByExactNoComment decl : map commentToDoc immediateAfterComms)
else do else do
let innerDoc = case decl of let innerDoc = case decl of
L (SrcSpanAnn _ (GHC.RealSrcSpan s _)) _ -> L (SrcSpanAnn _ (GHC.RealSrcSpan s _)) _ ->