Merge pull request #1 from infinity0/ghc-8.10.1

more GHC 8.10.1 fixes
pull/305/head
Javier Neira 2020-08-06 12:25:36 +02:00 committed by GitHub
commit 168ebd9b28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 121 additions and 15 deletions

View File

@ -61,7 +61,12 @@ import GHC ( Located
) )
import RdrName ( RdrName(..) ) import RdrName ( RdrName(..) )
import SrcLoc ( SrcSpan ) import SrcLoc ( SrcSpan )
#if MIN_VERSION_ghc(8,10,1) /* ghc-8.10.1 */
import GHC.Hs
import Bag
#else
import HsSyn import HsSyn
#endif
import qualified DynFlags as GHC import qualified DynFlags as GHC
import qualified GHC.LanguageExtensions.Type as GHC import qualified GHC.LanguageExtensions.Type as GHC
@ -380,7 +385,11 @@ parsePrintModuleTests conf filename input = do
let inputStr = Text.unpack input let inputStr = Text.unpack input
parseResult <- ExactPrint.Parsers.parseModuleFromString filename inputStr parseResult <- ExactPrint.Parsers.parseModuleFromString filename inputStr
case parseResult of case parseResult of
#if MIN_VERSION_ghc(8,10,1) /* ghc-8.10.1 */
Left err -> return $ Left $ "parsing error: " ++ show (bagToList (show <$> err))
#else
Left (_ , s ) -> return $ Left $ "parsing error: " ++ s Left (_ , s ) -> return $ Left $ "parsing error: " ++ s
#endif
Right (anns, parsedModule) -> runExceptT $ do Right (anns, parsedModule) -> runExceptT $ do
(inlineConf, perItemConf) <- (inlineConf, perItemConf) <-
case extractCommentConfigs anns (getTopLevelDeclNameMap parsedModule) of case extractCommentConfigs anns (getTopLevelDeclNameMap parsedModule) of

View File

@ -36,6 +36,7 @@ import qualified CmdLineParser as GHC
#if MIN_VERSION_ghc(8,10,1) /* ghc-8.10.1 */ #if MIN_VERSION_ghc(8,10,1) /* ghc-8.10.1 */
import GHC.Hs import GHC.Hs
import Bag
#else #else
import HsSyn import HsSyn
#endif #endif
@ -96,7 +97,11 @@ parseModuleWithCpp cpp opts args fp dynCheck =
++ show (warnings <&> warnExtractorCompat) ++ show (warnings <&> warnExtractorCompat)
x <- ExceptT.ExceptT $ liftIO $ dynCheck dflags2 x <- ExceptT.ExceptT $ liftIO $ dynCheck dflags2
res <- lift $ ExactPrint.parseModuleApiAnnsWithCppInternal cpp dflags2 fp res <- lift $ ExactPrint.parseModuleApiAnnsWithCppInternal cpp dflags2 fp
#if MIN_VERSION_ghc(8,10,1) /* ghc-8.10.1 */
either (\err -> ExceptT.throwE $ "transform error: " ++ show (bagToList (show <$> err)))
#else
either (\(span, err) -> ExceptT.throwE $ show span ++ ": " ++ err) either (\(span, err) -> ExceptT.throwE $ show span ++ ": " ++ err)
#endif
(\(a, m) -> pure (a, m, x)) (\(a, m) -> pure (a, m, x))
$ ExactPrint.postParseTransform res opts $ ExactPrint.postParseTransform res opts
@ -129,7 +134,11 @@ parseModuleFromString args fp dynCheck str =
dynCheckRes <- ExceptT.ExceptT $ liftIO $ dynCheck dflags1 dynCheckRes <- ExceptT.ExceptT $ liftIO $ dynCheck dflags1
let res = ExactPrint.parseModuleFromStringInternal dflags1 fp str let res = ExactPrint.parseModuleFromStringInternal dflags1 fp str
case res of case res of
#if MIN_VERSION_ghc(8,10,1) /* ghc-8.10.1 */
Left err -> ExceptT.throwE $ "parse error: " ++ show (bagToList (show <$> err))
#else
Left (span, err) -> ExceptT.throwE $ showOutputable span ++ ": " ++ err Left (span, err) -> ExceptT.throwE $ showOutputable span ++ ": " ++ err
#endif
Right (a , m ) -> pure (a, m, dynCheckRes) Right (a , m ) -> pure (a, m, dynCheckRes)

