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

Update to GHC 9.4 #49

Merged
merged 24 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
0a60f03
Bump `base`, `ghc`, `ghc-exactprint` bounds
9999years Nov 2, 2022
9dcb139
Replace `mappend` with `<>`
9999years Nov 2, 2022
3f76d5e
Update to new GHC API
9999years Nov 2, 2022
07c2d63
Expose a new disheartening set of compile errors
9999years Nov 2, 2022
ad6d071
fix many GHC 9.4 build errors in PatternMap.Instances
wavewave Nov 2, 2022
485ed2c
solved RFMap problem
wavewave Nov 2, 2022
cc45b8d
success in RecordCon case.
wavewave Nov 2, 2022
afbafce
RecordUpd case
wavewave Nov 2, 2022
04949b1
fix mkLet
wavewave Nov 3, 2022
e597bab
fix mkParen' for ghc 9.4
wavewave Nov 3, 2022
3c792c8
Retrie.Expr is now buildable.
wavewave Nov 3, 2022
733d280
Rewrites.Function, Rewrites.Patterns
wavewave Nov 3, 2022
602cbef
Retrie.CPP
wavewave Nov 3, 2022
cc8f9b2
build success!
wavewave Nov 3, 2022
31acebd
fix parentheses bug.
wavewave Nov 3, 2022
6be1b2c
further paren fix
wavewave Nov 3, 2022
aa0000c
fixed record pattern problem. the cases were dropped by accident.
wavewave Nov 3, 2022
42a49f2
ghc 9.2.4 build/test success!
wavewave Nov 3, 2022
e941aa8
replace MIN_VERSION_ghc with __GLASGOW_HASKELL__ to follow this repo …
wavewave Nov 3, 2022
415e5e6
make conditional compilation smaller in PatternMap.Instances.
wavewave Nov 3, 2022
3e5a3ba
revert accidental typo.
wavewave Nov 9, 2022
e4371da
ghc 9.2.1 -> 9.2.4, and add ghc 9.4.2 in CI
wavewave Nov 9, 2022
1e21960
update haskell/actions/setup to v2.0.1, ghc 9.4.2 -> 9.4.1 as supported
wavewave Nov 9, 2022
12223a5
add a note on UndecidableInstances
wavewave Nov 10, 2022
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
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
ghc: ['9.2.1']
ghc: ['9.4.1', '9.2.4']

steps:
- uses: actions/checkout@v2
- uses: haskell/actions/setup@v1
- uses: haskell/actions/setup@v2.0.1
with:
ghc-version: ${{ matrix.ghc }}

