From b7e69c73b6fc87a77df14721d4ed264f80a0cebd Mon Sep 17 00:00:00 2001 From: Mann mit Hut Date: Sun, 12 Jan 2025 20:18:39 +0100 Subject: [PATCH 1/2] Support GHC 9.12.1 --- compat/9.10.1/GHC/Compat.hs | 14 +++++++++++--- compat/9.12.1/GHC/Compat.hs | 19 +++++++++++++++++++ compat/9.6.6/GHC/Compat.hs | 14 +++++++++++--- compat/9.8.4/GHC/Compat.hs | 15 +++++++++++---- print-api.cabal | 24 +++++++++++++++++++----- src/PrintApi/CLI/Cmd/Dump.hs | 22 +++++++++++++--------- 6 files changed, 84 insertions(+), 24 deletions(-) create mode 100644 compat/9.12.1/GHC/Compat.hs diff --git a/compat/9.10.1/GHC/Compat.hs b/compat/9.10.1/GHC/Compat.hs index 659413b..5e4b33e 100644 --- a/compat/9.10.1/GHC/Compat.hs +++ b/compat/9.10.1/GHC/Compat.hs @@ -1,11 +1,19 @@ --- GHC 9.10.1 Compatibility -module GHC.Compat where +-- GHC 9.10.1 compatibility +module GHC.Compat + ( mkNamePprCtxForModule + , mkShowSub + ) where -import GHC (ModuleInfo) +import Data.Maybe (fromJust) +import GHC (Ghc, Module, ModuleInfo, NamePprCtx) +import GHC qualified import GHC.Iface.Syntax (AltPpr (..), ShowForAllFlag (..), ShowHowMuch (..), ShowSub (..)) import PrintApi.IgnoredDeclarations +mkNamePprCtxForModule :: Module -> ModuleInfo -> Ghc NamePprCtx +mkNamePprCtxForModule _ mod_info = fromJust <$> GHC.mkNamePprCtxForModule mod_info + mkShowSub :: ModuleInfo -> ShowSub mkShowSub mod_info = let ss_how_much = ShowSome (Just (showOcc mod_info)) (AltPpr Nothing) diff --git a/compat/9.12.1/GHC/Compat.hs b/compat/9.12.1/GHC/Compat.hs new file mode 100644 index 0000000..7356f09 --- /dev/null +++ b/compat/9.12.1/GHC/Compat.hs @@ -0,0 +1,19 @@ +-- GHC 9.12.1 compatibility +module GHC.Compat + ( GHC.mkNamePprCtxForModule + , mkShowSub + ) where + +import GHC (ModuleInfo) +import GHC qualified +import GHC.Iface.Syntax (AltPpr (..), ShowForAllFlag (..), ShowHowMuch (..), ShowSub (..)) + +import PrintApi.IgnoredDeclarations + +mkShowSub :: ModuleInfo -> ShowSub +mkShowSub mod_info = + let ss_how_much = ShowSome (Just (showOcc mod_info)) (AltPpr Nothing) + in ShowSub + { ss_how_much = ss_how_much + , ss_forall = ShowForAllMust + } diff --git a/compat/9.6.6/GHC/Compat.hs b/compat/9.6.6/GHC/Compat.hs index 548340f..f06865e 100644 --- a/compat/9.6.6/GHC/Compat.hs +++ b/compat/9.6.6/GHC/Compat.hs @@ -1,9 +1,17 @@ --- GHC 9.6.6 Compatibility -module GHC.Compat where +-- GHC 9.6.6 compatibility +module GHC.Compat + ( mkNamePprCtxForModule + , mkShowSub + ) where -import GHC (ModuleInfo) +import Data.Maybe (fromJust) +import GHC (Ghc, Module, ModuleInfo, NamePprCtx) +import GHC qualified import GHC.Iface.Syntax (AltPpr (..), ShowForAllFlag (..), ShowHowMuch (..), ShowSub (..)) +mkNamePprCtxForModule :: Module -> ModuleInfo -> Ghc NamePprCtx +mkNamePprCtxForModule _ mod_info = fromJust <$> GHC.mkNamePprCtxForModule mod_info + mkShowSub :: ModuleInfo -> ShowSub mkShowSub _mod_info = let ss_how_much = ShowSome [] (AltPpr Nothing) diff --git a/compat/9.8.4/GHC/Compat.hs b/compat/9.8.4/GHC/Compat.hs index b9b5627..36fd3a3 100644 --- a/compat/9.8.4/GHC/Compat.hs +++ b/compat/9.8.4/GHC/Compat.hs @@ -1,9 +1,16 @@ --- GHC 9.10.1 Compatibility -module GHC.Compat where +-- GHC 9.8.4 compatibility +module GHC.Compat + ( mkNamePprCtxForModule + , mkShowSub + ) where -import GHC (ModuleInfo) +import Data.Maybe (fromJust) +import GHC (Ghc, Module, ModuleInfo, NamePprCtx) +import GHC qualified import GHC.Iface.Syntax (AltPpr (..), ShowForAllFlag (..), ShowHowMuch (..), ShowSub (..)) -import PrintApi.IgnoredDeclarations () + +mkNamePprCtxForModule :: Module -> ModuleInfo -> Ghc NamePprCtx +mkNamePprCtxForModule _ mod_info = fromJust <$> GHC.mkNamePprCtxForModule mod_info mkShowSub :: ModuleInfo -> ShowSub mkShowSub _ = diff --git a/print-api.cabal b/print-api.cabal index c09c1d7..99d1c09 100644 --- a/print-api.cabal +++ b/print-api.cabal @@ -12,10 +12,11 @@ maintainer: hecate+github@glitchbra.in copyright: © 2023 Ben Gamari, 2024 Hécate Kleidukos extra-source-files: compat/9.10.1/GHC/Compat.hs + compat/9.12.1/GHC/Compat.hs compat/9.6.6/GHC/Compat.hs compat/9.8.4/GHC/Compat.hs -tested-with: GHC ==9.6.6 || ==9.8.4 || ==9.10.1 +tested-with: GHC ==9.6.6 || ==9.8.4 || ==9.10.1 || ==9.12.1 common extensions default-extensions: @@ -69,14 +70,17 @@ library import: ghc-options hs-source-dirs: src - if impl(ghc ==9.10.1) - hs-source-dirs: compat/9.10.1 + if impl(ghc ==9.6.6) + hs-source-dirs: compat/9.6.6 if impl(ghc ==9.8.4) hs-source-dirs: compat/9.8.4 - if impl(ghc ==9.6.6) - hs-source-dirs: compat/9.6.6 + if impl(ghc ==9.10.1) + hs-source-dirs: compat/9.10.1 + + if impl(ghc ==9.12.1) + hs-source-dirs: compat/9.12.1 other-modules: Paths_print_api autogen-modules: Paths_print_api @@ -148,6 +152,16 @@ executable print-api-9.10.1 else buildable: False +executable print-api-9.12.1 + import: print-api-common + main-is: Main.hs + + if impl(ghc ==9.12.1) + buildable: True + + else + buildable: False + test-suite print-api-test import: extensions import: ghc-options diff --git a/src/PrintApi/CLI/Cmd/Dump.hs b/src/PrintApi/CLI/Cmd/Dump.hs index 132877c..630cd24 100644 --- a/src/PrintApi/CLI/Cmd/Dump.hs +++ b/src/PrintApi/CLI/Cmd/Dump.hs @@ -11,7 +11,10 @@ -- Visibility : Public -- -- The processing of package information -module PrintApi.CLI.Cmd.Dump where +module PrintApi.CLI.Cmd.Dump + ( run + , computePackageAPI + ) where import Control.Monad.IO.Class import Data.Function (on, (&)) @@ -23,14 +26,15 @@ import Data.Text (Text) import Data.Text qualified as Text import Data.Text.Encoding qualified as TE import GHC - ( ModuleInfo + ( Module + , ModuleInfo , getModuleInfo , getNamePprCtx , lookupName , lookupQualifiedModule - , mkNamePprCtxForModule , modInfoExports , modInfoIface + , moduleName , parseDynamicFlags , runGhc , setProgramDynFlags @@ -157,13 +161,13 @@ reportModuleDecls usePublicOnly userIgnoredModules unitId moduleName if usePublicOnly then if isVisible docs - then extractModuleDeclarations moduleName mod_info + then extractModuleDeclarations modl mod_info else pure empty - else extractModuleDeclarations moduleName mod_info + else extractModuleDeclarations modl mod_info -extractModuleDeclarations :: ModuleName -> ModuleInfo -> Ghc SDoc -extractModuleDeclarations moduleName mod_info = do - Just name_ppr_ctx <- mkNamePprCtxForModule mod_info +extractModuleDeclarations :: Module -> ModuleInfo -> Ghc SDoc +extractModuleDeclarations modl mod_info = do + name_ppr_ctx <- Compat.mkNamePprCtxForModule modl mod_info let names = modInfoExports mod_info let sorted_names = List.sortBy (compare `on` nameOccName) names things <- @@ -190,7 +194,7 @@ extractModuleDeclarations moduleName mod_info = do (text "{-# MINIMAL" <+> ppr (classMinimalDef cls) <+> text "#-}") _ -> empty ] - pure $ withUserStyle name_ppr_ctx AllTheWay $ hang (modHeader moduleName) 2 contents <> text "" + pure $ withUserStyle name_ppr_ctx AllTheWay $ hang (modHeader (moduleName modl)) 2 contents <> text "" reportInstances :: Ghc SDoc reportInstances = do From badf9e663d1c06630bf26c258c60757b3dfb159d Mon Sep 17 00:00:00 2001 From: Mann mit Hut Date: Sun, 12 Jan 2025 20:30:53 +0100 Subject: [PATCH 2/2] Ran Fourmolu on PrintApi.CLI.Cmd.Dump --- src/PrintApi/CLI/Cmd/Dump.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/PrintApi/CLI/Cmd/Dump.hs b/src/PrintApi/CLI/Cmd/Dump.hs index 630cd24..e1666a8 100644 --- a/src/PrintApi/CLI/Cmd/Dump.hs +++ b/src/PrintApi/CLI/Cmd/Dump.hs @@ -12,9 +12,9 @@ -- -- The processing of package information module PrintApi.CLI.Cmd.Dump - ( run - , computePackageAPI - ) where + ( run + , computePackageAPI + ) where import Control.Monad.IO.Class import Data.Function (on, (&))