View File

@ -19,7 +19,11 @@ import Language.Haskell.Brittany.Internal.Config.Types
import RdrName ( RdrName(..) ) import RdrName ( RdrName(..) )
import GHC ( Located, runGhc, GenLocated(L), moduleNameString ) import GHC ( Located, runGhc, GenLocated(L), moduleNameString )
import qualified GHC import qualified GHC
#if MIN_VERSION_ghc(8,10,1) /* ghc-8.10.1 */
import GHC.Hs
#else
import HsSyn import HsSyn
#endif
import Name import Name
import BasicTypes import BasicTypes
import Language.Haskell.GHC.ExactPrint.Types ( mkAnnKey ) import Language.Haskell.GHC.ExactPrint.Types ( mkAnnKey )

View File

@ -37,8 +37,10 @@ import GHC ( runGhc
) )
import SrcLoc ( SrcSpan, noSrcSpan, Located , getLoc, unLoc ) import SrcLoc ( SrcSpan, noSrcSpan, Located , getLoc, unLoc )
import qualified FastString import qualified FastString
import HsSyn #if MIN_VERSION_ghc(8,10,1) /* ghc-8.10.1 */
#if MIN_VERSION_ghc(8,6,0) import GHC.Hs
import GHC.Hs.Extension (NoExtField (..))
#elif MIN_VERSION_ghc(8,6,0)
import HsExtension (NoExt (..)) import HsExtension (NoExt (..))
#endif #endif
import Name import Name
@ -1040,7 +1042,14 @@ layoutClsInst lcid@(L _ cid) = docLines
] ]
where where
layoutInstanceHead :: ToBriDocM BriDocNumbered layoutInstanceHead :: ToBriDocM BriDocNumbered
#if MIN_VERSION_ghc(8,6,0) /* 8.6 */ #if MIN_VERSION_ghc(8,10,1) /* ghc-8.10.1 */
layoutInstanceHead =
briDocByExactNoComment
$ InstD NoExtField
. ClsInstD NoExtField
. removeChildren
<$> lcid
#elif MIN_VERSION_ghc(8,6,0) /* 8.6 */
layoutInstanceHead = layoutInstanceHead =
briDocByExactNoComment briDocByExactNoComment
$ InstD NoExt $ InstD NoExt

View File

