Skip to content

GHC 9 support #86

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

Closed
wants to merge 1 commit into from
Closed
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: 2 additions & 0 deletions compat/GHC/Driver/Monad.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module GHC.Driver.Monad (module GhcMonad) where
import GhcMonad
2 changes: 2 additions & 0 deletions compat/GHC/Driver/Session.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module GHC.Driver.Session (module DynFlags) where
import DynFlags
9 changes: 9 additions & 0 deletions compat/GHC/Hs/Type.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{-# LANGUAGE CPP #-}
module GHC.Hs.Type
#if MIN_VERSION_ghc(8,10,0)
(module GHC.Hs.Types) where
import GHC.Hs.Types
#else
(module HsTypes) where
import HsTypes
#endif
2 changes: 0 additions & 2 deletions compat/GHC/Hs/Types.hs

This file was deleted.

2 changes: 2 additions & 0 deletions compat/GHC/Utils/Outputable.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module GHC.Utils.Outputable (module Outputable) where
import Outputable
2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ description: |

dependencies:
- base >= 4.7 && < 5
- ghc >= 8.4 && < 8.11
- ghc >= 8.4 && < 9.2

default-extensions:
- DataKinds
Expand Down
21 changes: 17 additions & 4 deletions src/GHC/SourceGen/Binds.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
-- license that can be found in the LICENSE file or at
-- https://developers.google.com/open-source/licenses/bsd

{-# LANGUAGE CPP #-}
-- | This module provides combinators for constructing Haskell declarations.
module GHC.SourceGen.Binds
( -- * Bindings
Expand Down Expand Up @@ -44,11 +45,16 @@ module GHC.SourceGen.Binds
, (<--)
) where

import BasicTypes (LexicalFixity(..))
import GHC.Hs.Binds
import GHC.Hs.Expr
import GHC.Hs.Types
import GHC.Hs.Type
#if MIN_VERSION_ghc(9,0,0)
import GHC.Types.Basic (LexicalFixity(..))
import GHC.Tc.Types.Evidence (HsWrapper(WpHole))
#else
import BasicTypes (LexicalFixity(..))
import TcEvidence (HsWrapper(WpHole))
#endif

import GHC.SourceGen.Binds.Internal
import GHC.SourceGen.Name
Expand Down Expand Up @@ -94,7 +100,11 @@ typeSig n = typeSigs [n]
funBinds :: HasValBind t => OccNameStr -> [RawMatch] -> t
funBinds name matches = bindB $ withPlaceHolder
(noExt FunBind name'
(matchGroup context matches) WpHole)
(matchGroup context matches)
#if !MIN_VERSION_ghc(9,0,0)
WpHole
#endif
)
[]
where
name' = valueRdrName $ unqual name
Expand Down Expand Up @@ -265,7 +275,10 @@ stmt e =
-- > =====
-- > bvar "x" <-- var "act"
(<--) :: Pat' -> HsExpr' -> Stmt'
p <-- e = withPlaceHolder $ noExt BindStmt (builtPat p) (builtLoc e) noSyntaxExpr noSyntaxExpr
p <-- e = withPlaceHolder $ noExt BindStmt (builtPat p) (builtLoc e)
#if !MIN_VERSION_ghc(9,0,0)
noSyntaxExpr noSyntaxExpr
#endif
infixl 1 <--

-- | Syntax types which can declare/define pattern bindings.
Expand Down
8 changes: 7 additions & 1 deletion src/GHC/SourceGen/Binds/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@
{-# LANGUAGE CPP #-}
module GHC.SourceGen.Binds.Internal where

#if MIN_VERSION_ghc(9,0,0)
import GHC.Types.Basic (Origin(Generated))
import GHC.Data.Bag (listToBag)
import GHC.Types.SrcLoc (Located)
#else
import BasicTypes (Origin(Generated))
import Bag (listToBag)
import SrcLoc (Located)
#endif
import GHC.Hs.Binds
import GHC.Hs.Decls
import GHC.Hs.Expr (MatchGroup(..), Match(..), GRHSs(..))
import SrcLoc (Located)

#if !MIN_VERSION_ghc(8,6,0)
import PlaceHolder (PlaceHolder(..))
Expand Down
30 changes: 23 additions & 7 deletions src/GHC/SourceGen/Decl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,21 @@ module GHC.SourceGen.Decl
, patSynBind
) where

#if MIN_VERSION_ghc(9,0,0)
import GHC.Types.Basic (LexicalFixity(Prefix))
import GHC.Data.Bag (listToBag)
import GHC.Types.SrcLoc (Located, LayoutInfo(..))
#else
import BasicTypes (LexicalFixity(Prefix))
import Bag (listToBag)
import SrcLoc (Located)
#endif
#if !MIN_VERSION_ghc(8,6,0)
import BasicTypes (DerivStrategy(..))
#endif
import Bag (listToBag)
import GHC.Hs.Binds
import GHC.Hs.Decls
import GHC.Hs.Types
import GHC.Hs.Type
( ConDeclField(..)
, FieldOcc(..)
, HsConDetails(..)
Expand All @@ -63,8 +70,10 @@ import GHC.Hs.Types
#endif
, SrcStrictness(..)
, SrcUnpackedness(..)
#if MIN_VERSION_ghc(9,0,0)
, hsUnrestricted
#endif
)
import SrcLoc (Located)

#if MIN_VERSION_ghc(8,10,0)
import GHC.Hs.Extension (NoExtField(NoExtField))
Expand Down Expand Up @@ -146,7 +155,9 @@ class'
class' context name vars decls
= noExt TyClD $ ClassDecl
{ tcdCtxt = builtLoc $ map builtLoc context
#if MIN_VERSION_ghc(8,10,0)
#if MIN_VERSION_ghc(9,0,0)
, tcdCExt = NoLayoutInfo
#elif MIN_VERSION_ghc(8,10,0)
, tcdCExt = NoExtField
#elif MIN_VERSION_ghc(8,6,0)
, tcdCExt = NoExt
Expand Down Expand Up @@ -298,10 +309,10 @@ data' = newOrDataType DataType
--
-- > Foo a Int
-- > =====
-- > conDecl "Foo" [field (var "a"), field (var "Int")]
-- > prefixCon "Foo" [field (var "a"), field (var "Int")]
prefixCon :: OccNameStr -> [Field] -> ConDecl'
prefixCon name fields = renderCon98Decl name
$ PrefixCon $ map renderField fields
$ PrefixCon $ map (hsUnrestricted . renderField) fields

-- | Declares a Haskell-98-style infix constructor for a data or type
-- declaration.
Expand All @@ -311,7 +322,7 @@ prefixCon name fields = renderCon98Decl name
-- > infixCon (field (var "A" @@ var "b")) ":+:" (field (Var "C" @@ var "d"))
infixCon :: Field -> OccNameStr -> Field -> ConDecl'
infixCon f name f' = renderCon98Decl name
$ InfixCon (renderField f) (renderField f')
$ InfixCon (hsUnrestricted $ renderField f) (hsUnrestricted $ renderField f')

-- | Declares Haskell-98-style record constructor for a data or type
-- declaration.
Expand Down Expand Up @@ -363,6 +374,11 @@ strict f = f { strictness = SrcStrict }
lazy :: Field -> Field
lazy f = f { strictness = SrcLazy }

#if !MIN_VERSION_ghc(9,0,0)
hsUnrestricted :: a -> a
hsUnrestricted = id
#endif

renderField :: Field -> Located HsType'
-- TODO: parenthesizeTypeForApp is an overestimate in the case of
-- rendering an infix or record type.
Expand Down
23 changes: 19 additions & 4 deletions src/GHC/SourceGen/Expr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ module GHC.SourceGen.Expr
import GHC.Hs.Expr
import GHC.Hs.Extension (GhcPs)
import GHC.Hs.Pat (HsRecField'(..), HsRecFields(..))
import GHC.Hs.Types (FieldOcc(..), AmbiguousFieldOcc(..))
import GHC.Hs.Type (FieldOcc(..), AmbiguousFieldOcc(..))
import GHC.Hs.Utils (mkHsIf)
import Data.String (fromString)
#if MIN_VERSION_ghc(9,0,0)
import GHC.Types.SrcLoc (unLoc, GenLocated(..), Located)
#else
import SrcLoc (unLoc, GenLocated(..), Located)
#endif

import GHC.SourceGen.Binds.Internal
import GHC.SourceGen.Binds
Expand Down Expand Up @@ -68,7 +73,7 @@ lambdaCase :: [RawMatch] -> HsExpr'
lambdaCase = noExt HsLamCase . matchGroup CaseAlt

if' :: HsExpr' -> HsExpr' -> HsExpr' -> HsExpr'
if' x y z = noExt HsIf Nothing (builtLoc x) (builtLoc y) (builtLoc z)
if' x y z = mkHsIf (builtLoc x) (builtLoc y) (builtLoc z)

-- | A MultiWayIf expression.
--
Expand All @@ -94,7 +99,12 @@ multiIf = noExtOrPlaceHolder HsMultiIf . map builtLoc
-- > =====
-- > do' [bvar "x" <-- var "act", stmt $ var "return" @@ var "x"]
do' :: [Stmt'] -> HsExpr'
do' = withPlaceHolder . noExt HsDo DoExpr
do' = withPlaceHolder
#if MIN_VERSION_ghc(9,0,0)
. noExt HsDo (DoExpr Nothing)
#else
. noExt HsDo DoExpr
#endif
. builtLoc . map (builtLoc . parenthesizeIfLet)
where
-- Put parentheses around a "let" in a do-binding, to avoid:
Expand All @@ -120,7 +130,12 @@ do' = withPlaceHolder . noExt HsDo DoExpr
-- > ]
listComp :: HsExpr' -> [Stmt'] -> HsExpr'
listComp lastExpr stmts =
let lastStmt = noExt LastStmt (builtLoc lastExpr) False noSyntaxExpr
let lastStmt = noExt LastStmt (builtLoc lastExpr) ret noSyntaxExpr
#if MIN_VERSION_ghc(9,0,0)
ret = Nothing
#else
ret = False
#endif
in withPlaceHolder . noExt HsDo ListComp . builtLoc . map builtLoc $
stmts ++ [lastStmt]

Expand Down
4 changes: 4 additions & 0 deletions src/GHC/SourceGen/Expr/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
module GHC.SourceGen.Expr.Internal where

import GHC.Hs.Expr
#if MIN_VERSION_ghc(9,0,0)
import GHC.Types.SrcLoc (Located, unLoc)
#else
import SrcLoc (Located, unLoc)
#endif

import GHC.SourceGen.Lit.Internal
import GHC.SourceGen.Syntax.Internal
Expand Down
11 changes: 8 additions & 3 deletions src/GHC/SourceGen/Lit.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

-- | This module provides combinators for constructing Haskell literals,
-- which may be used in either patterns or expressions.
{-# LANGUAGE CPP #-}
module GHC.SourceGen.Lit
( HsLit'
, HsOverLit'
Expand All @@ -16,12 +17,16 @@ module GHC.SourceGen.Lit
, frac
) where

import BasicTypes (FractionalLit(..))
import BasicTypes(IntegralLit(..), SourceText(..))
#if MIN_VERSION_ghc(9,0,0)
import GHC.Types.Basic (FractionalLit(..), IntegralLit(..), SourceText(..))
import GHC.Data.FastString (fsLit)
#else
import BasicTypes (FractionalLit(..), IntegralLit(..), SourceText(..))
import FastString (fsLit)
#endif
import GHC.Hs.Lit
import GHC.Hs.Expr (noExpr, noSyntaxExpr, HsExpr(..))
import GHC.Hs.Pat (Pat(..))
import FastString (fsLit)

import GHC.SourceGen.Lit.Internal
import GHC.SourceGen.Syntax.Internal
Expand Down
8 changes: 6 additions & 2 deletions src/GHC/SourceGen/Lit/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
-- license that can be found in the LICENSE file or at
-- https://developers.google.com/open-source/licenses/bsd

{-# LANGUAGE CPP #-}
module GHC.SourceGen.Lit.Internal where

import BasicTypes (SourceText(NoSourceText), FractionalLit(..))
import BasicTypes (IntegralLit(..))
#if MIN_VERSION_ghc(9,0,0)
import GHC.Types.Basic (SourceText(NoSourceText), FractionalLit(..), IntegralLit(..))
#else
import BasicTypes (SourceText(NoSourceText), FractionalLit(..), IntegralLit(..))
#endif
import GHC.Hs.Lit
import GHC.SourceGen.Syntax.Internal

Expand Down
25 changes: 23 additions & 2 deletions src/GHC/SourceGen/Module.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ import GHC.Hs
, ImportDeclQualifiedStyle(..)
#endif
)
#if MIN_VERSION_ghc(9,0,0)
import GHC.Types.SrcLoc (LayoutInfo(..))
import GHC.Unit.Module (IsBootInterface(..))
import GHC.Types.Name.Reader (RdrName)
#else
import RdrName (RdrName)
#endif

import GHC.SourceGen.Syntax.Internal
import GHC.SourceGen.Name
Expand All @@ -54,6 +60,9 @@ module' name exports imports decls = HsModule
, hsmodDecls = fmap builtLoc decls
, hsmodDeprecMessage = Nothing
, hsmodHaddockModHeader = Nothing
#if MIN_VERSION_ghc(9,0,0)
, hsmodLayout = NoLayoutInfo
#endif
}

qualified' :: ImportDecl' -> ImportDecl'
Expand All @@ -71,7 +80,13 @@ as' d m = d { ideclAs = Just (builtLoc $ unModuleNameStr m) }
import' :: ModuleNameStr -> ImportDecl'
import' m = noSourceText (noExt ImportDecl)
(builtLoc $ unModuleNameStr m)
Nothing False False
Nothing
#if MIN_VERSION_ghc(9,0,0)
NotBoot
#else
False
#endif
False
#if MIN_VERSION_ghc(8,10,0)
NotQualified
#else
Expand All @@ -89,7 +104,13 @@ hiding d ies = d

-- | Adds the @{-# SOURCE #-}@ pragma to an import.
source :: ImportDecl' -> ImportDecl'
source d = d { ideclSource = True }
source d = d { ideclSource =
#if MIN_VERSION_ghc(9,0,0)
IsBoot
#else
True
#endif
}

-- | Exports all methods and/or constructors.
--
Expand Down
10 changes: 9 additions & 1 deletion src/GHC/SourceGen/Name.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
--
-- These types are all instances of 'Data.String.IsString'. For ease of use,
-- we recommend enabling the @OverloadedStrings@ extension.
{-# LANGUAGE CPP #-}
module GHC.SourceGen.Name
( -- * RdrNameStr
RdrNameStr(..)
Expand All @@ -27,11 +28,18 @@ module GHC.SourceGen.Name
, moduleNameStrToString
) where

#if MIN_VERSION_ghc(9,0,0)
import GHC.Data.FastString (unpackFS)
import GHC.Unit.Module (moduleNameString)
import GHC.Types.Name.Occurrence (OccName, occNameFS, occNameSpace, isVarNameSpace)
import GHC.Types.Name (Name, nameOccName)
#else
import FastString (unpackFS)
import Module (moduleNameString)
import GHC.SourceGen.Name.Internal
import OccName (OccName, occNameFS, occNameSpace, isVarNameSpace)
import Name (Name, nameOccName)
#endif
import GHC.SourceGen.Name.Internal

unqual :: OccNameStr -> RdrNameStr
unqual = UnqualStr
Expand Down
Loading