ghc-source-gen 0.4.1.0 → 0.4.2.0
raw patch · 39 files changed
+337/−68 lines, 39 filesdep ~ghcdep ~tastyPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: ghc, tasty
API changes (from Hackage documentation)
- GHC.SourceGen.Type: forall' :: [HsTyVarBndr'] -> HsType' -> HsType'
+ GHC.SourceGen.Type: forall' :: [HsTyVarBndrS'] -> HsType' -> HsType'
Files
- ChangeLog.md +3/−0
- compat-8.10/GHC/Driver/Monad.hs +2/−0
- compat-8.10/GHC/Driver/Session.hs +2/−0
- compat-8.10/GHC/Hs/Type.hs +2/−0
- compat-8.10/GHC/Plugins.hs +2/−0
- compat-8.10/GHC/Tc/Types/Evidence.hs +2/−0
- compat-8.10/GHC/Types/Basic.hs +2/−0
- compat-8.10/GHC/Utils/Outputable.hs +2/−0
- compat/GHC/Driver/Monad.hs +2/−0
- compat/GHC/Driver/Session.hs +2/−0
- compat/GHC/Hs.hs +0/−0
- compat/GHC/Hs/Type.hs +2/−0
- compat/GHC/Hs/Types.hs +0/−2
- compat/GHC/Hs/Utils.hs +2/−0
- compat/GHC/Plugins.hs +2/−0
- compat/GHC/Tc/Types/Evidence.hs +2/−0
- compat/GHC/Types/Basic.hs +2/−0
- compat/GHC/Utils/Outputable.hs +2/−0
- ghc-source-gen.cabal +39/−9
- src/GHC/SourceGen/Binds.hs +16/−7
- src/GHC/SourceGen/Binds/Internal.hs +7/−1
- src/GHC/SourceGen/Decl.hs +24/−7
- src/GHC/SourceGen/Expr.hs +19/−4
- src/GHC/SourceGen/Expr/Internal.hs +4/−0
- src/GHC/SourceGen/Lit.hs +8/−3
- src/GHC/SourceGen/Lit/Internal.hs +6/−2
- src/GHC/SourceGen/Module.hs +23/−2
- src/GHC/SourceGen/Name.hs +9/−1
- src/GHC/SourceGen/Name/Internal.hs +10/−1
- src/GHC/SourceGen/Overloaded.hs +19/−2
- src/GHC/SourceGen/Pat.hs +19/−8
- src/GHC/SourceGen/Pat/Internal.hs +12/−2
- src/GHC/SourceGen/Pretty.hs +9/−4
- src/GHC/SourceGen/Syntax/Internal.hs +35/−2
- src/GHC/SourceGen/Type.hs +23/−6
- src/GHC/SourceGen/Type/Internal.hs +13/−1
- tests/name_test.hs +5/−0
- tests/pprint_examples.hs +1/−1
- tests/pprint_test.hs +3/−3
ChangeLog.md view
@@ -1,5 +1,8 @@ # Changelog for haskell-syntax +# 0.4.2.0+- Support GHC 9.+ # 0.4.1.0 - Add `funBindsWithFixity`. - Add `standaloneDeriving`.
+ compat-8.10/GHC/Driver/Monad.hs view
@@ -0,0 +1,2 @@+module GHC.Driver.Monad (module GhcMonad) where+import GhcMonad
+ compat-8.10/GHC/Driver/Session.hs view
@@ -0,0 +1,2 @@+module GHC.Driver.Session (module DynFlags) where+import DynFlags
+ compat-8.10/GHC/Hs/Type.hs view
@@ -0,0 +1,2 @@+module GHC.Hs.Type (module GHC.Hs.Types) where+import GHC.Hs.Types
+ compat-8.10/GHC/Plugins.hs view
@@ -0,0 +1,2 @@+module GHC.Plugins (module GhcPlugins) where+import GhcPlugins
+ compat-8.10/GHC/Tc/Types/Evidence.hs view
@@ -0,0 +1,2 @@+module GHC.Tc.Types.Evidence (module TcEvidence) where+import TcEvidence
+ compat-8.10/GHC/Types/Basic.hs view
@@ -0,0 +1,2 @@+module GHC.Types.Basic (module BasicTypes) where+import BasicTypes
+ compat-8.10/GHC/Utils/Outputable.hs view
@@ -0,0 +1,2 @@+module GHC.Utils.Outputable (module Outputable) where+import Outputable
+ compat/GHC/Driver/Monad.hs view
@@ -0,0 +1,2 @@+module GHC.Driver.Monad (module GhcMonad) where+import GhcMonad
+ compat/GHC/Driver/Session.hs view
@@ -0,0 +1,2 @@+module GHC.Driver.Session (module DynFlags) where+import DynFlags
compat/GHC/Hs.hs view
+ compat/GHC/Hs/Type.hs view
@@ -0,0 +1,2 @@+module GHC.Hs.Type (module HsTypes) where+import HsTypes
− compat/GHC/Hs/Types.hs
@@ -1,2 +0,0 @@-module GHC.Hs.Types (module HsTypes) where-import HsTypes
+ compat/GHC/Hs/Utils.hs view
@@ -0,0 +1,2 @@+module GHC.Hs.Utils (module HsUtils) where+import HsUtils
+ compat/GHC/Plugins.hs view
@@ -0,0 +1,2 @@+module GHC.Plugins (module GhcPlugins) where+import GhcPlugins
+ compat/GHC/Tc/Types/Evidence.hs view
@@ -0,0 +1,2 @@+module GHC.Tc.Types.Evidence (module TcEvidence) where+import TcEvidence
+ compat/GHC/Types/Basic.hs view
@@ -0,0 +1,2 @@+module GHC.Types.Basic (module BasicTypes) where+import BasicTypes
+ compat/GHC/Utils/Outputable.hs view
@@ -0,0 +1,2 @@+module GHC.Utils.Outputable (module Outputable) where+import Outputable
ghc-source-gen.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: ghc-source-gen-version: 0.4.1.0+version: 0.4.2.0 synopsis: Constructs Haskell syntax trees for the GHC API. description: @ghc-source-gen@ is a library for generating Haskell source code. It uses the <https://hackage.haskell.org/package/ghc ghc> library@@ -61,7 +61,7 @@ TypeSynonymInstances build-depends: base >=4.7 && <5- , ghc >=8.4 && <8.11+ , ghc >=8.4 && <9.2 if impl(ghc<8.10) other-modules: GHC.Hs@@ -72,9 +72,27 @@ GHC.Hs.ImpExp GHC.Hs.Lit GHC.Hs.Pat- GHC.Hs.Types+ GHC.Hs.Type+ GHC.Hs.Utils+ GHC.Driver.Monad+ GHC.Driver.Session+ GHC.Utils.Outputable+ GHC.Types.Basic+ GHC.Plugins+ GHC.Tc.Types.Evidence hs-source-dirs: compat+ if impl(ghc>=8.10) && impl(ghc<9.0)+ other-modules:+ GHC.Hs.Type+ GHC.Driver.Monad+ GHC.Driver.Session+ GHC.Utils.Outputable+ GHC.Types.Basic+ GHC.Plugins+ GHC.Tc.Types.Evidence+ hs-source-dirs:+ compat-8.10 default-language: Haskell2010 test-suite name_test@@ -92,9 +110,9 @@ build-depends: QuickCheck >=2.10 && <2.15 , base >=4.7 && <5- , ghc >=8.4 && <8.11+ , ghc >=8.4 && <9.2 , ghc-source-gen- , tasty >=1.0 && <1.4+ , tasty >=1.0 && <1.5 , tasty-hunit ==0.10.* , tasty-quickcheck >=0.9 && <0.11 default-language: Haskell2010@@ -113,11 +131,16 @@ TypeSynonymInstances build-depends: base >=4.7 && <5- , ghc >=8.4 && <8.11+ , ghc >=8.4 && <9.2 , ghc-paths ==0.1.* , ghc-source-gen- , tasty >=1.0 && <1.4+ , tasty >=1.0 && <1.5 , tasty-hunit ==0.10.*+ if impl(ghc<9.0)+ other-modules:+ GHC.Utils.Outputable+ hs-source-dirs:+ compat default-language: Haskell2010 test-suite pprint_test@@ -134,9 +157,16 @@ TypeSynonymInstances build-depends: base >=4.7 && <5- , ghc >=8.4 && <8.11+ , ghc >=8.4 && <9.2 , ghc-paths ==0.1.* , ghc-source-gen- , tasty >=1.0 && <1.4+ , tasty >=1.0 && <1.5 , tasty-hunit ==0.10.*+ if impl(ghc<9.0)+ other-modules:+ GHC.Driver.Monad+ GHC.Driver.Session+ GHC.Utils.Outputable+ hs-source-dirs:+ compat default-language: Haskell2010
src/GHC/SourceGen/Binds.hs view
@@ -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@@ -45,15 +46,16 @@ , (<--) ) where -import BasicTypes (LexicalFixity(..))+import GHC.Types.Basic (LexicalFixity(..)) import Data.Bool (bool) import Data.Maybe (fromMaybe) import GHC.Hs.Binds import GHC.Hs.Expr-import GHC.Hs.Types-import GhcPlugins (isSymOcc)-import TcEvidence (HsWrapper(WpHole))-+import GHC.Hs.Type+import GHC.Plugins (isSymOcc)+#if !MIN_VERSION_ghc(9,0,1)+import GHC.Tc.Types.Evidence (HsWrapper(WpHole))+#endif import GHC.SourceGen.Binds.Internal import GHC.SourceGen.Name import GHC.SourceGen.Name.Internal@@ -95,7 +97,11 @@ funBindsWithFixity :: HasValBind t => Maybe LexicalFixity -> OccNameStr -> [RawMatch] -> t funBindsWithFixity fixity name matches = bindB $ withPlaceHolder (noExt FunBind name'- (matchGroup context matches) WpHole)+ (matchGroup context matches) +#if !MIN_VERSION_ghc(9,0,1)+ WpHole+#endif+ ) [] where name' = valueRdrName $ unqual name@@ -288,7 +294,10 @@ -- > ===== -- > 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.
src/GHC/SourceGen/Binds/Internal.hs view
@@ -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(..))
src/GHC/SourceGen/Decl.hs view
@@ -49,14 +49,22 @@ , 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(..)@@ -71,8 +79,10 @@ #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))@@ -154,7 +164,9 @@ 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@@ -306,10 +318,10 @@ -- -- > 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.@@ -319,7 +331,7 @@ -- > 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.@@ -370,6 +382,11 @@ -- > strict $ field $ var "A" @@ var "b" 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
src/GHC/SourceGen/Expr.hs view
@@ -31,9 +31,14 @@ 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@@ -68,7 +73,7 @@ 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. --@@ -94,7 +99,12 @@ -- > ===== -- > 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:@@ -120,7 +130,12 @@ -- > ] 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]
src/GHC/SourceGen/Expr/Internal.hs view
@@ -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
src/GHC/SourceGen/Lit.hs view
@@ -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'@@ -16,12 +17,16 @@ , 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
src/GHC/SourceGen/Lit/Internal.hs view
@@ -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
src/GHC/SourceGen/Module.hs view
@@ -34,7 +34,13 @@ , 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@@ -54,6 +60,9 @@ , hsmodDecls = fmap builtLoc decls , hsmodDeprecMessage = Nothing , hsmodHaddockModHeader = Nothing+#if MIN_VERSION_ghc(9,0,0)+ , hsmodLayout = NoLayoutInfo+#endif } qualified' :: ImportDecl' -> ImportDecl'@@ -71,7 +80,13 @@ 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@@ -89,7 +104,13 @@ -- | 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. --
src/GHC/SourceGen/Name.hs view
@@ -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(..)@@ -27,11 +28,18 @@ , 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
src/GHC/SourceGen/Name/Internal.hs view
@@ -4,16 +4,25 @@ -- license that can be found in the LICENSE file or at -- https://developers.google.com/open-source/licenses/bsd +{-# LANGUAGE CPP #-} module GHC.SourceGen.Name.Internal where import Data.Char (isAlphaNum, isUpper) import Data.List (intercalate) import Data.String (IsString(..))+#if MIN_VERSION_ghc(9,0,0)+import GHC.Data.FastString (FastString, fsLit)+import GHC.Unit.Module (mkModuleNameFS, ModuleName, moduleNameString)+import GHC.Types.Name.Occurrence+import GHC.Types.Name.Reader+import GHC.Types.SrcLoc (Located)+#else import FastString (FastString, fsLit) import Module (mkModuleNameFS, ModuleName, moduleNameString)-import RdrName import OccName+import RdrName import SrcLoc (Located)+#endif import GHC.SourceGen.Syntax.Internal (builtLoc)
src/GHC/SourceGen/Overloaded.hs view
@@ -18,8 +18,7 @@ , BVar(..) ) where -import BasicTypes (Boxity(..))-import GHC.Hs.Types+import GHC.Hs.Type ( HsType(..) , HsTyVarBndr(..) )@@ -34,10 +33,20 @@ , HsTupArg(..) , HsTupleSort(..) )+#if MIN_VERSION_ghc(9,0,0)+import GHC.Types.Basic (Boxity(..))+import GHC.Core.DataCon (dataConName)+import GHC.Types.Name.Reader (RdrName(..), nameRdrName)+import GHC.Types.SrcLoc (Located)+import GHC.Builtin.Types (consDataCon_RDR, nilDataCon, unitDataCon)+import GHC.Types.Var (Specificity(..))+#else+import BasicTypes (Boxity(..)) import DataCon (dataConName) import RdrName (RdrName(..), nameRdrName) import SrcLoc (Located) import TysWiredIn (consDataCon_RDR, nilDataCon, unitDataCon)+#endif import GHC.SourceGen.Expr.Internal import GHC.SourceGen.Name.Internal@@ -241,8 +250,16 @@ instance BVar HsType' where bvar = var . UnqualStr +#if MIN_VERSION_ghc(9,0,0) instance BVar HsTyVarBndr' where+ bvar = noExt UserTyVar () . typeRdrName . UnqualStr++instance BVar HsTyVarBndrS' where+ bvar = noExt UserTyVar SpecifiedSpec . typeRdrName . UnqualStr+#else+instance BVar HsTyVarBndr' where bvar = noExt UserTyVar . typeRdrName . UnqualStr+#endif instance Var IE' where var n = noExt IEVar $ builtLoc $ IEName $ exportRdrName n
src/GHC/SourceGen/Pat.hs view
@@ -18,13 +18,13 @@ , sigP ) where -import GHC.Hs.Types+import GHC.Hs.Type import GHC.Hs.Pat hiding (LHsRecField') import GHC.SourceGen.Name.Internal import GHC.SourceGen.Pat.Internal import GHC.SourceGen.Syntax.Internal-import GHC.SourceGen.Type.Internal (sigWcType)+import GHC.SourceGen.Type.Internal (patSigType) -- | A wild pattern (@_@). wildP :: Pat'@@ -44,7 +44,13 @@ -- > ===== -- > conP "A" [bvar "b", bvar "c"] conP :: RdrNameStr -> [Pat'] -> Pat'-conP c xs = ConPatIn (valueRdrName c) $ PrefixCon+conP c xs =+#if MIN_VERSION_ghc(9,0,0)+ noExt ConPat+#else+ ConPatIn+#endif+ (valueRdrName c) $ PrefixCon $ map (builtPat . parenthesize) xs -- | A pattern constructor with no arguments.@@ -56,8 +62,13 @@ conP_ c = conP c [] recordConP :: RdrNameStr -> [(RdrNameStr, Pat')] -> Pat'-recordConP c fs- = ConPatIn (valueRdrName c)+recordConP c fs =+#if MIN_VERSION_ghc(9,0,0)+ noExt ConPat+#else+ ConPatIn+#endif+ (valueRdrName c) $ RecCon $ HsRecFields (map mkRecField fs) Nothing -- No ".." where mkRecField :: (RdrNameStr, Pat') -> LHsRecField' LPat'@@ -92,9 +103,9 @@ -- > sigPat (bvar "x") (var "y") sigP :: Pat' -> HsType' -> Pat' #if MIN_VERSION_ghc(8,8,0)-sigP p t = noExt SigPat (builtPat p) (sigWcType t)+sigP p t = noExt SigPat (builtPat p) (patSigType t) #elif MIN_VERSION_ghc(8,6,0)-sigP p t = SigPat (sigWcType t) (builtPat p)+sigP p t = SigPat (patSigType t) (builtPat p) #else-sigP p t = SigPatIn (builtPat p) (sigWcType t)+sigP p t = SigPatIn (builtPat p) (patSigType t) #endif
src/GHC/SourceGen/Pat/Internal.hs view
@@ -2,11 +2,16 @@ module GHC.SourceGen.Pat.Internal where import GHC.Hs.Pat (Pat(..))-import GHC.Hs.Types (HsConDetails(..))+#if MIN_VERSION_ghc(9,0,0)+import GHC.Hs.Type (HsConDetails(..))+import GHC.Types.SrcLoc (unLoc)+#else+import GHC.Hs.Type (HsConDetails(..))+import SrcLoc (unLoc)+#endif import GHC.SourceGen.Lit.Internal (litNeedsParen, overLitNeedsParen) import GHC.SourceGen.Syntax.Internal-import SrcLoc (unLoc) -- Note: GHC>=8.6 inserts parentheses automatically when pretty-printing patterns. -- When we stop supporting lower versions, we may be able to simplify this.@@ -24,9 +29,14 @@ needsPar (LitPat l) = litNeedsParen l needsPar (NPat l _ _ _) = overLitNeedsParen $ unLoc l #endif+#if MIN_VERSION_ghc(9,0,0)+needsPar (ConPat _ _ (PrefixCon xs)) = not $ null xs+needsPar (ConPat _ _ (InfixCon _ _)) = True+#else needsPar (ConPatIn _ (PrefixCon xs)) = not $ null xs needsPar (ConPatIn _ (InfixCon _ _)) = True needsPar ConPatOut{} = True+#endif #if MIN_VERSION_ghc(8,6,0) needsPar SigPat{} = True #else
src/GHC/SourceGen/Pretty.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} -- Copyright 2019 Google LLC -- -- Use of this source code is governed by a BSD-style@@ -11,15 +12,19 @@ , hPutPpr ) where -import DynFlags-import GhcMonad-import Outputable+import GHC.Driver.Monad+import GHC.Driver.Session+import GHC.Utils.Outputable import System.IO hPutPpr :: Outputable a => Handle -> a -> Ghc () hPutPpr h x = do dflags <- getDynFlags- liftIO $ printForUser dflags h neverQualify $ ppr x+ liftIO $ printForUser dflags h neverQualify+#if MIN_VERSION_ghc(9,0,1)+ AllTheWay+#endif+ $ ppr x putPpr :: Outputable a => a -> Ghc () putPpr = hPutPpr stdout
src/GHC/SourceGen/Syntax/Internal.hs view
@@ -39,6 +39,9 @@ , LHsRecField , LHsRecUpdField #endif+#if MIN_VERSION_ghc(9,0,0)+ , HsPatSigType+#endif ) import GHC.Hs.Binds (Sig, HsLocalBinds) #if MIN_VERSION_ghc(8,6,0)@@ -48,13 +51,19 @@ #endif import GHC.Hs.Decls (HsDerivingClause) import GHC.Hs.Pat+#if MIN_VERSION_ghc(9,0,0)+import GHC.Types.SrcLoc (SrcSpan, Located, GenLocated(..), mkGeneralSrcSpan)+#else import RdrName (RdrName) import SrcLoc (SrcSpan, Located, GenLocated(..), mkGeneralSrcSpan)+#endif -#if MIN_VERSION_ghc(8,8,0)+#if MIN_VERSION_ghc(9,0,0)+import GHC.Types.Basic (PromotionFlag(..))+#elif MIN_VERSION_ghc(8,8,0) import BasicTypes (PromotionFlag(..)) #else-import GHC.Hs.Types (Promoted(..))+import GHC.Hs.Type (Promoted(..)) #endif #if MIN_VERSION_ghc(8,10,0)@@ -65,6 +74,10 @@ import PlaceHolder(PlaceHolder(..)) #endif +#if MIN_VERSION_ghc(9,0,0)+import GHC.Types.Var (Specificity)+#endif+ import GHC.Hs.Extension (GhcPs) #if MIN_VERSION_ghc(8,6,0)@@ -194,15 +207,29 @@ -- Instances: -- -- * 'GHC.SourceGen.Overloaded.BVar'+#if MIN_VERSION_ghc(9,0,0)+type HsTyVarBndr' = HsTyVarBndr () GhcPs+type HsTyVarBndrS' = HsTyVarBndr Specificity GhcPs+#else type HsTyVarBndr' = HsTyVarBndr GhcPs+type HsTyVarBndrS' = HsTyVarBndr GhcPs+#endif type HsLit' = HsLit GhcPs+#if MIN_VERSION_ghc(9,0,0)+type HsModule' = HsModule+#else type HsModule' = HsModule GhcPs+#endif type HsBind' = HsBind GhcPs type HsLocalBinds' = HsLocalBinds GhcPs type HsValBinds' = HsValBinds GhcPs type Sig' = Sig GhcPs+#if MIN_VERSION_ghc(9,0,0)+type HsMatchContext' = HsMatchContext GhcPs+#else type HsMatchContext' = HsMatchContext RdrName+#endif type Match' = Match GhcPs type MatchGroup' = MatchGroup GhcPs type GRHS' = GRHS GhcPs@@ -227,4 +254,10 @@ type DerivStrategy' = DerivStrategy GhcPs #else type DerivStrategy' = DerivStrategy+#endif++#if MIN_VERSION_ghc(9,0,0)+type HsPatSigType' = HsPatSigType GhcPs+#else+type HsPatSigType' = LHsSigWcType' #endif
src/GHC/SourceGen/Type.hs view
@@ -22,7 +22,12 @@ ) where import Data.String (fromString)-import GHC.Hs.Types+#if MIN_VERSION_ghc(9,0,0)+import GHC.Hs.Type+import GHC.Parser.Annotation+#else+import GHC.Hs.Type+#endif import GHC.SourceGen.Syntax.Internal import GHC.SourceGen.Lit.Internal (noSourceText)@@ -56,7 +61,11 @@ -- > ===== -- > var "a" --> var "b" (-->) :: HsType' -> HsType' -> HsType'-a --> b = noExt HsFunTy (parenthesizeTypeForFun $ builtLoc a) (builtLoc b)+a --> b = noExt HsFunTy+#if MIN_VERSION_ghc(9,0,0)+ (HsUnrestrictedArrow NormalSyntax)+#endif+ (parenthesizeTypeForFun $ builtLoc a) (builtLoc b) infixr 0 --> @@ -65,12 +74,17 @@ -- > forall a . T a -- > ===== -- > forall' [bvar "a"] $ var "T" @@ var "a"-forall' :: [HsTyVarBndr'] -> HsType' -> HsType'+forall' :: [HsTyVarBndrS'] -> HsType' -> HsType' forall' ts = noExt HsForAllTy+#if MIN_VERSION_ghc(9,0,0)+ (mkHsForAllInvisTele (map builtLoc ts))+#else #if MIN_VERSION_ghc(8,10,0) ForallInvis -- "Invisible" forall, i.e., with a dot #endif- (map builtLoc ts) . builtLoc+ (map builtLoc ts)+#endif+ . builtLoc -- | Qualify a type with constraints. --@@ -88,5 +102,8 @@ -- > ===== -- > kindedVar "x" (var "A") kindedVar :: OccNameStr -> HsType' -> HsTyVarBndr'-kindedVar v t = noExt KindedTyVar (typeRdrName $ UnqualStr v)- (builtLoc t)+kindedVar v t = noExt KindedTyVar+#if MIN_VERSION_ghc(9,0,0)+ ()+#endif+ (typeRdrName $ UnqualStr v) (builtLoc t)
src/GHC/SourceGen/Type/Internal.hs view
@@ -7,8 +7,13 @@ {-# LANGUAGE CPP #-} module GHC.SourceGen.Type.Internal where -import GHC.Hs.Types as Types+#if MIN_VERSION_ghc(9,0,0)+import GHC.Hs.Type as Types+import GHC.Types.SrcLoc (Located, unLoc)+#else+import GHC.Hs.Type as Types import SrcLoc (Located, unLoc)+#endif import GHC.SourceGen.Syntax.Internal @@ -62,3 +67,10 @@ wcType :: HsType' -> LHsWcType' wcType = noExt (withPlaceHolder Types.HsWC) . builtLoc++patSigType :: HsType' -> HsPatSigType'+#if MIN_VERSION_ghc(9,0,0)+patSigType = mkHsPatSigType . builtLoc+#else+patSigType = sigWcType+#endif
tests/name_test.hs view
@@ -1,9 +1,14 @@ {-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE CPP #-} module Main (main) where import GHC.SourceGen.Name +#if MIN_VERSION_ghc(9,0,1)+import GHC.Types.Name.Occurrence+#else import OccName+#endif import Data.List (intercalate) import Data.String (fromString)
tests/pprint_examples.hs view
@@ -11,7 +11,7 @@ import GHC.Paths (libdir) import GHC (runGhc)-import Outputable (Outputable)+import GHC.Utils.Outputable (Outputable) import GHC.SourceGen
tests/pprint_test.hs view
@@ -1,11 +1,11 @@ {-# LANGUAGE OverloadedStrings #-} module Main(main) where -import DynFlags (getDynFlags)-import GhcMonad (liftIO)+import GHC.Driver.Session (getDynFlags)+import GHC.Driver.Monad (liftIO) import GHC.Paths (libdir) import GHC (runGhc, DynFlags)-import Outputable (Outputable)+import GHC.Utils.Outputable (Outputable) import Test.Tasty import Test.Tasty.HUnit