Skip to content

Commit

Permalink
Support GHC 9.6
Browse files Browse the repository at this point in the history
  • Loading branch information
avdv committed Nov 20, 2023
1 parent 3773e14 commit 1e5244e
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 19 deletions.
4 changes: 4 additions & 0 deletions src/GHC/SourceGen/Binds.hs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ funBindsWithFixity fixity name matches = bindB $ withPlaceHolder
WpHole
#endif
)
#if !MIN_VERSION_ghc(9,6,0)
[]
#endif
where
name' = valueRdrName $ unqual name
occ = valueOccName name
Expand Down Expand Up @@ -189,7 +191,9 @@ patBindGRHSs p g =
$ withPlaceHolder
(withPlaceHolder
(withEpAnnNotUsed PatBind (builtPat p) (mkGRHSs g)))
#if !MIN_VERSION_ghc(9,6,0)
$ ([],[])
#endif

-- | Defines a pattern binding without any guards.
--
Expand Down
12 changes: 10 additions & 2 deletions src/GHC/SourceGen/Binds/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import PlaceHolder (PlaceHolder(..))

import GHC.SourceGen.Pat.Internal (parenthesize)
import GHC.SourceGen.Syntax.Internal
import GHC (noExtField, NoExtField (NoExtField))

-- | A binding definition inside of a @let@ or @where@ clause.
--
Expand Down Expand Up @@ -83,12 +84,19 @@ data RawGRHSs = RawGRHSs

matchGroup :: HsMatchContext' -> [RawMatch] -> MatchGroup' LHsExpr'
matchGroup context matches =
noExt MG (mkLocated $ map (mkLocated . mkMatch) matches)
#if MIN_VERSION_ghc(9,6,0)
MG Generated
#else
noExt MG
#endif
matches'
#if !MIN_VERSION_ghc(8,6,0)
[] PlaceHolder
#endif
#elif !MIN_VERSION_ghc(9,6,0)
Generated
#endif
where
matches' = mkLocated $ map (mkLocated . mkMatch) matches
mkMatch :: RawMatch -> Match' LHsExpr'
mkMatch r = withEpAnnNotUsed Match context
(map builtPat $ map parenthesize $ rawMatchPats r)
Expand Down
31 changes: 28 additions & 3 deletions src/GHC/SourceGen/Decl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,27 @@ module GHC.SourceGen.Decl
, patSynBind
) where

#if MIN_VERSION_ghc(9,0,0) && !MIN_VERSION_ghc(9,6,0)
import GHC.Types.SrcLoc (LayoutInfo(..))
#endif
#if MIN_VERSION_ghc(9,0,0)
import GHC (LexicalFixity(Prefix))
import GHC.Data.Bag (listToBag)

#if MIN_VERSION_ghc(9,6,0)
import GHC (GhcPs, LayoutInfo (NoLayoutInfo))
#else
import GHC (GhcPs)
import GHC.Types.SrcLoc (LayoutInfo(..))
#endif

#else
import BasicTypes (LexicalFixity(Prefix))
import Bag (listToBag)
#endif
#if !MIN_VERSION_ghc(8,6,0)
import BasicTypes (DerivStrategy(..))
#endif
import GHC (GhcPs)
import GHC.Hs.Binds
import GHC.Hs.Decls

Expand Down Expand Up @@ -108,6 +117,7 @@ import GHC.SourceGen.Name
import GHC.SourceGen.Name.Internal
import GHC.SourceGen.Syntax.Internal
import GHC.SourceGen.Type.Internal
import GHC.Hs

