Skip to content

Commit b7e69c7

Browse files
committed
Support GHC 9.12.1
1 parent 78bd292 commit b7e69c7

File tree

6 files changed

+84
-24
lines changed

6 files changed

+84
-24
lines changed

compat/9.10.1/GHC/Compat.hs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1-
-- GHC 9.10.1 Compatibility
2-
module GHC.Compat where
1+
-- GHC 9.10.1 compatibility
2+
module GHC.Compat
3+
( mkNamePprCtxForModule
4+
, mkShowSub
5+
) where
36

4-
import GHC (ModuleInfo)
7+
import Data.Maybe (fromJust)
8+
import GHC (Ghc, Module, ModuleInfo, NamePprCtx)
9+
import GHC qualified
510
import GHC.Iface.Syntax (AltPpr (..), ShowForAllFlag (..), ShowHowMuch (..), ShowSub (..))
611

712
import PrintApi.IgnoredDeclarations
813

14+
mkNamePprCtxForModule :: Module -> ModuleInfo -> Ghc NamePprCtx
15+
mkNamePprCtxForModule _ mod_info = fromJust <$> GHC.mkNamePprCtxForModule mod_info
16+
917
mkShowSub :: ModuleInfo -> ShowSub
1018
mkShowSub mod_info =
1119
let ss_how_much = ShowSome (Just (showOcc mod_info)) (AltPpr Nothing)

compat/9.12.1/GHC/Compat.hs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
-- GHC 9.12.1 compatibility
2+
module GHC.Compat
3+
( GHC.mkNamePprCtxForModule
4+
, mkShowSub
5+
) where
6+
7+
import GHC (ModuleInfo)
8+
import GHC qualified
9+
import GHC.Iface.Syntax (AltPpr (..), ShowForAllFlag (..), ShowHowMuch (..), ShowSub (..))
10+
11+
import PrintApi.IgnoredDeclarations
12+
13+
mkShowSub :: ModuleInfo -> ShowSub
14+
mkShowSub mod_info =
15+
let ss_how_much = ShowSome (Just (showOcc mod_info)) (AltPpr Nothing)
16+
in ShowSub
17+
{ ss_how_much = ss_how_much
18+
, ss_forall = ShowForAllMust
19+
}

compat/9.6.6/GHC/Compat.hs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
-- GHC 9.6.6 Compatibility
2-
module GHC.Compat where
1+
-- GHC 9.6.6 compatibility
2+
module GHC.Compat
3+
( mkNamePprCtxForModule
4+
, mkShowSub
5+
) where
36

4-
import GHC (ModuleInfo)
7+
import Data.Maybe (fromJust)
8+
import GHC (Ghc, Module, ModuleInfo, NamePprCtx)
9+
import GHC qualified
510
import GHC.Iface.Syntax (AltPpr (..), ShowForAllFlag (..), ShowHowMuch (..), ShowSub (..))
611

12+
mkNamePprCtxForModule :: Module -> ModuleInfo -> Ghc NamePprCtx
13+
mkNamePprCtxForModule _ mod_info = fromJust <$> GHC.mkNamePprCtxForModule mod_info
14+
715
mkShowSub :: ModuleInfo -> ShowSub
816
mkShowSub _mod_info =
917
let ss_how_much = ShowSome [] (AltPpr Nothing)

compat/9.8.4/GHC/Compat.hs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
-- GHC 9.10.1 Compatibility
2-
module GHC.Compat where
1+
-- GHC 9.8.4 compatibility
2+
module GHC.Compat
3+
( mkNamePprCtxForModule
4+
, mkShowSub
5+
) where
36

4-
import GHC (ModuleInfo)
7+
import Data.Maybe (fromJust)
8+
import GHC (Ghc, Module, ModuleInfo, NamePprCtx)
9+
import GHC qualified
510
import GHC.Iface.Syntax (AltPpr (..), ShowForAllFlag (..), ShowHowMuch (..), ShowSub (..))
6-
import PrintApi.IgnoredDeclarations ()
11+
12+
mkNamePprCtxForModule :: Module -> ModuleInfo -> Ghc NamePprCtx
13+
mkNamePprCtxForModule _ mod_info = fromJust <$> GHC.mkNamePprCtxForModule mod_info
714

815
mkShowSub :: ModuleInfo -> ShowSub
916
mkShowSub _ =

