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

Add GHC 9.8.1 to the cabal CI #775

Merged
merged 13 commits into from
Nov 12, 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.0.2, 9.2.8, 9.4.7, 9.6.3]
ghc: [8.10.7, 9.0.2, 9.2.8, 9.4.7, 9.6.3, 9.8.1]
defaults:
run:
# The default shell on Windows is `pwsh`. However, it doesn't expand
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Added

- Support for GHC 9.8 ([#775]).

### Changed

### Fixed
Expand Down Expand Up @@ -368,6 +370,7 @@ This version is accidentally pushlished, and is the same as 5.3.3.

[#784]: https://github.com/mihaimaruseac/hindent/pull/784
[#780]: https://github.com/mihaimaruseac/hindent/pull/780
[#775]: https://github.com/mihaimaruseac/hindent/pull/775
[#750]: https://github.com/mihaimaruseac/hindent/pull/750
[#742]: https://github.com/mihaimaruseac/hindent/pull/742
[#741]: https://github.com/mihaimaruseac/hindent/pull/741
Expand Down
10 changes: 5 additions & 5 deletions hindent.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ library
, directory
, exceptions
, filepath
, ghc-lib-parser >=9.2 && <9.7
, ghc-lib-parser >=9.2 && <9.9
, ghc-lib-parser-ex
, monad-loops
, mtl
Expand Down Expand Up @@ -121,7 +121,7 @@ library hindent-internal
, directory
, exceptions
, filepath
, ghc-lib-parser >=9.2 && <9.7
, ghc-lib-parser >=9.2 && <9.9
, ghc-lib-parser-ex
, monad-loops
, mtl
Expand Down Expand Up @@ -154,7 +154,7 @@ executable hindent
, directory
, exceptions
, filepath
, ghc-lib-parser >=9.2 && <9.7
, ghc-lib-parser >=9.2 && <9.9
, ghc-lib-parser-ex
, hindent
, monad-loops
Expand Down Expand Up @@ -190,7 +190,7 @@ test-suite hindent-test
, directory
, exceptions
, filepath
, ghc-lib-parser >=9.2 && <9.7
, ghc-lib-parser >=9.2 && <9.9
, ghc-lib-parser-ex
, hindent
, hindent-internal
Expand Down Expand Up @@ -229,7 +229,7 @@ benchmark hindent-bench
, directory
, exceptions
, filepath
, ghc-lib-parser >=9.2 && <9.7
, ghc-lib-parser >=9.2 && <9.9
, 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 @@ -34,7 +34,7 @@ dependencies:
- directory
- exceptions
- filepath
- ghc-lib-parser >= 9.2 && < 9.7
- ghc-lib-parser >= 9.2 && < 9.9
- ghc-lib-parser-ex
- monad-loops
- mtl
Expand Down
28 changes: 27 additions & 1 deletion src/HIndent/Parse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import HIndent.GhcLibParserWrapper.GHC.Hs
import GHC.Utils.Error
import GHC.Utils.Outputable hiding ((<>), empty, text)
#endif
#if MIN_VERSION_ghc_lib_parser(9,8,1)
import GHC.Unit.Module.Warnings
#endif
-- | This function parses the given Haskell source code with the given file
-- path (if any) and parse options.
parseModule ::
Expand Down Expand Up @@ -49,7 +52,30 @@ lexCode code
-- The 'StarIsType' extension is always enabled to compile a code using
-- kinds like '* -> *'.
parserOptsFromExtensions :: [GLP.Extension] -> ParserOpts
#if MIN_VERSION_ghc_lib_parser(9,4,1)
#if MIN_VERSION_ghc_lib_parser(9,8,1)
parserOptsFromExtensions opts =
mkParserOpts
opts'
diagOpts
[] -- There are no supported languages and extensions (this list is used only in error messages)
False -- Safe imports are off.
False -- Haddock comments are treated as normal comments.
True -- Comments are kept in an AST.
False -- Do not update the internal position of a comment.
where
opts' = ES.fromList $ GLP.StarIsType : opts
diagOpts =
DiagOpts
{ diag_warning_flags = ES.empty
, diag_fatal_warning_flags = ES.empty
, diag_custom_warning_categories = emptyWarningCategorySet
, diag_fatal_custom_warning_categories = emptyWarningCategorySet
, diag_warn_is_error = False
, diag_reverse_errors = False
, diag_max_errors = Nothing
, diag_ppr_ctx = defaultSDocContext
}
#elif MIN_VERSION_ghc_lib_parser(9,4,1)
parserOptsFromExtensions opts =
mkParserOpts
opts'
Expand Down
93 changes: 84 additions & 9 deletions src/HIndent/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,33 @@
vertical = do
pretty name
(space >> pretty fields) <-|> (newline >> indentedBlock (pretty fields))
#if MIN_VERSION_ghc_lib_parser(9,4,1)
#if MIN_VERSION_ghc_lib_parser(9,8,1)
prettyHsExpr (RecordUpd _ name fields) = hor <-|> ver
where
hor = spaced [pretty name, printHorFields fields]
ver = do
pretty name
newline
indentedBlock $ printHorFields fields <-|> printVerFields fields
printHorFields RegularRecUpdFields {..} =
hFields $ fmap (`printCommentsAnd` horField) recUpdFields
printHorFields OverloadedRecUpdFields {..} =
hFields $ fmap (`printCommentsAnd` horField) olRecUpdFields
printVerFields RegularRecUpdFields {..} =
vFields $ fmap printField recUpdFields
printVerFields OverloadedRecUpdFields {..} =
vFields $ fmap printField olRecUpdFields
printField x = printCommentsAnd x $ (<-|>) <$> horField <*> verField
horField HsFieldBind {..} = do
pretty hfbLHS
string " = "
pretty hfbRHS
verField HsFieldBind {..} = do
pretty hfbLHS
string " ="
newline
indentedBlock $ pretty hfbRHS
#elif MIN_VERSION_ghc_lib_parser(9,4,1)
prettyHsExpr (RecordUpd _ name fields) = hor <-|> ver
where
hor = spaced [pretty name, either printHorFields printHorFields fields]
Expand Down Expand Up @@ -1132,7 +1158,7 @@
prettyMatchExpr Match {m_ctxt = LambdaExpr, ..} = do
string "\\"
unless (null m_pats)
$ case unLoc $ head m_pats of

Check warning on line 1161 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (ubuntu-latest, 9.8.1)

In the use of ‘head’

Check warning on line 1161 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (macos-latest, 9.8.1)

In the use of ‘head’

Check warning on line 1161 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (windows-latest, 9.8.1)

In the use of ‘head’
LazyPat {} -> space
BangPat {} -> space
_ -> return ()
Expand Down Expand Up @@ -1168,7 +1194,7 @@
prettyMatchProc Match {m_ctxt = LambdaExpr, ..} = do
string "\\"
unless (null m_pats)
$ case unLoc $ head m_pats of

Check warning on line 1197 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (ubuntu-latest, 9.8.1)

In the use of ‘head’

Check warning on line 1197 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (macos-latest, 9.8.1)

In the use of ‘head’

Check warning on line 1197 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (windows-latest, 9.8.1)

In the use of ‘head’
LazyPat {} -> space
BangPat {} -> space
_ -> return ()
Expand Down Expand Up @@ -1293,7 +1319,11 @@
where
hor = spaced $ fmap pretty [l, r]
ver = pretty $ HsTypeWithVerticalAppTy x
#if MIN_VERSION_ghc_lib_parser(9,8,1)
prettyHsType (HsAppKindTy _ l _ r) = pretty l >> string " @" >> pretty r
#else
prettyHsType (HsAppKindTy _ l r) = pretty l >> string " @" >> pretty r
#endif
prettyHsType (HsFunTy _ _ a b) = (pretty a >> string " -> ") |=> pretty b
prettyHsType (HsListTy _ xs) = brackets $ pretty xs
prettyHsType (HsTupleTy _ HsUnboxedTuple []) = string "(# #)"
Expand Down Expand Up @@ -2011,8 +2041,8 @@
[] -> pure ()
[x'] -> string x'
xs -> do
string $ head xs

Check warning on line 2044 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (ubuntu-latest, 9.8.1)

In the use of ‘head’

Check warning on line 2044 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (macos-latest, 9.8.1)

In the use of ‘head’

Check warning on line 2044 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (windows-latest, 9.8.1)

In the use of ‘head’
indentedWithFixedLevel 0 $ newlinePrefixed $ string <$> tail xs

Check warning on line 2045 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (ubuntu-latest, 9.8.1)

In the use of ‘tail’

Check warning on line 2045 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (macos-latest, 9.8.1)

In the use of ‘tail’

Check warning on line 2045 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (windows-latest, 9.8.1)

In the use of ‘tail’
pretty' (IEModuleContents _ name) = pretty $ fmap ModuleNameWithPrefix name
pretty' IEGroup {} = docNode
pretty' IEDoc {} = docNode
Expand All @@ -2038,15 +2068,25 @@
case famEqnFor of
DataFamInstDeclForTopLevel -> "data instance"
DataFamInstDeclForInsideClassInst -> "data"

-- | HsArg (LHsType GhcPs) (LHsType GhcPs)
#if MIN_VERSION_ghc_lib_parser(9,8,1)
instance Pretty
(HsArg
GhcPs
(GenLocated SrcSpanAnnA (HsType GhcPs))
(GenLocated SrcSpanAnnA (HsType GhcPs))) where
pretty' (HsValArg x) = pretty x
pretty' (HsTypeArg _ x) = string "@" >> pretty x
pretty' HsArgPar {} = notUsedInParsedStage
#else
instance Pretty
(HsArg
(GenLocated SrcSpanAnnA (HsType GhcPs))
(GenLocated SrcSpanAnnA (HsType GhcPs))) where
pretty' (HsValArg x) = pretty x
pretty' (HsTypeArg _ x) = string "@" >> pretty x
pretty' HsArgPar {} = notUsedInParsedStage
#endif
#if MIN_VERSION_ghc_lib_parser(9,4,1)
instance Pretty (HsQuote GhcPs) where
pretty' (ExpBr _ x) = brackets $ wrapWithBars $ pretty x
Expand All @@ -2065,6 +2105,21 @@
instance Pretty (WarnDecls GhcPs) where
pretty' (Warnings _ _ x) = lined $ fmap pretty x
#endif
#if MIN_VERSION_ghc_lib_parser(9,8,1)
instance Pretty (WarnDecl GhcPs) where
pretty' (Warning _ names deprecatedOrWarning) =
case deprecatedOrWarning of
DeprecatedTxt _ reasons -> prettyWithTitleReasons "DEPRECATED" reasons
WarningTxt _ _ reasons -> prettyWithTitleReasons "WARNING" reasons
where
prettyWithTitleReasons title reasons =
lined
[ string $ "{-# " ++ title
, spaced
[hCommaSep $ fmap pretty names, hCommaSep $ fmap pretty reasons]
, string " #-}"
]
#else
instance Pretty (WarnDecl GhcPs) where
pretty' (Warning _ names deprecatedOrWarning) =
case deprecatedOrWarning of
Expand All @@ -2078,6 +2133,7 @@
[hCommaSep $ fmap pretty names, hCommaSep $ fmap pretty reasons]
, string " #-}"
]
#endif
#if MIN_VERSION_ghc_lib_parser(9,4,1)
instance Pretty (WithHsDocIdentifiers StringLiteral GhcPs) where
pretty' WithHsDocIdentifiers {..} = pretty hsDocString
Expand Down Expand Up @@ -2203,19 +2259,28 @@
, string "::"
, pretty fd_sig_ty
]
#if MIN_VERSION_ghc_lib_parser(9,6,1)
#if MIN_VERSION_ghc_lib_parser(9,8,0)
instance Pretty (ForeignImport GhcPs) where
pretty' (CImport (L _ (SourceText s)) conv safety _ _) =
spaced [pretty conv, pretty safety, string s]
spaced [pretty conv, pretty safety, output s]
pretty' (CImport _ conv safety _ _) = spaced [pretty conv, pretty safety]
#elif MIN_VERSION_ghc_lib_parser(9,6,0)
instance Pretty (ForeignImport GhcPs) where
pretty' (CImport (L _ (SourceText s)) conv safety _ _ ) =
spaced [pretty conv, pretty safety, string s]
pretty' (CImport _ conv safety _ _) = spaced [pretty conv, pretty safety]
#else
instance Pretty ForeignImport where
pretty' (CImport conv safety _ _ (L _ (SourceText s))) =
spaced [pretty conv, pretty safety, string s]
pretty' (CImport conv safety _ _ _) = spaced [pretty conv, pretty safety]
#endif

#if MIN_VERSION_ghc_lib_parser(9,6,1)
#if MIN_VERSION_ghc_lib_parser(9,8,0)
instance Pretty (ForeignExport GhcPs) where
pretty' (CExport (L _ (SourceText s)) conv) = spaced [pretty conv, output s]
pretty' (CExport _ conv) = pretty conv
#elif MIN_VERSION_ghc_lib_parser(9,6,0)
instance Pretty (ForeignExport GhcPs) where
pretty' (CExport (L _ (SourceText s)) conv) = spaced [pretty conv, string s]
pretty' (CExport _ conv) = pretty conv
Expand Down Expand Up @@ -2344,11 +2409,15 @@
pretty' (HsIntegral x) = pretty x
pretty' (HsFractional x) = pretty x
pretty' (HsIsString _ x) = string $ unpackFS x

#if MIN_VERSION_ghc_lib_parser(9,8,1)
instance Pretty IntegralLit where
pretty' IL {il_text = SourceText s} = output s
pretty' IL {..} = string $ show il_value
#else
instance Pretty IntegralLit where
pretty' IL {il_text = SourceText s} = string s
pretty' IL {..} = string $ show il_value

#endif
instance Pretty FractionalLit where
pretty' = output

Expand All @@ -2365,7 +2434,7 @@
pretty' (HsFloatPrim _ x) = pretty x >> string "#"
pretty' HsDoublePrim {} = notUsedInParsedStage
pretty' x =
case x of

Check warning on line 2437 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (ubuntu-latest, 8.10.7)

Pattern match(es) are non-exhaustive

Check warning on line 2437 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (macos-latest, 8.10.7)

Pattern match(es) are non-exhaustive

Check warning on line 2437 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (windows-latest, 8.10.7)

Pattern match(es) are non-exhaustive
HsString {} -> prettyString
HsStringPrim {} -> prettyString
where
Expand Down Expand Up @@ -2504,7 +2573,7 @@
string p |=> pretty (fmap StmtLRInsideVerticalList x)
newline
string "]"
stmtsAndPrefixes l = ("| ", head l) : fmap (", ", ) (tail l)

Check warning on line 2576 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (ubuntu-latest, 9.8.1)

In the use of ‘head’

Check warning on line 2576 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (ubuntu-latest, 9.8.1)

In the use of ‘tail’

Check warning on line 2576 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (macos-latest, 9.8.1)

In the use of ‘head’

Check warning on line 2576 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (macos-latest, 9.8.1)

In the use of ‘tail’

Check warning on line 2576 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (windows-latest, 9.8.1)

In the use of ‘head’

Check warning on line 2576 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (windows-latest, 9.8.1)

In the use of ‘tail’

instance Pretty DoExpression where
pretty' DoExpression {..} = do
Expand Down Expand Up @@ -2538,13 +2607,19 @@
pretty' StdCallConv = string "stdcall"
pretty' PrimCallConv = string "prim"
pretty' JavaScriptCallConv = string "javascript"

#if MIN_VERSION_ghc_lib_parser(9,8,1)
instance Pretty ModuleDeprecatedPragma where
pretty' (ModuleDeprecatedPragma (WarningTxt _ _ xs)) =
spaced [string "{-# WARNING", spaced $ fmap pretty xs, string "#-}"]
pretty' (ModuleDeprecatedPragma (DeprecatedTxt _ xs)) =
spaced [string "{-# DEPRECATED", spaced $ fmap pretty xs, string "#-}"]
#else
instance Pretty ModuleDeprecatedPragma where
pretty' (ModuleDeprecatedPragma (WarningTxt _ xs)) =
spaced [string "{-# WARNING", spaced $ fmap pretty xs, string "#-}"]
pretty' (ModuleDeprecatedPragma (DeprecatedTxt _ xs)) =
spaced [string "{-# DEPRECATED", spaced $ fmap pretty xs, string "#-}"]

#endif
instance Pretty HsSrcBang where
pretty' (HsSrcBang _ unpack strictness) = do
pretty unpack
Expand Down
32 changes: 29 additions & 3 deletions src/HIndent/Pretty/NodeComments.hs
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,17 @@ instance CommentExtraction ModuleName where

instance CommentExtraction ModuleNameWithPrefix where
nodeComments ModuleNameWithPrefix {} = emptyNodeComments

#if MIN_VERSION_ghc_lib_parser(9,8,1)
instance CommentExtraction (IE GhcPs) where
nodeComments IEVar {} = emptyNodeComments
nodeComments (IEThingAbs (_, x) _) = nodeComments x
nodeComments (IEThingAll (_, x) _) = nodeComments x
nodeComments (IEThingWith (_, x) _ _ _) = nodeComments x
nodeComments (IEModuleContents (_, x) _) = nodeComments x
nodeComments IEGroup {} = emptyNodeComments
nodeComments IEDoc {} = emptyNodeComments
nodeComments IEDocNamed {} = emptyNodeComments
#else
instance CommentExtraction (IE GhcPs) where
nodeComments IEVar {} = emptyNodeComments
nodeComments (IEThingAbs x _) = nodeComments x
Expand All @@ -630,7 +640,7 @@ instance CommentExtraction (IE GhcPs) where
nodeComments IEGroup {} = emptyNodeComments
nodeComments IEDoc {} = emptyNodeComments
nodeComments IEDocNamed {} = emptyNodeComments

#endif
instance CommentExtraction
(FamEqn GhcPs (GenLocated SrcSpanAnnA (HsType GhcPs))) where
nodeComments FamEqn {..} = nodeComments feqn_ext
Expand All @@ -641,15 +651,25 @@ instance CommentExtraction FamEqn' where
-- | Pretty-print a data instance.
instance CommentExtraction (FamEqn GhcPs (HsDataDefn GhcPs)) where
nodeComments FamEqn {..} = nodeComments feqn_ext

-- | HsArg (LHsType GhcPs) (LHsType GhcPs)
#if MIN_VERSION_ghc_lib_parser(9,8,1)
instance CommentExtraction
(HsArg
GhcPs
(GenLocated SrcSpanAnnA (HsType GhcPs))
(GenLocated SrcSpanAnnA (HsType GhcPs))) where
nodeComments HsValArg {} = emptyNodeComments
nodeComments HsTypeArg {} = emptyNodeComments
nodeComments HsArgPar {} = emptyNodeComments
#else
instance CommentExtraction
(HsArg
(GenLocated SrcSpanAnnA (HsType GhcPs))
(GenLocated SrcSpanAnnA (HsType GhcPs))) where
nodeComments HsValArg {} = emptyNodeComments
nodeComments HsTypeArg {} = emptyNodeComments
nodeComments HsArgPar {} = emptyNodeComments
#endif
#if MIN_VERSION_ghc_lib_parser(9,4,1)
instance CommentExtraction (HsQuote GhcPs) where
nodeComments ExpBr {} = emptyNodeComments
Expand Down Expand Up @@ -967,6 +987,12 @@ instance CommentExtraction (HsUntypedSplice GhcPs) where
nodeComments (HsUntypedSpliceExpr x _) = nodeComments x
nodeComments HsQuasiQuote {} = emptyNodeComments
#endif

#if MIN_VERSION_ghc_lib_parser(9,8,1)
instance CommentExtraction (LHsRecUpdFields GhcPs) where
nodeComments RegularRecUpdFields {} = emptyNodeComments
nodeComments OverloadedRecUpdFields {} = emptyNodeComments
#endif
-- | Marks an AST node as never appearing in the AST.
--
-- Some AST node types are only used in the renaming or type-checking phase.
Expand Down
Loading