-- | A definition that can appear in the body of a @class@ declaration.
--
Expand Down Expand Up @@ -174,7 +184,10 @@ class'
class' context name vars decls
= noExt TyClD $ ClassDecl
{ tcdCtxt = toHsContext $ mkLocated $ map mkLocated context
#if MIN_VERSION_ghc(9,2,0)
#if MIN_VERSION_ghc(9,6,0)
, tcdLayout = NoLayoutInfo
, tcdCExt = (EpAnnNotUsed, NoAnnSortKey)
#elif MIN_VERSION_ghc(9,2,0)
, tcdCExt = (EpAnnNotUsed, NoAnnSortKey, NoLayoutInfo)
#elif MIN_VERSION_ghc(9,0,0)
, tcdCExt = NoLayoutInfo
Expand Down Expand Up @@ -323,11 +336,23 @@ newOrDataType newOrData name vars conDecls derivs
withEpAnnNotUsed DataDecl (typeRdrName $ unqual name)
(mkQTyVars vars)
Prefix
$ noExt HsDataDefn newOrData
$ noExt HsDataDefn
#if !MIN_VERSION_ghc(9,6,0)
newOrData
#endif
cxt
Nothing
Nothing
#if MIN_VERSION_ghc(9,6,0)
(case newOrData of
NewType -> case conDecls of
[decl] -> NewTypeCon $ mkLocated decl
_ -> error "NewTypeCon with more than one decl"
DataType -> DataTypeCons False (map mkLocated conDecls)
)
#else
(map mkLocated conDecls)
#endif
#if MIN_VERSION_ghc(9,4,0)
(toHsDeriving $ map mkLocated derivs)
#else
Expand Down
15 changes: 12 additions & 3 deletions src/GHC/SourceGen/Expr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ module GHC.SourceGen.Expr
) where

import GHC.Hs.Expr
import GHC.Hs.Extension (GhcPs)
import GHC.Hs.Extension (GhcPs
#if MIN_VERSION_ghc(9,6,0)
, noHsTok
#endif
)
#if MIN_VERSION_ghc(9,4,0)
import GHC.Hs.Pat (HsFieldBind(..), HsRecFields(..))
#else
Expand Down Expand Up @@ -58,6 +62,7 @@ import GHC.SourceGen.Type.Internal
, sigWcType
, wcType
)
import GHC.Types.SourceText (SourceText(NoSourceText))

-- | An overloaded label, as used with the @OverloadedLabels@ extension.
--
Expand All @@ -67,7 +72,9 @@ import GHC.SourceGen.Type.Internal
overLabel :: String -> HsExpr'
overLabel = hsOverLabel . fromString
where
#if MIN_VERSION_ghc(9,2,0)
#if MIN_VERSION_ghc(9,6,0)
hsOverLabel = withEpAnnNotUsed HsOverLabel NoSourceText
#elif MIN_VERSION_ghc(9,2,0)
hsOverLabel = withEpAnnNotUsed HsOverLabel
#else
hsOverLabel = noExt HsOverLabel Nothing
Expand Down Expand Up @@ -198,7 +205,9 @@ e @::@ t = ExprWithTySig (builtLoc e) (sigWcType t)
-- > =====
-- > var "f" @@ var "Int"
tyApp :: HsExpr' -> HsType' -> HsExpr'
#if MIN_VERSION_ghc(9,2,0)
#if MIN_VERSION_ghc(9,6,0)
tyApp e t = noExt HsAppType e' noHsTok t'
#elif MIN_VERSION_ghc(9,2,0)
tyApp e t = HsAppType builtSpan e' t'
#elif MIN_VERSION_ghc(8,8,0)
tyApp e t = noExt HsAppType e' t'
Expand Down
61 changes: 54 additions & 7 deletions src/GHC/SourceGen/Module.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ module GHC.SourceGen.Module
, moduleContents
) where

