diff --git a/ghc-show-ast/Main.hs b/ghc-show-ast/Main.hs index 2b93aac..49f25a4 100644 --- a/ghc-show-ast/Main.hs +++ b/ghc-show-ast/Main.hs @@ -13,7 +13,14 @@ import Data.Typeable (cast) import System.Environment (getArgs) import Text.PrettyPrint -#if MIN_VERSION_ghc(9,2,0) +#if MIN_VERSION_ghc(9,4,0) +import GHC.Driver.Config.Diagnostic (initDiagOpts) +import GHC.Driver.Config.Parser (initParserOpts) +import qualified GHC.Driver.Errors as Error (printMessages) +#if MIN_VERSION_ghc(9,6,0) +import qualified GHC.Types.Error as GHC (NoDiagnosticOpts(..)) +#endif +#elif MIN_VERSION_ghc(9,2,0) import qualified GHC.Driver.Errors as Error import qualified GHC.Parser.Errors.Ppr as Error #elif MIN_VERSION_ghc(9,0,0) @@ -103,7 +110,7 @@ main = do result <- parseModule f print $ gPrint result -#if MIN_VERSION_ghc(9,0,1) +#if MIN_VERSION_ghc(9,0,1) && !MIN_VERSION_ghc(9,6,0) parseModule :: FilePath -> IO GHC.HsModule #else parseModule :: FilePath -> IO (GHC.HsModule GHC.GhcPs) @@ -111,10 +118,27 @@ parseModule :: FilePath -> IO (GHC.HsModule GHC.GhcPs) parseModule f = GHC.runGhc (Just libdir) $ do dflags <- GHC.getDynFlags contents <- GHC.liftIO $ GHC.stringToStringBuffer <$> readFile f +#if MIN_VERSION_ghc(9,4,0) + let (_, options) = GHC.getOptions (initParserOpts dflags) contents f +#else let options = GHC.getOptions dflags contents f +#endif (dflags', _, _) <- GHC.parseDynamicFilePragma dflags options -#if MIN_VERSION_ghc(9,2,0) +#if MIN_VERSION_ghc(9,4,0) + let diagOpts = initDiagOpts dflags' + state = + GHC.initParserState + ( GHC.mkParserOpts + (GHC.extensionFlags dflags') + diagOpts + [] + (GHC.safeImportsOn dflags') + (GHC.gopt GHC.Opt_Haddock dflags') + (GHC.gopt GHC.Opt_KeepRawTokenStream dflags') + True + ) +#elif MIN_VERSION_ghc(9,2,0) let state = GHC.initParserState ( GHC.mkParserOpts @@ -135,7 +159,18 @@ parseModule f = GHC.runGhc (Just libdir) $ do case GHC.unP Parser.parseModule state of GHC.POk _state m -> return $ GHC.unLoc m -#if MIN_VERSION_ghc(9,2,0) +#if MIN_VERSION_ghc(9,4,0) + GHC.PFailed s -> do + logger <- GHC.getLogger + liftIO $ do + let errors = GHC.getPsErrorMessages s +# if MIN_VERSION_ghc(9,6,0) + Error.printMessages logger GHC.NoDiagnosticOpts diagOpts errors +# else + Error.printMessages logger diagOpts errors +# endif + exitFailure +#elif MIN_VERSION_ghc(9,2,0) GHC.PFailed s -> do logger <- GHC.getLogger liftIO $ do diff --git a/ghc-source-gen.cabal b/ghc-source-gen.cabal index e5c7799..19bf18e 100644 --- a/ghc-source-gen.cabal +++ b/ghc-source-gen.cabal @@ -61,7 +61,7 @@ library TypeSynonymInstances build-depends: base >=4.7 && <5 - , ghc >=8.4 && <9.5 + , ghc >=8.4 && <9.7 if impl(ghc<8.10) other-modules: GHC.Hs @@ -104,7 +104,7 @@ test-suite name_test build-depends: QuickCheck >=2.10 && <2.15 , base >=4.7 && <5 - , ghc >=8.4 && <9.5 + , ghc >=8.4 && <9.7 , ghc-source-gen , tasty >=1.0 && <1.5 , tasty-hunit ==0.10.* @@ -125,7 +125,7 @@ test-suite pprint_examples TypeSynonymInstances build-depends: base >=4.7 && <5 - , ghc >=8.4 && <9.5 + , ghc >=8.4 && <9.7 , ghc-paths ==0.1.* , ghc-source-gen , tasty >=1.0 && <1.5 @@ -151,7 +151,7 @@ test-suite pprint_test TypeSynonymInstances build-depends: base >=4.7 && <5 - , ghc >=8.4 && <9.5 + , ghc >=8.4 && <9.7 , ghc-paths ==0.1.* , ghc-source-gen , tasty >=1.0 && <1.5 diff --git a/package.yaml b/package.yaml index eb733ab..f601753 100644 --- a/package.yaml +++ b/package.yaml @@ -30,7 +30,7 @@ description: | dependencies: - base >= 4.7 && < 5 -- ghc >= 8.4 && < 9.5 +- ghc >= 8.4 && < 9.7 default-extensions: - DataKinds diff --git a/src/GHC/SourceGen/Binds.hs b/src/GHC/SourceGen/Binds.hs index 4137c46..98e1b08 100644 --- a/src/GHC/SourceGen/Binds.hs +++ b/src/GHC/SourceGen/Binds.hs @@ -101,12 +101,14 @@ typeSig n = typeSigs [n] funBindsWithFixity :: HasValBind t => Maybe LexicalFixity -> OccNameStr -> [RawMatch] -> t funBindsWithFixity fixity name matches = bindB $ withPlaceHolder (noExt FunBind name' - (matchGroup context matches) + (matchGroup context matches) #if !MIN_VERSION_ghc(9,0,1) WpHole #endif ) +#if !MIN_VERSION_ghc(9,6,0) [] +#endif where name' = valueRdrName $ unqual name occ = valueOccName name @@ -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. -- diff --git a/src/GHC/SourceGen/Binds/Internal.hs b/src/GHC/SourceGen/Binds/Internal.hs index 99605cf..9a5124d 100644 --- a/src/GHC/SourceGen/Binds/Internal.hs +++ b/src/GHC/SourceGen/Binds/Internal.hs @@ -83,12 +83,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) diff --git a/src/GHC/SourceGen/Decl.hs b/src/GHC/SourceGen/Decl.hs index 35acdc0..ee12956 100644 --- a/src/GHC/SourceGen/Decl.hs +++ b/src/GHC/SourceGen/Decl.hs @@ -54,7 +54,13 @@ module GHC.SourceGen.Decl #if MIN_VERSION_ghc(9,0,0) import GHC (LexicalFixity(Prefix)) import GHC.Data.Bag (listToBag) -import GHC.Types.SrcLoc (LayoutInfo(..)) + +#if MIN_VERSION_ghc(9,6,0) +import GHC (GhcPs, LayoutInfo (NoLayoutInfo)) +#else +import GHC.Types.SrcLoc (LayoutInfo(NoLayoutInfo)) +#endif + #else import BasicTypes (LexicalFixity(Prefix)) import Bag (listToBag) @@ -62,7 +68,6 @@ import Bag (listToBag) #if !MIN_VERSION_ghc(8,6,0) import BasicTypes (DerivStrategy(..)) #endif -import GHC (GhcPs) import GHC.Hs.Binds import GHC.Hs.Decls @@ -108,6 +113,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. -- @@ -174,7 +180,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 @@ -323,11 +332,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 diff --git a/src/GHC/SourceGen/Expr.hs b/src/GHC/SourceGen/Expr.hs index 6cded38..49c5c55 100644 --- a/src/GHC/SourceGen/Expr.hs +++ b/src/GHC/SourceGen/Expr.hs @@ -30,6 +30,10 @@ module GHC.SourceGen.Expr import GHC.Hs.Expr import GHC.Hs.Extension (GhcPs) +#if MIN_VERSION_ghc(9,6,0) +import GHC.Hs.Extension (noHsTok) +import GHC.Types.SourceText (SourceText(NoSourceText)) +#endif #if MIN_VERSION_ghc(9,4,0) import GHC.Hs.Pat (HsFieldBind(..), HsRecFields(..)) #else @@ -67,7 +71,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 @@ -198,7 +204,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' diff --git a/src/GHC/SourceGen/Module.hs b/src/GHC/SourceGen/Module.hs index 7745b6b..1d9340a 100644 --- a/src/GHC/SourceGen/Module.hs +++ b/src/GHC/SourceGen/Module.hs @@ -26,7 +26,14 @@ module GHC.SourceGen.Module , moduleContents ) where -import GHC.Hs.ImpExp (LIEWrappedName, IEWildcard(..), IEWrappedName(..), IE(..)) +import GHC.Hs.ImpExp + ( IEWildcard(..), IEWrappedName(..), IE(..) +#if MIN_VERSION_ghc(9,6,0) + , ImportListInterpretation (EverythingBut, Exactly), XImportDeclPass (ideclSourceText, ideclImplicit) +#else + , LIEWrappedName +#endif + ) import GHC.Hs ( HsModule(..) , ImportDecl(..) @@ -35,10 +42,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 @@ -49,9 +61,16 @@ import GHC.Types.PkgQual (RawPkgQual(..)) #endif import GHC.SourceGen.Syntax.Internal -import GHC.SourceGen.Name import GHC.SourceGen.Name.Internal import GHC.SourceGen.Lit.Internal (noSourceText) +#if MIN_VERSION_ghc(9,0,0) +import GHC.SourceGen.Name (unqual) +#endif +#if MIN_VERSION_ghc(9,4,0) +import GHC.SourceGen.Name (RdrNameStr, ModuleNameStr(unModuleNameStr), OccNameStr) +import GHC.Types.SourceText (SourceText(NoSourceText)) +import GHC.Types.SrcLoc (GenLocated) +#endif module' :: Maybe ModuleNameStr @@ -64,13 +83,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 } @@ -87,12 +114,12 @@ 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 #else - Nothing + Nothing #endif #if MIN_VERSION_ghc(9,0,0) NotBoot @@ -105,15 +132,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' @@ -150,8 +198,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. -- diff --git a/src/GHC/SourceGen/Overloaded.hs b/src/GHC/SourceGen/Overloaded.hs index 7d3a1d5..762e81d 100644 --- a/src/GHC/SourceGen/Overloaded.hs +++ b/src/GHC/SourceGen/Overloaded.hs @@ -22,7 +22,11 @@ import GHC.Hs.Type ( HsType(..) , HsTyVarBndr(..) ) -import GHC.Hs (IE(..), IEWrappedName(..)) +import GHC.Hs (IE(..), IEWrappedName(..) +#if MIN_VERSION_ghc(9,6,0) + , noExtField +#endif + ) #if !MIN_VERSION_ghc(8,6,0) import PlaceHolder(PlaceHolder(..)) #endif @@ -286,8 +290,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 - diff --git a/src/GHC/SourceGen/Pat.hs b/src/GHC/SourceGen/Pat.hs index 5f74595..9f82370 100644 --- a/src/GHC/SourceGen/Pat.hs +++ b/src/GHC/SourceGen/Pat.hs @@ -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' @@ -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. -- diff --git a/src/GHC/SourceGen/Syntax/Internal.hs b/src/GHC/SourceGen/Syntax/Internal.hs index a5bc7f5..c1a2c2c 100644 --- a/src/GHC/SourceGen/Syntax/Internal.hs +++ b/src/GHC/SourceGen/Syntax/Internal.hs @@ -62,7 +62,7 @@ import RdrName (RdrName) import SrcLoc (SrcSpan, Located, GenLocated(..), mkGeneralSrcSpan) #endif -#if MIN_VERSION_ghc(9,2,0) +#if MIN_VERSION_ghc(9,2,0) && !MIN_VERSION_ghc(9,6,0) import GHC.Parser.Annotation ( SrcSpanAnn'(..) , AnnSortKey(..) @@ -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 diff --git a/stack-9.0.yaml b/stack-9.0.yaml index 3d5b32d..b463ce3 100644 --- a/stack-9.0.yaml +++ b/stack-9.0.yaml @@ -11,4 +11,4 @@ packages: - ghc-show-ast ghc-options: - "$locals": -Wall -Werror + "$locals": -Wall -Werror -Wwarn=unused-imports -Wwarn=dodgy-imports diff --git a/stack-9.2.yaml b/stack-9.2.yaml index 1b38645..da6d321 100644 --- a/stack-9.2.yaml +++ b/stack-9.2.yaml @@ -4,12 +4,12 @@ # license that can be found in the LICENSE file or at # https://developers.google.com/open-source/licenses/bsd -resolver: nightly-2022-08-19 -compiler: ghc-9.2.4 +resolver: lts-20.26 +compiler: ghc-9.2.8 packages: - . - ghc-show-ast ghc-options: - "$locals": -Wall -Werror + "$locals": -Wall -Werror -Wwarn=unused-imports -Wwarn=dodgy-imports diff --git a/stack-9.4.yaml b/stack-9.4.yaml new file mode 100644 index 0000000..cb92c0e --- /dev/null +++ b/stack-9.4.yaml @@ -0,0 +1,15 @@ +# Copyright 2019 Google LLC +# +# Use of this source code is governed by a BSD-style +# license that can be found in the LICENSE file or at +# https://developers.google.com/open-source/licenses/bsd + +resolver: lts-21.25 +compiler: ghc-9.4.8 + +packages: +- . +- ghc-show-ast + +ghc-options: + "$locals": -Wall -Werror -Wwarn=unused-imports -Wwarn=dodgy-imports diff --git a/stack-9.6.yaml b/stack-9.6.yaml new file mode 100644 index 0000000..440029e --- /dev/null +++ b/stack-9.6.yaml @@ -0,0 +1,15 @@ +# Copyright 2019 Google LLC +# +# Use of this source code is governed by a BSD-style +# license that can be found in the LICENSE file or at +# https://developers.google.com/open-source/licenses/bsd + +resolver: nightly-2023-11-21 +compiler: ghc-9.6.3 + +packages: +- . +- ghc-show-ast + +ghc-options: + "$locals": -Wall -Werror -Wwarn=unused-imports -Wwarn=dodgy-imports