@ -19,7 +19,11 @@ import Language.Haskell.Brittany.Internal.Config.Types
import qualified Language.Haskell.GHC.ExactPrint.Types as ExactPrint.Types import qualified Language.Haskell.GHC.ExactPrint.Types as ExactPrint.Types
import GHC ( runGhc, GenLocated(L), SrcSpan, moduleNameString, AnnKeywordId(..), RdrName(..) ) import GHC ( runGhc, GenLocated(L), SrcSpan, moduleNameString, AnnKeywordId(..), RdrName(..) )
#if MIN_VERSION_ghc(8,10,1) /* ghc-8.10.1 */
import GHC.Hs
#else
import HsSyn import HsSyn
#endif
import Name import Name
import qualified FastString import qualified FastString
import BasicTypes import BasicTypes
@ -521,7 +525,12 @@ layoutExpr lexpr@(L _ expr) = do
#else #else
ExplicitTuple args boxity -> do ExplicitTuple args boxity -> do
#endif #endif
#if MIN_VERSION_ghc(8,6,0) /* ghc-8.6 */ #if MIN_VERSION_ghc(8,10,1) /* ghc-8.10.1 */
let argExprs = args <&> \arg -> case arg of
(L _ (Present _ e)) -> (arg, Just e);
(L _ (Missing NoExtField)) -> (arg, Nothing)
(L _ XTupArg{}) -> error "brittany internal error: XTupArg"
#elif MIN_VERSION_ghc(8,6,0) /* ghc-8.6 */
let argExprs = args <&> \arg -> case arg of let argExprs = args <&> \arg -> case arg of
(L _ (Present _ e)) -> (arg, Just e); (L _ (Present _ e)) -> (arg, Just e);
(L _ (Missing NoExt)) -> (arg, Nothing) (L _ (Missing NoExt)) -> (arg, Nothing)
@ -984,10 +993,18 @@ layoutExpr lexpr@(L _ expr) = do
else Just <$> docSharedWrapper layoutExpr rFExpr else Just <$> docSharedWrapper layoutExpr rFExpr
return $ (lfield, lrdrNameToText lnameF, rFExpDoc) return $ (lfield, lrdrNameToText lnameF, rFExpDoc)
recordExpression False indentPolicy lexpr nameDoc rFs recordExpression False indentPolicy lexpr nameDoc rFs
#if MIN_VERSION_ghc(8,10,1) /* ghc-8.10.1 */
HsRecFields [] (Just (L _ 0)) -> do
#else
HsRecFields [] (Just 0) -> do HsRecFields [] (Just 0) -> do
#endif
let t = lrdrNameToText lname let t = lrdrNameToText lname
docWrapNode lname $ docLit $ t <> Text.pack " { .. }" docWrapNode lname $ docLit $ t <> Text.pack " { .. }"
#if MIN_VERSION_ghc(8,10,1) /* ghc-8.10.1 */
HsRecFields fs@(_:_) (Just (L _ dotdoti)) | dotdoti == length fs -> do
#else
HsRecFields fs@(_:_) (Just dotdoti) | dotdoti == length fs -> do HsRecFields fs@(_:_) (Just dotdoti) | dotdoti == length fs -> do
#endif
let nameDoc = docWrapNode lname $ docLit $ lrdrNameToText lname let nameDoc = docWrapNode lname $ docLit $ lrdrNameToText lname
fieldDocs <- fs `forM` \fieldl@(L _ (HsRecField (L _ fieldOcc) fExpr pun)) -> do fieldDocs <- fs `forM` \fieldl@(L _ (HsRecField (L _ fieldOcc) fExpr pun)) -> do
#if MIN_VERSION_ghc(8,6,0) /* ghc-8.6 */ #if MIN_VERSION_ghc(8,6,0) /* ghc-8.6 */
@ -1137,12 +1154,15 @@ layoutExpr lexpr@(L _ expr) = do
HsStatic{} -> do HsStatic{} -> do
-- TODO -- TODO
briDocByExactInlineOnly "HsStatic{}" lexpr briDocByExactInlineOnly "HsStatic{}" lexpr
#if MIN_VERSION_ghc(8,10,1) /* ghc-8.10.1 */
#else
HsArrApp{} -> do HsArrApp{} -> do
-- TODO -- TODO
briDocByExactInlineOnly "HsArrApp{}" lexpr briDocByExactInlineOnly "HsArrApp{}" lexpr
HsArrForm{} -> do HsArrForm{} -> do
-- TODO -- TODO
briDocByExactInlineOnly "HsArrForm{}" lexpr briDocByExactInlineOnly "HsArrForm{}" lexpr
#endif
HsTick{} -> do HsTick{} -> do
-- TODO -- TODO
briDocByExactInlineOnly "HsTick{}" lexpr briDocByExactInlineOnly "HsTick{}" lexpr
@ -1152,6 +1172,8 @@ layoutExpr lexpr@(L _ expr) = do
HsTickPragma{} -> do HsTickPragma{} -> do
-- TODO -- TODO
briDocByExactInlineOnly "HsTickPragma{}" lexpr briDocByExactInlineOnly "HsTickPragma{}" lexpr
#if MIN_VERSION_ghc(8,10,1) /* ghc-8.10.1 */
#else
EWildPat{} -> do EWildPat{} -> do
docLit $ Text.pack "_" docLit $ Text.pack "_"
#if MIN_VERSION_ghc(8,6,0) /* ghc-8.6 */ #if MIN_VERSION_ghc(8,6,0) /* ghc-8.6 */
@ -1169,6 +1191,7 @@ layoutExpr lexpr@(L _ expr) = do
ELazyPat{} -> do ELazyPat{} -> do
-- TODO -- TODO
briDocByExactInlineOnly "ELazyPat{}" lexpr briDocByExactInlineOnly "ELazyPat{}" lexpr
#endif
HsWrap{} -> do HsWrap{} -> do
-- TODO -- TODO
briDocByExactInlineOnly "HsWrap{}" lexpr briDocByExactInlineOnly "HsWrap{}" lexpr