import GHC.Hs.ImpExp (LIEWrappedName, IEWildcard(..), IEWrappedName(..), IE(..))
import GHC.Hs.ImpExp
( LIEWrappedName, IEWildcard(..), IEWrappedName(..), IE(..)
#if MIN_VERSION_ghc(9,6,0)
, ImportListInterpretation (EverythingBut, Exactly), XImportDeclPass (ideclSourceText, ideclImplicit)
#endif
)
import GHC.Hs
( HsModule(..)
, ImportDecl(..)
Expand All @@ -35,10 +40,15 @@ import GHC.Hs
#endif
#if MIN_VERSION_ghc(9,2,0)
, EpAnn(..)
#endif
#if MIN_VERSION_ghc(9,6,0)
, hsmodDeprecMessage, hsmodHaddockModHeader, hsmodAnn, AnnKeywordId, XModulePs (XModulePs, hsmodLayout), noAnn, LayoutInfo (NoLayoutInfo), GhcPs, XImportDeclPass (XImportDeclPass, ideclAnn), SrcSpanAnnA, noExtField
#endif
)
#if MIN_VERSION_ghc(9,0,0)
#if MIN_VERSION_ghc(9,0,0) && !MIN_VERSION_ghc(9,6,0)
import GHC.Types.SrcLoc (LayoutInfo(..))
#endif
#if MIN_VERSION_ghc(9,0,0)
import GHC.Unit.Module (IsBootInterface(..))
import GHC.Types.Name.Reader (RdrName)
#else
Expand All @@ -50,8 +60,11 @@ import GHC.Types.PkgQual (RawPkgQual(..))

import GHC.SourceGen.Syntax.Internal
import GHC.SourceGen.Name
( RdrNameStr, ModuleNameStr(unModuleNameStr), OccNameStr, unqual )
import GHC.SourceGen.Name.Internal
import GHC.SourceGen.Lit.Internal (noSourceText)
import GHC.Types.SourceText (SourceText(NoSourceText))
import GHC.Types.SrcLoc (GenLocated)

module'
:: Maybe ModuleNameStr
Expand All @@ -64,13 +77,21 @@ module' name exports imports decls = HsModule
, hsmodExports = fmap (mkLocated . map mkLocated) exports
, hsmodImports = map mkLocated imports
, hsmodDecls = fmap mkLocated decls
#if MIN_VERSION_ghc(9,6,0)
, hsmodExt = XModulePs
{ hsmodAnn = noAnn
, hsmodLayout = NoLayoutInfo
, hsmodDeprecMessage = Nothing
, hsmodHaddockModHeader = Nothing }
#else
, hsmodDeprecMessage = Nothing
, hsmodHaddockModHeader = Nothing
#if MIN_VERSION_ghc(9,0,0)
# if MIN_VERSION_ghc(9,0,0)
, hsmodLayout = NoLayoutInfo
#endif
#if MIN_VERSION_ghc(9,2,0)
# endif
# if MIN_VERSION_ghc(9,2,0)
, hsmodAnn = EpAnnNotUsed
# endif
#endif
}

Expand All @@ -87,7 +108,7 @@ as' :: ImportDecl' -> ModuleNameStr -> ImportDecl'
as' d m = d { ideclAs = Just (mkLocated $ unModuleNameStr m) }

import' :: ModuleNameStr -> ImportDecl'
import' m = noSourceText (withEpAnnNotUsed ImportDecl)
import' m = importDecl
(mkLocated $ unModuleNameStr m)
#if MIN_VERSION_ghc(9,4,0)
NoRawPkgQual
Expand All @@ -105,15 +126,36 @@ import' m = noSourceText (withEpAnnNotUsed ImportDecl)
#else
False
#endif
False Nothing Nothing
#if !MIN_VERSION_ghc(9,6,0)
False
#endif
Nothing Nothing
where
#if MIN_VERSION_ghc(9,6,0)
importDecl = ImportDecl
(XImportDeclPass{ ideclAnn = EpAnnNotUsed
, ideclSourceText = NoSourceText
, ideclImplicit = False
})
#else
importDecl = noSourceText (withEpAnnNotUsed ImportDecl)
#endif