Expand Down
17 changes: 17 additions & 0 deletions Retrie/CPP.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
-- This source code is licensed under the MIT license found in the
-- LICENSE file in the root directory of this source tree.
--
{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
module Retrie.CPP
Expand All @@ -26,6 +27,10 @@ import Debug.Trace
import Retrie.ExactPrint
import Retrie.GHC
import Retrie.Replace
#if __GLASGOW_HASKELL__ < 904
#else
import GHC.Types.PkgQual
#endif

-- Note [CPP]
-- We can't just run the pre-processor on files and then rewrite them, because
Expand Down Expand Up @@ -342,8 +347,20 @@ eqImportDecl x y =
&& ((==) `on` ideclQualified) x y
&& ((==) `on` ideclAs) x y
&& ((==) `on` ideclHiding) x y
#if __GLASGOW_HASKELL__ < 904
&& ((==) `on` ideclPkgQual) x y
#else
&& (eqRawPkgQual `on` ideclPkgQual) x y
#endif
&& ((==) `on` ideclSource) x y
&& ((==) `on` ideclSafe) x y
-- intentionally leave out ideclImplicit and ideclSourceSrc
-- former doesn't matter for this check, latter is prone to whitespace issues
#if __GLASGOW_HASKELL__ < 904
#else
where
eqRawPkgQual NoRawPkgQual NoRawPkgQual = True
eqRawPkgQual NoRawPkgQual (RawPkgQual _) = False
eqRawPkgQual (RawPkgQual _) NoRawPkgQual = False
eqRawPkgQual (RawPkgQual s) (RawPkgQual s') = s == s'
#endif
4 changes: 4 additions & 0 deletions Retrie/Context.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ updateContext c i =
-- In left child, prec is 10, so HsApp child will NOT get paren'd
-- In right child, prec is 11, so every child gets paren'd (unless atomic)
updExp (OpApp _ _ op _) = c { ctxtParentPrec = HasPrec $ lookupOp op (ctxtFixityEnv c) }
#if __GLASGOW_HASKELL__ < 904
updExp (HsLet _ lbs _) = addInScope neverParen $ collectLocalBinders CollNoDictBinders lbs
#else
updExp (HsLet _ _ lbs _ _) = addInScope neverParen $ collectLocalBinders CollNoDictBinders lbs
#endif
updExp _ = neverParen

updType :: HsType GhcPs -> Context
Expand Down
14 changes: 9 additions & 5 deletions Retrie/ExactPrint.hs
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,16 @@ swapEntryDPT a b = do
-- Compatibility module with ghc-exactprint

parseContentNoFixity :: Parsers.LibDir -> FilePath -> String -> IO AnnotatedModule
parseContentNoFixity libdir fp str = do
parseContentNoFixity libdir fp str = join $ Parsers.withDynFlags libdir $ \dflags -> do
r <- Parsers.parseModuleFromString libdir fp str
case r of
Left msg -> do
#if __GLASGOW_HASKELL__ < 810
#if __GLASGOW_HASKELL__ < 900
fail $ show msg
#else
#elif __GLASGOW_HASKELL__ < 904
fail $ show $ bagToList msg
#else
fail $ showSDoc dflags $ ppr msg
#endif
Right m -> return $ unsafeMkA (makeDeltaAst m) 0

Expand Down Expand Up @@ -314,10 +316,12 @@ parseHelper :: (ExactPrint a)
=> Parsers.LibDir -> FilePath -> Parsers.Parser a -> String -> IO (Annotated a)
parseHelper libdir fp parser str = join $ Parsers.withDynFlags libdir $ \dflags ->
case parser dflags fp str of
#if __GLASGOW_HASKELL__ < 810
#if __GLASGOW_HASKELL__ < 900
Left (_, msg) -> throwIO $ ErrorCall msg
#else
#elif __GLASGOW_HASKELL__ < 904
Left errBag -> throwIO $ ErrorCall (show $ bagToList errBag)
#else
Left msg -> throwIO $ ErrorCall (showSDoc dflags $ ppr msg)
#endif
Right x -> return $ unsafeMkA (makeDeltaAst x) 0

Expand Down
7 changes: 3 additions & 4 deletions Retrie/ExactPrint/Annotated.hs
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,12 @@ instance Default ast => Default (Annotated ast) where
def = Annotated D.def 0

instance (Data ast, Monoid ast) => Semigroup (Annotated ast) where
(<>) = mappend
a1 <> (Annotated ast2 _) =
runIdentity $ transformA a1 $ \ ast1 ->
mappend ast1 <$> return ast2

instance (Data ast, Monoid ast) => Monoid (Annotated ast) where
mempty = Annotated mempty 0
mappend a1 (Annotated ast2 _) =
runIdentity $ transformA a1 $ \ ast1 ->
mappend ast1 <$> return ast2

-- | Construct an 'Annotated'.
-- This should really only be used in the parsing functions, hence the scary name.
Expand Down
67 changes: 64 additions & 3 deletions Retrie/Expr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module Retrie.Expr
, grhsToExpr
, mkApps
, mkConPatIn
, mkEpAnn
, mkHsAppsTy
, mkLams
, mkLet
Expand Down Expand Up @@ -138,15 +139,21 @@ mkLams vs e = do
mkLet :: Monad m => HsLocalBinds GhcPs -> LHsExpr GhcPs -> TransformT m (LHsExpr GhcPs)
mkLet EmptyLocalBinds{} e = return e
mkLet lbs e = do
#if __GLASGOW_HASKELL__ < 904
an <- mkEpAnn (DifferentLine 1 5)
(AnnsLet {
alLet = EpaDelta (SameLine 0) [],
alIn = EpaDelta (DifferentLine 1 1) []
})
le <- mkLocA (SameLine 1) $ HsLet an lbs e
return le


#else
an <- mkEpAnn (DifferentLine 1 5) NoEpAnns
let tokLet = L (TokenLoc (EpaDelta (SameLine 0) [])) HsTok
tokIn = L (TokenLoc (EpaDelta (DifferentLine 1 1) [])) HsTok
le <- mkLocA (SameLine 1) $ HsLet an tokLet lbs tokIn e
return le
#endif

mkApps :: MonadIO m => LHsExpr GhcPs -> [LHsExpr GhcPs] -> TransformT m (LHsExpr GhcPs)
mkApps e [] = return e
Expand Down Expand Up @@ -261,9 +268,17 @@ patToExpr orig = case dLPat orig of
negE <- maybe (return e) (mkLocA (SameLine 0) . NegApp noAnn e) mbNeg
-- addAllAnnsT llit negE
return negE
#if __GLASGOW_HASKELL__ < 904
go (ParPat an p') = do
p <- patToExpr p'
lift $ mkLocA (SameLine 1) (HsPar an p)
#else
go (ParPat an _ p' _) = do
p <- patToExpr p'
let tokLP = L (TokenLoc (EpaDelta (SameLine 0) [])) HsTok
tokRP = L (TokenLoc (EpaDelta (SameLine 0) [])) HsTok
lift $ mkLocA (SameLine 1) (HsPar an tokLP p tokRP)
#endif
go SigPat{} = error "patToExpr SigPat"
go (TuplePat an ps boxity) = do
es <- forM ps $ \pat -> do
Expand Down Expand Up @@ -311,8 +326,15 @@ precedence _ _ = Nothing
parenify
:: Monad m => Context -> LHsExpr GhcPs -> TransformT m (LHsExpr GhcPs)
parenify Context{..} le@(L _ e)
#if __GLASGOW_HASKELL__ < 904
| needed ctxtParentPrec (precedence ctxtFixityEnv e) && needsParens e =
mkParen' (getEntryDP le) (\an -> HsPar an (setEntryDP le (SameLine 0)))
#else
| needed ctxtParentPrec (precedence ctxtFixityEnv e) && needsParens e = do
let tokLP = L (TokenLoc (EpaDelta (SameLine 0) [])) HsTok
tokRP = L (TokenLoc (EpaDelta (SameLine 0) [])) HsTok
in mkParen' (getEntryDP le) (\an -> HsPar an tokLP (setEntryDP le (SameLine 0)) tokRP)
#endif
| otherwise = return le
where
{- parent -} {- child -}
Expand All @@ -327,7 +349,11 @@ getUnparened = mkT unparen `extT` unparenT `extT` unparenP

-- TODO: what about comments?
unparen :: LHsExpr GhcPs -> LHsExpr GhcPs
#if __GLASGOW_HASKELL__ < 904
unparen (L _ (HsPar _ e)) = e
#else
unparen (L _ (HsPar _ _ e _)) = e
#endif
unparen e = e

-- | hsExprNeedsParens is not always up-to-date, so this allows us to override
Expand All @@ -342,6 +368,7 @@ mkParen k e = do
(e0,pe0) <- swapEntryDPT e pe
return pe0

#if __GLASGOW_HASKELL__ < 904
mkParen' :: (Data x, Monad m, Monoid an)
=> DeltaPos -> (EpAnn AnnParen -> x) -> TransformT m (LocatedAn an x)
mkParen' dp k = do
Expand All @@ -350,6 +377,25 @@ mkParen' dp k = do
let anc = Anchor (realSrcSpan l) (MovedAnchor (SameLine 0))
pe <- mkLocA dp (k (EpAnn anc an emptyComments))
return pe
#else
mkParen' :: (Data x, Monad m, Monoid an)
=> DeltaPos -> (EpAnn NoEpAnns -> x) -> TransformT m (LocatedAn an x)
mkParen' dp k = do
let an = NoEpAnns
l <- uniqueSrcSpanT
let anc = Anchor (realSrcSpan l) (MovedAnchor (SameLine 0))
pe <- mkLocA dp (k (EpAnn anc an emptyComments))
return pe

mkParenTy :: (Data x, Monad m, Monoid an)
=> DeltaPos -> (EpAnn AnnParen -> x) -> TransformT m (LocatedAn an x)
mkParenTy dp k = do
let an = AnnParen AnnParens d0 d0
l <- uniqueSrcSpanT
let anc = Anchor (realSrcSpan l) (MovedAnchor (SameLine 0))
pe <- mkLocA dp (k (EpAnn anc an emptyComments))
return pe
#endif

-- This explicitly operates on 'Located (Pat GhcPs)' instead of 'LPat GhcPs'
-- because it is applied at that type by SYB.
Expand All @@ -361,7 +407,13 @@ parenifyP
parenifyP Context{..} p@(L _ pat)
| IsLhs <- ctxtParentPrec
, needed pat =
#if __GLASGOW_HASKELL__ < 904
mkParen' (getEntryDP p) (\an -> ParPat an (setEntryDP p (SameLine 0)))
#else
let tokLP = L (TokenLoc (EpaDelta (SameLine 0) [])) HsTok
tokRP = L (TokenLoc (EpaDelta (SameLine 0) [])) HsTok
in mkParen' (getEntryDP p) (\an -> ParPat an tokLP (setEntryDP p (SameLine 0)) tokRP)
#endif
| otherwise = return p
where
needed BangPat{} = False
Expand All @@ -384,7 +436,12 @@ parenifyP Context{..} p@(L _ pat)
parenifyT
:: Monad m => Context -> LHsType GhcPs -> TransformT m (LHsType GhcPs)
parenifyT Context{..} lty@(L _ ty)
| needed ty = mkParen' (getEntryDP lty) (\an -> HsParTy an (setEntryDP lty (SameLine 0)))
| needed ty =
#if __GLASGOW_HASKELL__ < 904
mkParen' (getEntryDP lty) (\an -> HsParTy an (setEntryDP lty (SameLine 0)))
#else
mkParenTy (getEntryDP lty) (\an -> HsParTy an (setEntryDP lty (SameLine 0)))
#endif
| otherwise = return lty
where
needed HsAppTy{}
Expand All @@ -397,7 +454,11 @@ unparenT (L _ (HsParTy _ ty)) = ty
unparenT ty = ty

unparenP :: LPat GhcPs -> LPat GhcPs
#if __GLASGOW_HASKELL__ < 904
unparenP (L _ (ParPat _ p)) = p
#else
unparenP (L _ (ParPat _ _ p _)) = p
#endif
unparenP p = p

--------------------------------------------------------------------
Expand Down
6 changes: 2 additions & 4 deletions Retrie/Fixity.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ newtype FixityEnv = FixityEnv

instance Semigroup FixityEnv where
-- | 'mappend' for 'FixityEnv' is right-biased
(<>) = mappend
(FixityEnv e1) <> (FixityEnv e2) = FixityEnv (plusFsEnv e1 e2)

instance Monoid FixityEnv where
mempty = mkFixityEnv []
-- | 'mappend' for 'FixityEnv' is right-biased
mappend (FixityEnv e1) (FixityEnv e2) = FixityEnv (plusFsEnv e1 e2)

lookupOp :: LHsExpr GhcPs -> FixityEnv -> Fixity
lookupOp (L _ e) | Just n <- varRdrName e = lookupOpRdrName n
Expand All @@ -45,7 +43,7 @@ extendFixityEnv l (FixityEnv env) =
FixityEnv $ extendFsEnvList env [ (fs, p) | p@(fs,_) <- l ]

ppFixityEnv :: FixityEnv -> String
ppFixityEnv = unlines . map ppFixity . eltsUFM . unFixityEnv
ppFixityEnv = unlines . map ppFixity . nonDetEltsUFM . unFixityEnv
where
ppFixity (fs, Fixity _ p d) = unwords
[ case d of
Expand Down
4 changes: 4 additions & 0 deletions Retrie/GHC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module Retrie.GHC
, module GHC.Hs.Expr
, module GHC.Parser.Annotation
, module GHC.Parser.Errors.Ppr
, module GHC.Plugins
, module GHC.Types.Basic
, module GHC.Types.Error
, module GHC.Types.Fixity
Expand All @@ -27,6 +28,7 @@ module Retrie.GHC
, module GHC.Types.Unique.FM
, module GHC.Types.Unique.Set
, module GHC.Unit.Module.Name
, module GHC.Utils.Outputable
) where

import GHC
Expand All @@ -39,6 +41,7 @@ import GHC.Hs
import GHC.Hs.Expr
import GHC.Parser.Annotation
import GHC.Parser.Errors.Ppr
import GHC.Plugins (showSDoc)
import GHC.Types.Basic hiding (EP)
import GHC.Types.Error
import GHC.Types.Fixity
Expand All @@ -51,6 +54,7 @@ import GHC.Types.Unique
import GHC.Types.Unique.FM
import GHC.Types.Unique.Set
import GHC.Unit.Module.Name
import GHC.Utils.Outputable (Outputable (ppr))

import Data.Bifunctor (second)
import Data.Maybe
Expand Down
Loading