View File

@ -15,7 +15,11 @@ import Language.Haskell.Brittany.Internal.Types
import Language.Haskell.Brittany.Internal.LayouterBasics import Language.Haskell.Brittany.Internal.LayouterBasics
import GHC ( runGhc, GenLocated(L), moduleNameString ) import GHC ( runGhc, GenLocated(L), moduleNameString )
#if MIN_VERSION_ghc(8,10,1) /* ghc-8.10.1 */
import GHC.Hs
#else
import HsSyn import HsSyn
#endif
import Name import Name

View File

@ -18,9 +18,14 @@ import GHC ( unLoc
, AnnKeywordId(..) , AnnKeywordId(..)
, Located , Located
) )
#if MIN_VERSION_ghc(8,10,1) /* ghc-8.10.1 */
import GHC.Hs
import GHC.Hs.ImpExp
#else
import HsSyn import HsSyn
import Name
import HsImpExp import HsImpExp
#endif
import Name
import FieldLabel import FieldLabel
import qualified FastString import qualified FastString
import BasicTypes import BasicTypes

View File

@ -12,7 +12,11 @@ import GHC ( unLoc
, moduleNameString , moduleNameString
, Located , Located
) )
#if MIN_VERSION_ghc(8,10,1) /* ghc-8.10.1 */
import GHC.Hs
#else
import HsSyn import HsSyn
#endif
import Name import Name
import FieldLabel import FieldLabel
import qualified FastString import qualified FastString
@ -59,7 +63,11 @@ layoutImport limportD@(L _ importD) = docWrapNode limportD $ case importD of
hiding = maybe False fst mllies hiding = maybe False fst mllies
minQLength = length "import qualified " minQLength = length "import qualified "
qLengthReal = qLengthReal =
#if MIN_VERSION_ghc(8,10,1) /* ghc-8.10.1 */
let qualifiedPart = if q /= NotQualified then length "qualified " else 0
#else
let qualifiedPart = if q then length "qualified " else 0 let qualifiedPart = if q then length "qualified " else 0
#endif
safePart = if safe then length "safe " else 0 safePart = if safe then length "safe " else 0
pkgPart = maybe 0 ((+ 1) . Text.length) pkgNameT pkgPart = maybe 0 ((+ 1) . Text.length) pkgNameT
srcPart = if src then length "{-# SOURCE #-} " else 0 srcPart = if src then length "{-# SOURCE #-} " else 0
@ -73,7 +81,11 @@ layoutImport limportD@(L _ importD) = docWrapNode limportD $ case importD of
[ appSep $ docLit $ Text.pack "import" [ appSep $ docLit $ Text.pack "import"
, if src then appSep $ docLit $ Text.pack "{-# SOURCE #-}" else docEmpty , if src then appSep $ docLit $ Text.pack "{-# SOURCE #-}" else docEmpty
, if safe then appSep $ docLit $ Text.pack "safe" else docEmpty , if safe then appSep $ docLit $ Text.pack "safe" else docEmpty
#if MIN_VERSION_ghc(8,10,1) /* ghc-8.10.1 */
, if q /= NotQualified then appSep $ docLit $ Text.pack "qualified" else docEmpty
#else
, if q then appSep $ docLit $ Text.pack "qualified" else docEmpty , if q then appSep $ docLit $ Text.pack "qualified" else docEmpty
#endif
, maybe docEmpty (appSep . docLit) pkgNameT , maybe docEmpty (appSep . docLit) pkgNameT
] ]
indentName = indentName =