exposing :: ImportDecl' -> [IE'] -> ImportDecl'
exposing d ies = d
#if MIN_VERSION_ghc(9,6,0)
{ ideclImportList = Just (Exactly, mkLocated $ map mkLocated ies) }
#else
{ ideclHiding = Just (False, mkLocated $ map mkLocated ies) }
#endif

hiding :: ImportDecl' -> [IE'] -> ImportDecl'
hiding d ies = d
#if MIN_VERSION_ghc(9,6,0)
{ ideclImportList = Just (EverythingBut, mkLocated $ map mkLocated ies) }
#else
{ ideclHiding = Just (True, mkLocated $ map mkLocated ies) }
#endif

-- | Adds the @{-# SOURCE #-}@ pragma to an import.
source :: ImportDecl' -> ImportDecl'
Expand Down Expand Up @@ -150,8 +192,13 @@ thingWith n cs = withEpAnnNotUsed IEThingWith (wrappedName n) NoIEWildcard

-- TODO: support "mixed" syntax with both ".." and explicit names.

#if MIN_VERSION_ghc(9,6,0)
wrappedName :: RdrNameStr -> GenLocated SrcSpanAnnA (IEWrappedName GhcPs)
wrappedName rNameStr = mkLocated (IEName noExtField $ exportRdrName rNameStr)
#else
wrappedName :: RdrNameStr -> LIEWrappedName RdrName
wrappedName = mkLocated . IEName . exportRdrName
#endif

-- | Exports an entire module.
--
Expand Down
11 changes: 9 additions & 2 deletions src/GHC/SourceGen/Overloaded.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import GHC.Hs.Type
( HsType(..)
, HsTyVarBndr(..)
)
import GHC.Hs (IE(..), IEWrappedName(..))
import GHC.Hs (IE(..), IEWrappedName(..), noExtField)
#if !MIN_VERSION_ghc(8,6,0)
import PlaceHolder(PlaceHolder(..))
#endif
Expand Down Expand Up @@ -286,7 +286,14 @@ instance BVar HsTyVarBndr' where
#endif

instance Var IE' where
var n = noExt IEVar $ mkLocated $ IEName $ exportRdrName n
var n =
noExt IEVar $ mkLocated $
#if MIN_VERSION_ghc(9,6,0)
(IEName noExtField)
#else
IEName
#endif
$ exportRdrName n

instance BVar IE' where
bvar = var . UnqualStr
Expand Down
10 changes: 9 additions & 1 deletion src/GHC/SourceGen/Pat.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ import GHC.SourceGen.Type.Internal (patSigType)
#if MIN_VERSION_ghc(9,2,0)
import GHC.Parser.Annotation (EpAnn(..))
#endif
#if MIN_VERSION_ghc(9,6,0)
import GHC (noHsTok)
#endif

-- | A wild pattern (@_@).
wildP :: Pat'
Expand All @@ -40,7 +43,12 @@ wildP = noExtOrPlaceHolder WildPat
-- > =====
-- > asP "a" (var "B")
asP :: RdrNameStr -> Pat' -> Pat'
v `asP` p = withEpAnnNotUsed AsPat (valueRdrName v) $ builtPat $ parenthesize p
v `asP` p =
withEpAnnNotUsed AsPat (valueRdrName v)
#if MIN_VERSION_ghc(9,6,0)
noHsTok
#endif
(builtPat $ parenthesize p)

-- | A pattern constructor.
--
Expand Down
2 changes: 1 addition & 1 deletion src/GHC/SourceGen/Syntax/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ type HsTyVarBndrS' = HsTyVarBndr GhcPs
#endif

type HsLit' = HsLit GhcPs
#if MIN_VERSION_ghc(9,0,0)
#if MIN_VERSION_ghc(9,0,0) && !MIN_VERSION_ghc(9,6,0)
type HsModule' = HsModule
#else
type HsModule' = HsModule GhcPs
Expand Down

0 comments on commit 1e5244e

Please sign in to comment.