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

Support GHC 9.6 #699

Merged
merged 26 commits into from
Apr 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/presubmit-cabal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
fail-fast: false # don't cancel other jobs if one fails
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
ghc: ["8.10.7", "9.2.5", "9.4.4"]
ghc: ["8.10.7", "9.2.5", "9.4.4", "9.6.1"]
defaults:
run:
# The default shell on Windows is `pwsh`. However, it doesn't expand
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

### Added

- ...
- Support for GHC 9.6 ([#699])

### Changed

Expand Down Expand Up @@ -338,6 +338,7 @@ This version is accidentally pushlished, and is the same as 5.3.3.
[@uhbif19]: https://github.com/uhbif19
[@toku-sa-n]: https://github.com/toku-sa-n

[#699]: https://github.com/mihaimaruseac/hindent/pull/699
[#696]: https://github.com/mihaimaruseac/hindent/pull/696
[#672]: https://github.com/mihaimaruseac/hindent/pull/672
[#671]: https://github.com/mihaimaruseac/hindent/pull/671
Expand Down
73 changes: 39 additions & 34 deletions TESTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,7 @@ Infix constructor pattern

```haskell
-- https://github.com/mihaimaruseac/hindent/issues/424
from $ \(author `InnerJoin` post) -> pure ()
a = from $ \(author `InnerJoin` post) -> pure ()
```

Unboxed sum pattern matching.
Expand Down Expand Up @@ -1634,7 +1634,6 @@ f :: (forall a. Data a => a -> a) -> (forall a b. Data a => a -> b)
g :: forall a b. a -> b
```


An infix operator containing `#`

```haskell
Expand Down Expand Up @@ -1671,7 +1670,7 @@ foo ::

Class constraints should leave `::` on same line

``` haskell
```haskell
-- see https://github.com/chrisdone/hindent/pull/266#issuecomment-244182805
fun ::
(Class a, Class b)
Expand Down Expand Up @@ -2005,7 +2004,7 @@ Type application
```haskell
{-# LANGUAGE TypeApplications #-}

fun @Int 12
a = fun @Int 12
```

An expression with a SCC pragma
Expand Down Expand Up @@ -2327,32 +2326,33 @@ f = Module.Path.mdo
Long line, tuple

```haskell
test
(alphaBetaGamma, deltaEpsilonZeta, etaThetaIota, kappaLambdaMu, nuXiOmicro79)
(alphaBetaGamma, deltaEpsilonZeta, etaThetaIota, kappaLambdaMu, nuXiOmicron80)
( alphaBetaGamma
, deltaEpsilonZeta
, etaThetaIota
, kappaLambdaMu
, nuXiOmicronP81)
a =
test
(alphaBetaGamma, deltaEpsilonZeta, etaThetaIota, kappaLambdaMu, nuXiOmic79)
(alphaBetaGamma, deltaEpsilonZeta, etaThetaIota, kappaLambdaMu, nuXiOmicr80)
( alphaBetaGamma
, deltaEpsilonZeta
, etaThetaIota
, kappaLambdaMu
, nuXiOmicro81)
```

Long line, tuple section

```haskell
test
(, alphaBetaGamma, , deltaEpsilonZeta, , etaThetaIota, kappaLambdaMu, nu79, )
(, alphaBetaGamma, , deltaEpsilonZeta, , etaThetaIota, kappaLambdaMu, , n80, )
(
, alphaBetaGamma
,
, deltaEpsilonZeta
,
, etaThetaIota
, kappaLambdaMu
,
, nu81
,)
a =
test
(, alphaBetaGamma, , deltaEpsilonZeta, , etaThetaIota, kappaLambdaMu, nu79)
(, alphaBetaGamma, , deltaEpsilonZeta, , etaThetaIota, kappaLambdaMu, nuX80)
(
, alphaBetaGamma
,
, deltaEpsilonZeta
,
, etaThetaIota
, kappaLambdaMu
, nuXi81
,)
```

Linebreaks after very short names if the total line length goes over the limit
Expand Down Expand Up @@ -2392,9 +2392,10 @@ f = \ !a -> undefined
An infix operator with a lambda expression

```haskell
for xs $ \x -> do
left x
right x
a =
for xs $ \x -> do
left x
right x
```

Nested lambdas
Expand Down Expand Up @@ -2551,16 +2552,18 @@ x =
With `do`

```haskell
for xs $ do
left x
right x
a =
for xs $ do
left x
right x
```

With lambda-case

```haskell
for xs $ \case
Left x -> x
a =
for xs $ \case
Left x -> x
```

`$` chain
Expand Down Expand Up @@ -2625,7 +2628,8 @@ Force indent and print RHS in a top-level expression

```haskell
-- https://github.com/mihaimaruseac/hindent/issues/473
template $
a =
template $
haskell
[ SomeVeryLongName
, AnotherLongNameEvenLongToBreakTheLine
Expand Down Expand Up @@ -2741,6 +2745,7 @@ f =
[s|foo
|]
```

### Ranges

from
Expand Down
60 changes: 40 additions & 20 deletions hindent.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,16 @@ library
, utf8-string
, yaml
default-language: Haskell2010
if impl(ghc >= 9.4.1)
if impl(ghc >= 9.6.1)
build-depends:
ghc-lib-parser >=9.4.1.20220807 && <9.5
ghc-lib-parser >=9.6.1.20230312 && <9.7
else
build-depends:
ghc-lib-parser >=9.2.3.20220527 && <9.3
if impl(ghc >= 9.4.1)
build-depends:
ghc-lib-parser >=9.4.1.20220807 && <9.5
else
build-depends:
ghc-lib-parser >=9.2.3.20220527 && <9.3

library hindent-internal
exposed-modules:
Expand Down Expand Up @@ -134,12 +138,16 @@ library hindent-internal
, utf8-string
, yaml
default-language: Haskell2010
if impl(ghc >= 9.4.1)
if impl(ghc >= 9.6.1)
build-depends:
ghc-lib-parser >=9.4.1.20220807 && <9.5
ghc-lib-parser >=9.6.1.20230312 && <9.7
else
build-depends:
ghc-lib-parser >=9.2.3.20220527 && <9.3
if impl(ghc >= 9.4.1)
build-depends:
ghc-lib-parser >=9.4.1.20220807 && <9.5
else
build-depends:
ghc-lib-parser >=9.2.3.20220527 && <9.3

executable hindent
main-is: Main.hs
Expand Down Expand Up @@ -174,12 +182,16 @@ executable hindent
, utf8-string
, yaml
default-language: Haskell2010
if impl(ghc >= 9.4.1)
if impl(ghc >= 9.6.1)
build-depends:
ghc-lib-parser >=9.4.1.20220807 && <9.5
ghc-lib-parser >=9.6.1.20230312 && <9.7
else
build-depends:
ghc-lib-parser >=9.2.3.20220527 && <9.3
if impl(ghc >= 9.4.1)
build-depends:
ghc-lib-parser >=9.4.1.20220807 && <9.5
else
build-depends:
ghc-lib-parser >=9.2.3.20220527 && <9.3

test-suite hindent-test
type: exitcode-stdio-1.0
Expand Down Expand Up @@ -217,12 +229,16 @@ test-suite hindent-test
, utf8-string
, yaml
default-language: Haskell2010
if impl(ghc >= 9.4.1)
if impl(ghc >= 9.6.1)
build-depends:
ghc-lib-parser >=9.4.1.20220807 && <9.5
ghc-lib-parser >=9.6.1.20230312 && <9.7
else
build-depends:
ghc-lib-parser >=9.2.3.20220527 && <9.3
if impl(ghc >= 9.4.1)
build-depends:
ghc-lib-parser >=9.4.1.20220807 && <9.5
else
build-depends:
ghc-lib-parser >=9.2.3.20220527 && <9.3

benchmark hindent-bench
type: exitcode-stdio-1.0
Expand Down Expand Up @@ -260,9 +276,13 @@ benchmark hindent-bench
, utf8-string
, yaml
default-language: Haskell2010
if impl(ghc >= 9.4.1)
if impl(ghc >= 9.6.1)
build-depends:
ghc-lib-parser >=9.4.1.20220807 && <9.5
ghc-lib-parser >=9.6.1.20230312 && <9.7
else
build-depends:
ghc-lib-parser >=9.2.3.20220527 && <9.3
if impl(ghc >= 9.4.1)
build-depends:
ghc-lib-parser >=9.4.1.20220807 && <9.5
else
build-depends:
ghc-lib-parser >=9.2.3.20220527 && <9.3
11 changes: 8 additions & 3 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,16 @@ dependencies:
- yaml

when:
- condition: impl(ghc >= 9.4.1)
- condition: impl(ghc >= 9.6.1)
then:
dependencies: ghc-lib-parser >= 9.4.1.20220807 && < 9.5
dependencies: ghc-lib-parser >= 9.6.1.20230312 && < 9.7
else:
dependencies: ghc-lib-parser >= 9.2.3.20220527 && < 9.3
when:
- condition: impl(ghc >= 9.4.1)
then:
dependencies: ghc-lib-parser >= 9.4.1.20220807 && < 9.5
else:
dependencies: ghc-lib-parser >= 9.2.3.20220527 && < 9.3

library:
source-dirs: src
Expand Down
10 changes: 8 additions & 2 deletions src/HIndent.hs
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,12 @@ reformat config mexts mfilepath =
else x' <> "\n")
(f x)
| otherwise = f x

-- | Generate an AST from the given module for debugging.
#if MIN_VERSION_ghc_lib_parser(9,6,1)
testAst :: ByteString -> Either String (HsModule GhcPs)
#else
testAst :: ByteString -> Either String HsModule
#endif
testAst x =
case parseModule Nothing exts (UTF8.toString x) of
POk _ m -> Right $ modifyASTForPrettyPrinting m
Expand All @@ -141,9 +144,12 @@ testAst x =
-- | Does the strict bytestring have a trailing newline?
hasTrailingLine :: ByteString -> Bool
hasTrailingLine xs = not (S8.null xs) && S8.last xs == '\n'

-- | Print the module.
#if MIN_VERSION_ghc_lib_parser(9,6,1)
prettyPrint :: Config -> (HsModule GhcPs) -> Builder
#else
prettyPrint :: Config -> HsModule -> Builder
#endif
prettyPrint config m =
runPrinterStyle config (pretty $ modifyASTForPrettyPrinting m)

Expand Down
Loading