View File

@ -9,9 +9,14 @@ import Language.Haskell.Brittany.Internal.Layouters.Import
import Language.Haskell.Brittany.Internal.Config.Types import Language.Haskell.Brittany.Internal.Config.Types
import GHC (unLoc, runGhc, GenLocated(L), moduleNameString, AnnKeywordId(..)) import GHC (unLoc, runGhc, GenLocated(L), moduleNameString, AnnKeywordId(..))
#if MIN_VERSION_ghc(8,10,1) /* ghc-8.10.1 */
import GHC.Hs
import GHC.Hs.ImpExp
#else
import HsSyn import HsSyn
import Name
import HsImpExp import HsImpExp
#endif
import Name
import FieldLabel import FieldLabel
import qualified FastString import qualified FastString
import BasicTypes import BasicTypes

View File

@ -21,7 +21,11 @@ import GHC ( Located
, ol_val , ol_val
) )
import qualified GHC import qualified GHC
#if MIN_VERSION_ghc(8,10,1) /* ghc-8.10.1 */
import GHC.Hs
#else
import HsSyn import HsSyn
#endif
import Name import Name
import BasicTypes import BasicTypes
@ -136,14 +140,22 @@ layoutPat (ghcDL -> lpat@(L _ pat)) = docWrapNode lpat $ case pat of
, docSeparator , docSeparator
, docLit $ Text.pack "}" , docLit $ Text.pack "}"
] ]
#if MIN_VERSION_ghc(8,10,1) /* ghc-8.10.1 */
ConPatIn lname (RecCon (HsRecFields [] (Just (L _ 0)))) -> do
#else
ConPatIn lname (RecCon (HsRecFields [] (Just 0))) -> do ConPatIn lname (RecCon (HsRecFields [] (Just 0))) -> do
#endif
-- Abc { .. } -> expr -- Abc { .. } -> expr
let t = lrdrNameToText lname let t = lrdrNameToText lname
Seq.singleton <$> docSeq Seq.singleton <$> docSeq
[ appSep $ docLit t [ appSep $ docLit t
, docLit $ Text.pack "{..}" , docLit $ Text.pack "{..}"
] ]
#if MIN_VERSION_ghc(8,10,1) /* ghc-8.10.1 */
ConPatIn lname (RecCon (HsRecFields fs@(_:_) (Just (L _ dotdoti)))) | dotdoti == length fs -> do
#else
ConPatIn lname (RecCon (HsRecFields fs@(_:_) (Just dotdoti))) | dotdoti == length fs -> do ConPatIn lname (RecCon (HsRecFields fs@(_:_) (Just dotdoti))) | dotdoti == length fs -> do
#endif
-- Abc { a = locA, .. } -- Abc { a = locA, .. }
let t = lrdrNameToText lname let t = lrdrNameToText lname
fds <- fs `forM` \(L _ (HsRecField (L _ fieldOcc) fPat pun)) -> do fds <- fs `forM` \(L _ (HsRecField (L _ fieldOcc) fPat pun)) -> do

View File

@ -17,7 +17,11 @@ import GHC ( runGhc
, GenLocated(L) , GenLocated(L)
, moduleNameString , moduleNameString
) )
#if MIN_VERSION_ghc(8,10,1) /* ghc-8.10.1 */
import GHC.Hs
#else
import HsSyn import HsSyn
#endif
import Name import Name
import qualified FastString import qualified FastString
import BasicTypes import BasicTypes

View File

