Skip to content

Commit

Permalink
Support GHC 9.10
Browse files Browse the repository at this point in the history
  • Loading branch information
toku-sa-n committed Sep 3, 2024
1 parent 0d2bd1f commit ef709c7
Show file tree
Hide file tree
Showing 24 changed files with 1,325 additions and 148 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/presubmit-cabal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
# `haskell-actions/setup`.
# See https://github.com/haskell-actions/setup/issues/77.
os: [ubuntu-latest, macos-13, windows-latest]
ghc: [8.10.7, 9.0.2, 9.2.8, 9.4.8, 9.6.4, 9.8.1]
ghc: [8.10.7, 9.0.2, 9.2.8, 9.4.8, 9.6.4, 9.8.1, 9.10.1]
defaults:
run:
# The default shell on Windows is `pwsh`. However, it doesn't expand
Expand Down
4 changes: 3 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.8 ([#775]).
- Support for GHC 9.8 ([#775]) and GHC 9.10([#904]).
- Support for `ImportPostQualified` ([#875]).
- HIndent now formats multiple files in parallel ([#914]).

Expand All @@ -13,6 +13,7 @@
- The formatting style of import declarations with constructors ([#829]).
- HIndent no longer inserts an empty line after a standalone kind signature ([#873]).
- Bumped Stack LTS to 22.26 ([#918]).
- HIndent re-assumes the default extensions are enabled ([#904]).

### Fixed

Expand Down Expand Up @@ -381,6 +382,7 @@ This version is accidentally pushlished, and is the same as 5.3.3.

[#918]: https://github.com/mihaimaruseac/hindent/pull/918
[#914]: https://github.com/mihaimaruseac/hindent/pull/914
[#904]: https://github.com/mihaimaruseac/hindent/pull/904
[#875]: https://github.com/mihaimaruseac/hindent/pull/875
[#873]: https://github.com/mihaimaruseac/hindent/pull/873
[#868]: https://github.com/mihaimaruseac/hindent/pull/868
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ line-length: 80
force-trailing-newline: true
sort-imports: true
line-breaks: []
extensions: []
extensions: [
"GHC2021",
"ListTuplePuns",
]
```

By default, hindent preserves the newline or lack of newline in your input. With `force-trailing-newline`, it will make sure there is always a trailing newline.
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ toCriterion = go
(UTF8.toString desc)
(nf
(either (error . show) id
. reformat HIndent.defaultConfig [] Nothing)
. reformat HIndent.defaultConfig defaultExtensions Nothing)
code)
: go next
else go next
Expand Down
10 changes: 5 additions & 5 deletions hindent.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ library
, directory
, exceptions
, filepath
, ghc-lib-parser >=9.2 && <9.9
, ghc-lib-parser >=9.2 && <9.11
, ghc-lib-parser-ex
, monad-loops
, mtl
Expand Down Expand Up @@ -196,7 +196,7 @@ library hindent-internal
, directory
, exceptions
, filepath
, ghc-lib-parser >=9.2 && <9.9
, ghc-lib-parser >=9.2 && <9.11
, ghc-lib-parser-ex
, monad-loops
, mtl
Expand Down Expand Up @@ -230,7 +230,7 @@ executable hindent
, directory
, exceptions
, filepath
, ghc-lib-parser >=9.2 && <9.9
, ghc-lib-parser >=9.2 && <9.11
, ghc-lib-parser-ex
, hindent
, monad-loops
Expand Down Expand Up @@ -267,7 +267,7 @@ test-suite hindent-test
, directory
, exceptions
, filepath
, ghc-lib-parser >=9.2 && <9.9
, ghc-lib-parser >=9.2 && <9.11
, ghc-lib-parser-ex
, hindent
, hindent-internal
Expand Down Expand Up @@ -307,7 +307,7 @@ benchmark hindent-bench
, directory
, exceptions
, filepath
, ghc-lib-parser >=9.2 && <9.9
, ghc-lib-parser >=9.2 && <9.11
, ghc-lib-parser-ex
, hindent
, hindent-internal
Expand Down
2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dependencies:
- directory
- exceptions
- filepath
- ghc-lib-parser >= 9.2 && < 9.9
- ghc-lib-parser >= 9.2 && < 9.11
- ghc-lib-parser-ex
- monad-loops
- mtl
Expand Down
1 change: 1 addition & 0 deletions src/HIndent.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module HIndent
, getConfig
, -- * Extension
Extension(..)
, defaultExtensions
, -- * Error
ParseError(..)
, prettyParseError
Expand Down
21 changes: 20 additions & 1 deletion src/HIndent/Ast/Declaration/Data/GADT/Constructor/Signature.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,33 @@ prettyVertically Record {..} =
[prettyWith fields (vFields' . fmap pretty), pretty result]

mkConstructorSignature :: GHC.ConDecl GHC.GhcPs -> Maybe ConstructorSignature
#if MIN_VERSION_ghc_lib_parser(9, 10, 1)
mkConstructorSignature GHC.ConDeclGADT {con_g_args = GHC.PrefixConGADT _ xs, ..} =
Just
$ ByArrows
{ parameters =
fmap (fmap mkType . fromGenLocated . GHC.hsScaledThing) xs
, result = mkType <$> fromGenLocated con_res_ty
}
#else
mkConstructorSignature GHC.ConDeclGADT {con_g_args = GHC.PrefixConGADT xs, ..} =
Just
$ ByArrows
{ parameters =
fmap (fmap mkType . fromGenLocated . GHC.hsScaledThing) xs
, result = mkType <$> fromGenLocated con_res_ty
}
#if MIN_VERSION_ghc_lib_parser(9, 4, 0)
#endif
#if MIN_VERSION_ghc_lib_parser(9, 10, 1)
mkConstructorSignature GHC.ConDeclGADT {con_g_args = GHC.RecConGADT _ xs, ..} =
Just
$ Record
{ fields =
fromGenLocated
$ fmap (fmap (fmap mkRecordField . fromGenLocated)) xs
, result = mkType <$> fromGenLocated con_res_ty
}
#elif MIN_VERSION_ghc_lib_parser(9, 4, 0)
mkConstructorSignature GHC.ConDeclGADT {con_g_args = GHC.RecConGADT xs _, ..} =
Just
$ Record
Expand Down
13 changes: 10 additions & 3 deletions src/HIndent/Ast/Declaration/Instance/Family/Data.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE RecordWildCards, CPP #-}

module HIndent.Ast.Declaration.Instance.Family.Data
( DataFamilyInstance
Expand All @@ -15,14 +15,21 @@ import qualified HIndent.GhcLibParserWrapper.GHC.Hs as GHC
import {-# SOURCE #-} HIndent.Pretty
import HIndent.Pretty.Combinators
import HIndent.Pretty.NodeComments

#if MIN_VERSION_ghc_lib_parser(9, 10, 1)
data DataFamilyInstance = DataFamilyInstance
{ newOrData :: NewOrData
, name :: WithComments PrefixName
, types :: GHC.HsFamEqnPats GHC.GhcPs
, body :: DataBody
}
#else
data DataFamilyInstance = DataFamilyInstance
{ newOrData :: NewOrData
, name :: WithComments PrefixName
, types :: GHC.HsTyPats GHC.GhcPs
, body :: DataBody
}

#endif
instance CommentExtraction DataFamilyInstance where
nodeComments DataFamilyInstance {} = NodeComments [] [] []

Expand Down
12 changes: 9 additions & 3 deletions src/HIndent/Ast/Declaration/Instance/Family/Type.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE RecordWildCards, CPP #-}

module HIndent.Ast.Declaration.Instance.Family.Type
( TypeFamilyInstance
Expand All @@ -12,13 +12,19 @@ import qualified HIndent.GhcLibParserWrapper.GHC.Hs as GHC
import {-# SOURCE #-} HIndent.Pretty
import HIndent.Pretty.Combinators
import HIndent.Pretty.NodeComments

#if MIN_VERSION_ghc_lib_parser(9, 10, 1)
data TypeFamilyInstance = TypeFamilyInstance
{ name :: WithComments PrefixName
, types :: GHC.HsFamEqnPats GHC.GhcPs
, bind :: GHC.LHsType GHC.GhcPs
}
#else
data TypeFamilyInstance = TypeFamilyInstance
{ name :: WithComments PrefixName
, types :: GHC.HsTyPats GHC.GhcPs
, bind :: GHC.LHsType GHC.GhcPs
}

#endif
instance CommentExtraction TypeFamilyInstance where
nodeComments TypeFamilyInstance {} = NodeComments [] [] []

Expand Down
9 changes: 8 additions & 1 deletion src/HIndent/Ast/Declaration/Signature.hs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,14 @@ mkSignature (GHC.InlineSig _ n GHC.InlinePragma {..}) = Inline {..}
mkSignature (GHC.SpecSig _ n sigs _) = Specialise {..}
where
name = fromGenLocated $ fmap mkPrefixName n
#if MIN_VERSION_ghc_lib_parser(9, 6, 0)
#if MIN_VERSION_ghc_lib_parser(9, 10, 1)
mkSignature (GHC.SCCFunSig _ n _) = Scc name
where
name = fromGenLocated $ fmap mkPrefixName n
mkSignature (GHC.CompleteMatchSig _ ns _) = Complete names
where
names = mkWithComments $ fmap (fromGenLocated . fmap mkPrefixName) ns
#elif MIN_VERSION_ghc_lib_parser(9, 6, 0)
mkSignature (GHC.SCCFunSig _ n _) = Scc name
where
name = fromGenLocated $ fmap mkPrefixName n
Expand Down
30 changes: 21 additions & 9 deletions src/HIndent/Ast/Declaration/Warning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module HIndent.Ast.Declaration.Warning
) where

import qualified GHC.Types.SourceText as GHC
import qualified GHC.Types.SrcLoc as GHC
import HIndent.Ast.Declaration.Warning.Kind
import HIndent.Ast.Name.Prefix
import HIndent.Ast.NodeComments
Expand All @@ -21,7 +20,7 @@ import HIndent.Pretty.NodeComments
data WarningDeclaration = WarningDeclaration
{ names :: [WithComments PrefixName]
, kind :: Kind
, reasons :: [GHC.Located GHC.StringLiteral]
, reasons :: [WithComments GHC.StringLiteral]
}

instance CommentExtraction WarningDeclaration where
Expand All @@ -36,35 +35,48 @@ instance Pretty WarningDeclaration where
]

mkWarningDeclaration :: GHC.WarnDecl GHC.GhcPs -> WarningDeclaration
#if MIN_VERSION_ghc_lib_parser(9, 8, 1)
#if MIN_VERSION_ghc_lib_parser(9, 10, 1)
mkWarningDeclaration (GHC.Warning _ ns (GHC.DeprecatedTxt _ rs)) =
WarningDeclaration {kind = Deprecated, ..}
where
names = fmap (fromGenLocated . fmap mkPrefixName) ns
reasons = fmap (fmap GHC.hsDocString) rs
reasons = fmap (fromGenLocated . fmap GHC.hsDocString) rs
mkWarningDeclaration (GHC.Warning _ ns (GHC.WarningTxt _ _ rs)) =
WarningDeclaration {kind = Warning, ..}
where
names = fmap (fromGenLocated . fmap mkPrefixName) ns
reasons = fmap (fmap GHC.hsDocString) rs
reasons = fmap (fromGenLocated . fmap GHC.hsDocString) rs
#elif MIN_VERSION_ghc_lib_parser(9, 8, 1)
mkWarningDeclaration (GHC.Warning _ ns (GHC.DeprecatedTxt _ rs)) =
WarningDeclaration {kind = Deprecated, ..}
where
names = fmap (fromGenLocated . fmap mkPrefixName) ns
reasons = fmap (fromGenLocated . fmap GHC.hsDocString) rs
mkWarningDeclaration (GHC.Warning _ ns (GHC.WarningTxt _ _ rs)) =
WarningDeclaration {kind = Warning, ..}
where
names = fmap (fromGenLocated . fmap mkPrefixName) ns
reasons = fmap (fromGenLocated . fmap GHC.hsDocString) rs
#elif MIN_VERSION_ghc_lib_parser(9, 4, 1)
mkWarningDeclaration (GHC.Warning _ ns (GHC.DeprecatedTxt _ rs)) =
WarningDeclaration {kind = Deprecated, ..}
where
names = fmap (fromGenLocated . fmap mkPrefixName) ns
reasons = fmap (fmap GHC.hsDocString) rs
reasons = fmap (fromGenLocated . fmap GHC.hsDocString) rs
mkWarningDeclaration (GHC.Warning _ ns (GHC.WarningTxt _ rs)) =
WarningDeclaration {kind = Warning, ..}
where
names = fmap (fromGenLocated . fmap mkPrefixName) ns
reasons = fmap (fmap GHC.hsDocString) rs
reasons = fmap (fromGenLocated . fmap GHC.hsDocString) rs
#else
mkWarningDeclaration (GHC.Warning _ ns (GHC.DeprecatedTxt _ reasons)) =
mkWarningDeclaration (GHC.Warning _ ns (GHC.DeprecatedTxt _ rs)) =
WarningDeclaration {kind = Deprecated, ..}
where
names = fmap (fromGenLocated . fmap mkPrefixName) ns
mkWarningDeclaration (GHC.Warning _ ns (GHC.WarningTxt _ reasons)) =
reasons = fmap fromGenLocated rs
mkWarningDeclaration (GHC.Warning _ ns (GHC.WarningTxt _ rs)) =
WarningDeclaration {kind = Warning, ..}
where
names = fmap (fromGenLocated . fmap mkPrefixName) ns
reasons = fmap fromGenLocated rs
#endif
8 changes: 8 additions & 0 deletions src/HIndent/Ast/Import/Entry.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,19 @@ instance Pretty ImportEntry where
pretty name >> hFillingTuple (fmap pretty constructors)

mkImportEntry :: GHC.IE GHC.GhcPs -> ImportEntry
#if MIN_VERSION_ghc_lib_parser(9, 10, 1)
mkImportEntry (GHC.IEVar _ name _) = SingleIdentifier name
mkImportEntry (GHC.IEThingAbs _ name _) = SingleIdentifier name
mkImportEntry (GHC.IEThingAll _ name _) = WithAllConstructors name
mkImportEntry (GHC.IEThingWith _ name _ constructors _) =
WithSpecificConstructors {..}
#else
mkImportEntry (GHC.IEVar _ name) = SingleIdentifier name
mkImportEntry (GHC.IEThingAbs _ name) = SingleIdentifier name
mkImportEntry (GHC.IEThingAll _ name) = WithAllConstructors name
mkImportEntry (GHC.IEThingWith _ name _ constructors) =
WithSpecificConstructors {..}
#endif
mkImportEntry _ = undefined

sortVariantsAndExplicitImports ::
Expand Down
8 changes: 8 additions & 0 deletions src/HIndent/Ast/Module/Export/Entry.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,19 @@ instance Pretty ExportEntry where
pretty' (ByModule s) = string "module " >> pretty s

mkExportEntry :: GHC.IE GHC.GhcPs -> ExportEntry
#if MIN_VERSION_ghc_lib_parser(9, 10, 1)
mkExportEntry (GHC.IEVar _ name _) = SingleIdentifier name
mkExportEntry (GHC.IEThingAbs _ name _) = SingleIdentifier name
mkExportEntry (GHC.IEThingAll _ name _) = WithAllConstructors name
mkExportEntry (GHC.IEThingWith _ name _ constructors _) =
WithSpecificConstructors name constructors
#else
mkExportEntry (GHC.IEVar _ name) = SingleIdentifier name
mkExportEntry (GHC.IEThingAbs _ name) = SingleIdentifier name
mkExportEntry (GHC.IEThingAll _ name) = WithAllConstructors name
mkExportEntry (GHC.IEThingWith _ name _ constructors) =
WithSpecificConstructors name constructors
#endif
mkExportEntry (GHC.IEModuleContents _ name) = ByModule name
mkExportEntry GHC.IEGroup {} = neverAppears
mkExportEntry GHC.IEDoc {} = neverAppears
Expand Down
14 changes: 13 additions & 1 deletion src/HIndent/Ast/Module/Warning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ import qualified HIndent.GhcLibParserWrapper.GHC.Unit.Module.Warnings as GHC
import HIndent.Pretty
import HIndent.Pretty.Combinators
import HIndent.Pretty.NodeComments
#if MIN_VERSION_ghc_lib_parser(9, 4, 1)
#if MIN_VERSION_ghc_lib_parser(9, 10, 1)
data ModuleWarning = ModuleWarning
{ messages :: [GHC.LocatedE
(GHC.WithHsDocIdentifiers GHC.StringLiteral GHC.GhcPs)]
, kind :: Kind
}
#elif MIN_VERSION_ghc_lib_parser(9, 4, 1)
data ModuleWarning = ModuleWarning
{ messages :: [GHC.Located
(GHC.WithHsDocIdentifiers GHC.StringLiteral GHC.GhcPs)]
Expand Down Expand Up @@ -54,6 +60,12 @@ fromWarningTxt (GHC.WarningTxt _ messages) = ModuleWarning {..}
where
kind = Warning
#endif
#if MIN_VERSION_ghc_lib_parser(9, 10, 1)
fromWarningTxt (GHC.DeprecatedTxt _ messages) = ModuleWarning {..}
where
kind = Deprecated
#else
fromWarningTxt (GHC.DeprecatedTxt _ messages) = ModuleWarning {..}
where
kind = Deprecated
#endif
9 changes: 7 additions & 2 deletions src/HIndent/Ast/NodeComments.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE RecordWildCards #-}

module HIndent.Ast.NodeComments
Expand Down Expand Up @@ -43,13 +44,15 @@ fromEpAnn' GHC.EpAnn {..} = NodeComments {..}
isCommentOnSameLine (GHC.L comAnn _) =
GHC.srcSpanEndLine (GHC.anchor entry)
== GHC.srcSpanStartLine (GHC.anchor comAnn)
#if !MIN_VERSION_ghc_lib_parser(9, 10, 1)
fromEpAnn' GHC.EpAnnNotUsed = NodeComments [] [] []

#endif
filterOutEofAndPragmasFromAnn :: GHC.EpAnn ann -> GHC.EpAnn ann
filterOutEofAndPragmasFromAnn GHC.EpAnn {..} =
GHC.EpAnn {comments = filterOutEofAndPragmasFromComments comments, ..}
#if !MIN_VERSION_ghc_lib_parser(9, 10, 1)
filterOutEofAndPragmasFromAnn GHC.EpAnnNotUsed = GHC.EpAnnNotUsed

#endif
filterOutEofAndPragmasFromComments :: GHC.EpAnnComments -> GHC.EpAnnComments
filterOutEofAndPragmasFromComments comments =
GHC.EpaCommentsBalanced
Expand All @@ -63,7 +66,9 @@ filterOutEofAndPragmas ::
filterOutEofAndPragmas = filter isNeitherEofNorPragmaComment

isNeitherEofNorPragmaComment :: GHC.GenLocated l GHC.EpaComment -> Bool
#if !MIN_VERSION_ghc_lib_parser(9, 10, 1)
isNeitherEofNorPragmaComment (GHC.L _ (GHC.EpaComment GHC.EpaEofComment _)) =
False
#endif
isNeitherEofNorPragmaComment (GHC.L _ (GHC.EpaComment tok _)) =
not $ isPragma tok
Loading

0 comments on commit ef709c7

Please sign in to comment.