print-api.cabal

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ maintainer: hecate+github@glitchbra.in
1212
copyright: © 2023 Ben Gamari, 2024 Hécate Kleidukos
1313
extra-source-files:
1414
compat/9.10.1/GHC/Compat.hs
15+
compat/9.12.1/GHC/Compat.hs
1516
compat/9.6.6/GHC/Compat.hs
1617
compat/9.8.4/GHC/Compat.hs
1718

18-
tested-with: GHC ==9.6.6 || ==9.8.4 || ==9.10.1
19+
tested-with: GHC ==9.6.6 || ==9.8.4 || ==9.10.1 || ==9.12.1
1920

2021
common extensions
2122
default-extensions:
@@ -69,14 +70,17 @@ library
6970
import: ghc-options
7071
hs-source-dirs: src
7172

72-
if impl(ghc ==9.10.1)
73-
hs-source-dirs: compat/9.10.1
73+
if impl(ghc ==9.6.6)
74+
hs-source-dirs: compat/9.6.6
7475

7576
if impl(ghc ==9.8.4)
7677
hs-source-dirs: compat/9.8.4
7778

78-
if impl(ghc ==9.6.6)
79-
hs-source-dirs: compat/9.6.6
79+
if impl(ghc ==9.10.1)
80+
hs-source-dirs: compat/9.10.1
81+
82+
if impl(ghc ==9.12.1)
83+
hs-source-dirs: compat/9.12.1
8084

8185
other-modules: Paths_print_api
8286
autogen-modules: Paths_print_api
@@ -148,6 +152,16 @@ executable print-api-9.10.1
148152
else
149153
buildable: False
150154

155+
executable print-api-9.12.1
156+
import: print-api-common
157+
main-is: Main.hs
158+
159+
if impl(ghc ==9.12.1)
160+
buildable: True
161+
162+
else
163+
buildable: False
164+
151165
test-suite print-api-test
152166
import: extensions
153167
import: ghc-options

src/PrintApi/CLI/Cmd/Dump.hs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
-- Visibility : Public
1212
--
1313
-- The processing of package information
14-
module PrintApi.CLI.Cmd.Dump where
14+
module PrintApi.CLI.Cmd.Dump
15+
( run
16+
, computePackageAPI
17+
) where
1518

1619
import Control.Monad.IO.Class
1720
import Data.Function (on, (&))
@@ -23,14 +26,15 @@ import Data.Text (Text)
2326
import Data.Text qualified as Text
2427
import Data.Text.Encoding qualified as TE
2528
import GHC
26-
( ModuleInfo
29+
( Module
30+
, ModuleInfo
2731
, getModuleInfo
2832
, getNamePprCtx
2933
, lookupName
3034
, lookupQualifiedModule
31-
, mkNamePprCtxForModule
3235
, modInfoExports
3336
, modInfoIface
37+
, moduleName
3438
, parseDynamicFlags
3539
, runGhc
3640
, setProgramDynFlags
@@ -157,13 +161,13 @@ reportModuleDecls usePublicOnly userIgnoredModules unitId moduleName
157161
if usePublicOnly
158162
then
159163
if isVisible docs
160-
then extractModuleDeclarations moduleName mod_info
164+
then extractModuleDeclarations modl mod_info
161165
else pure empty
162-
else extractModuleDeclarations moduleName mod_info
166+
else extractModuleDeclarations modl mod_info
163167

164-
extractModuleDeclarations :: ModuleName -> ModuleInfo -> Ghc SDoc
165-
extractModuleDeclarations moduleName mod_info = do
166-
Just name_ppr_ctx <- mkNamePprCtxForModule mod_info
168+
extractModuleDeclarations :: Module -> ModuleInfo -> Ghc SDoc
169+
extractModuleDeclarations modl mod_info = do
170+
name_ppr_ctx <- Compat.mkNamePprCtxForModule modl mod_info
167171
let names = modInfoExports mod_info
168172
let sorted_names = List.sortBy (compare `on` nameOccName) names
169173
things <-
@@ -190,7 +194,7 @@ extractModuleDeclarations moduleName mod_info = do
190194
(text "{-# MINIMAL" <+> ppr (classMinimalDef cls) <+> text "#-}")
191195
_ -> empty
192196
]
193-
pure $ withUserStyle name_ppr_ctx AllTheWay $ hang (modHeader moduleName) 2 contents <> text ""
197+
pure $ withUserStyle name_ppr_ctx AllTheWay $ hang (modHeader (moduleName modl)) 2 contents <> text ""
194198

195199
reportInstances :: Ghc SDoc
196200
reportInstances = do

0 commit comments

Comments
 (0)