@ -13,7 +13,11 @@ import Language.Haskell.Brittany.Internal.Types
import Language.Haskell.Brittany.Internal.LayouterBasics import Language.Haskell.Brittany.Internal.LayouterBasics
import GHC ( runGhc, GenLocated(L), moduleNameString ) import GHC ( runGhc, GenLocated(L), moduleNameString )
#if MIN_VERSION_ghc(8,10,1) /* ghc-8.10.1 */
import GHC.Hs
#else
import HsSyn import HsSyn
#endif
import Name import Name
import qualified FastString import qualified FastString
import BasicTypes import BasicTypes

View File

@ -25,7 +25,11 @@ import GHC ( runGhc
, AnnKeywordId (..) , AnnKeywordId (..)
) )
import Language.Haskell.GHC.ExactPrint.Types ( mkAnnKey ) import Language.Haskell.GHC.ExactPrint.Types ( mkAnnKey )
#if MIN_VERSION_ghc(8,10,1) /* ghc-8.10.1 */
import GHC.Hs
#else
import HsSyn import HsSyn
#endif
import Name import Name
import Outputable ( ftext, showSDocUnsafe ) import Outputable ( ftext, showSDocUnsafe )
import BasicTypes import BasicTypes
@ -61,7 +65,9 @@ layoutType ltype@(L _ typ) = docWrapNode ltype $ case typ of
t <- lrdrNameToTextAnnTypeEqualityIsSpecial name t <- lrdrNameToTextAnnTypeEqualityIsSpecial name
docWrapNode name $ docLit t docWrapNode name $ docLit t
#endif #endif
#if MIN_VERSION_ghc(8,6,0) #if MIN_VERSION_ghc(8,10,1)
HsForAllTy _ _ bndrs (L _ (HsQualTy _ (L _ cntxts) typ2)) -> do
#elif MIN_VERSION_ghc(8,6,0)
HsForAllTy _ bndrs (L _ (HsQualTy _ (L _ cntxts) typ2)) -> do HsForAllTy _ bndrs (L _ (HsQualTy _ (L _ cntxts) typ2)) -> do
#else #else
HsForAllTy bndrs (L _ (HsQualTy (L _ cntxts) typ2)) -> do HsForAllTy bndrs (L _ (HsQualTy (L _ cntxts) typ2)) -> do
@ -151,7 +157,9 @@ layoutType ltype@(L _ typ) = docWrapNode ltype $ case typ of
] ]
) )
] ]
#if MIN_VERSION_ghc(8,6,0) #if MIN_VERSION_ghc(8,10,1)
HsForAllTy _ _ bndrs typ2 -> do
#elif MIN_VERSION_ghc(8,6,0)
HsForAllTy _ bndrs typ2 -> do HsForAllTy _ bndrs typ2 -> do
#else #else
HsForAllTy bndrs typ2 -> do HsForAllTy bndrs typ2 -> do

View File

@ -304,15 +304,13 @@ lines' s = case break (== '\n') s of
(s1, (_:r)) -> s1 : lines' r (s1, (_:r)) -> s1 : lines' r
#if MIN_VERSION_ghc(8,10,1) /* ghc-8.10.1 */ #if MIN_VERSION_ghc(8,10,1) /* ghc-8.10.1 */
absurdExt :: HsExtension.NoExtField -> a absurdExt :: HsExtension.NoExtCon -> a
absurdExt = error "cannot construct NoExtField" absurdExt = HsExtension.noExtCon
#else #elif MIN_VERSION_ghc(8,6,0) /* ghc-8.6 */
#if MIN_VERSION_ghc(8,6,0) /* ghc-8.6 */
-- | A method to dismiss NoExt patterns for total matches -- | A method to dismiss NoExt patterns for total matches
absurdExt :: HsExtension.NoExt -> a absurdExt :: HsExtension.NoExt -> a
absurdExt = error "cannot construct NoExt" absurdExt = error "cannot construct NoExt"
#else #else
absurdExt :: () absurdExt :: ()
absurdExt = () absurdExt = ()
#endif /* ghc-8.6 */ #endif
#endif /* ghc-8.10.1 */