Skip to content

Commit 5ddc93a

Browse files
authored
Add GHC 9.2 support for hie-compat (#2003)
* Add GHC 9.2 support hie-compat * Remove mkHieFile from public API Then we can share the module re-exports for GHC >= 9
1 parent 9207050 commit 5ddc93a

File tree

11 files changed

+15
-128
lines changed

11 files changed

+15
-128
lines changed

Diff for: ghcide/src/Development/IDE/GHC/Compat.hs

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ module Development.IDE.GHC.Compat(
1414
HieFile(..),
1515
NameCacheUpdater(..),
1616
hieExportNames,
17-
mkHieFile,
1817
mkHieFile',
1918
enrichHie,
2019
writeHieFile,
@@ -159,7 +158,7 @@ import Module (InstalledUnitId,
159158
toInstalledUnitId)
160159
import TcType (pprSigmaType)
161160
#endif
162-
import Compat.HieAst (enrichHie, mkHieFile)
161+
import Compat.HieAst (enrichHie)
163162
import Compat.HieBin
164163
import Compat.HieTypes
165164
import Compat.HieUtils

Diff for: hie-compat/hie-compat.cabal

+6-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ library
3030
build-depends: ghc, ghc-boot
3131
if (impl(ghc >= 9.0) && impl(ghc < 9.1))
3232
ghc-options: -Wall -Wno-name-shadowing
33+
else
34+
ghc-options: -Wall -Wno-name-shadowing
3335

3436
exposed-modules:
3537
Compat.HieAst
@@ -45,5 +47,8 @@ library
4547
if (impl(ghc > 8.9) && impl(ghc < 8.11))
4648
hs-source-dirs: src-ghc810 src-reexport
4749
if (impl(ghc >= 9.0) && impl(ghc < 9.1) || flag(ghc-lib))
48-
hs-source-dirs: src-ghc901
50+
hs-source-dirs: src-reexport-ghc9
51+
if (impl(ghc >= 9.2) && impl(ghc < 9.3))
52+
hs-source-dirs: src-reexport-ghc9
53+
4954

Diff for: hie-compat/src-ghc810/Compat/HieAst.hs

+2-31
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Main functions for .hie file generation
1717
{-# LANGUAGE AllowAmbiguousTypes #-}
1818
{-# LANGUAGE ViewPatterns #-}
1919
{-# LANGUAGE DeriveDataTypeable #-}
20-
module Compat.HieAst ( mkHieFile, enrichHie ) where
20+
module Compat.HieAst ( enrichHie ) where
2121

2222
import GhcPrelude
2323

@@ -32,7 +32,7 @@ import Desugar ( deSugarExpr )
3232
import FieldLabel
3333
import GHC.Hs
3434
import HscTypes
35-
import Module ( ModuleName, ml_hs_file )
35+
import Module ( ModuleName )
3636
import MonadUtils ( concatMapM, liftIO )
3737
import Name ( Name, nameSrcSpan )
3838
import NameEnv ( NameEnv, emptyNameEnv, extendNameEnv, lookupNameEnv )
@@ -41,15 +41,11 @@ import TcHsSyn ( hsLitType, hsPatType )
4141
import Type ( mkVisFunTys, Type )
4242
import TysWiredIn ( mkListTy, mkSumTy )
4343
import Var ( Id, Var, setVarName, varName, varType )
44-
import TcRnTypes
45-
import MkIface ( mkIfaceExports )
4644
import Panic
4745

4846
import HieTypes
4947
import HieUtils
5048

51-
import qualified Data.Array as A
52-
import qualified Data.ByteString as BS
5349
import qualified Data.Map as M
5450
import qualified Data.Set as S
5551
import Data.Data ( Data, Typeable )
@@ -223,31 +219,6 @@ modifyState = foldr go id
223219

224220
type HieM = ReaderT HieState Hsc
225221

226-
-- | Construct an 'HieFile' from the outputs of the typechecker.
227-
mkHieFile :: ModSummary
228-
-> TcGblEnv
229-
-> RenamedSource
230-
-> BS.ByteString -> Hsc HieFile
231-
mkHieFile ms ts rs src = do
232-
let tc_binds = tcg_binds ts
233-
(asts', arr) <- getCompressedAsts tc_binds rs
234-
let Just src_file = ml_hs_file $ ms_location ms
235-
return $ HieFile
236-
{ hie_hs_file = src_file
237-
, hie_module = ms_mod ms
238-
, hie_types = arr
239-
, hie_asts = asts'
240-
-- mkIfaceExports sorts the AvailInfos for stability
241-
, hie_exports = mkIfaceExports (tcg_exports ts)
242-
, hie_hs_src = src
243-
}
244-
245-
getCompressedAsts :: TypecheckedSource -> RenamedSource
246-
-> Hsc (HieASTs TypeIndex, A.Array TypeIndex HieTypeFlat)
247-
getCompressedAsts ts rs = do
248-
asts <- enrichHie ts rs
249-
return $ compressTypes asts
250-
251222
enrichHie :: TypecheckedSource -> RenamedSource -> Hsc (HieASTs Type)
252223
enrichHie ts (hsGrp, imports, exports, _) = flip runReaderT initState $ do
253224
tasts <- toHie $ fmap (BC RegularBind ModuleScope) ts

Diff for: hie-compat/src-ghc86/Compat/HieAst.hs

+2-32
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Main functions for .hie file generation
1717
{-# LANGUAGE ViewPatterns #-}
1818
{-# LANGUAGE DeriveDataTypeable #-}
1919
{-# LANGUAGE DataKinds #-}
20-
module Compat.HieAst ( mkHieFile, enrichHie ) where
20+
module Compat.HieAst ( enrichHie ) where
2121

2222
import Avail ( Avails )
2323
import Bag ( Bag, bagToList )
@@ -30,22 +30,18 @@ import Desugar ( deSugarExpr )
3030
import FieldLabel
3131
import HsSyn
3232
import HscTypes
33-
import Module ( ModuleName, ml_hs_file )
33+
import Module ( ModuleName )
3434
import MonadUtils ( concatMapM, liftIO )
3535
import Name ( Name, nameSrcSpan )
3636
import SrcLoc
3737
import TcHsSyn ( hsLitType, hsPatType )
3838
import Type ( mkFunTys, Type )
3939
import TysWiredIn ( mkListTy, mkSumTy )
4040
import Var ( Id, Var, setVarName, varName, varType )
41-
import TcRnTypes
42-
import MkIface ( mkIfaceExports )
4341

4442
import Compat.HieTypes
4543
import Compat.HieUtils
4644

47-
import qualified Data.Array as A
48-
import qualified Data.ByteString as BS
4945
import qualified Data.Map as M
5046
import qualified Data.Set as S
5147
import Data.Data ( Data, Typeable )
@@ -101,32 +97,6 @@ modifyState = foldr go id
10197

10298
type HieM = ReaderT HieState Hsc
10399

104-
-- | Construct an 'HieFile' from the outputs of the typechecker.
105-
mkHieFile :: ModSummary
106-
-> TcGblEnv
107-
-> RenamedSource
108-
-> BS.ByteString
109-
-> Hsc HieFile
110-
mkHieFile ms ts rs src = do
111-
let tc_binds = tcg_binds ts
112-
(asts', arr) <- getCompressedAsts tc_binds rs
113-
let Just src_file = ml_hs_file $ ms_location ms
114-
return $ HieFile
115-
{ hie_hs_file = src_file
116-
, hie_module = ms_mod ms
117-
, hie_types = arr
118-
, hie_asts = asts'
119-
-- mkIfaceExports sorts the AvailInfos for stability
120-
, hie_exports = mkIfaceExports (tcg_exports ts)
121-
, hie_hs_src = src
122-
}
123-
124-
getCompressedAsts :: TypecheckedSource -> RenamedSource
125-
-> Hsc (HieASTs TypeIndex, A.Array TypeIndex HieTypeFlat)
126-
getCompressedAsts ts rs = do
127-
asts <- enrichHie ts rs
128-
return $ compressTypes asts
129-
130100
enrichHie :: TypecheckedSource -> RenamedSource -> Hsc (HieASTs Type)
131101
enrichHie ts (hsGrp, imports, exports, _) = flip runReaderT initState $ do
132102
tasts <- toHie $ fmap (BC RegularBind ModuleScope) ts

Diff for: hie-compat/src-ghc88/Compat/HieAst.hs

+1-27
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Main functions for .hie file generation
1616
{-# LANGUAGE AllowAmbiguousTypes #-}
1717
{-# LANGUAGE ViewPatterns #-}
1818
{-# LANGUAGE DeriveDataTypeable #-}
19-
module Compat.HieAst ( mkHieFile, enrichHie ) where
19+
module Compat.HieAst ( enrichHie ) where
2020

2121
import Avail ( Avails )
2222
import Bag ( Bag, bagToList )
@@ -90,32 +90,6 @@ modifyState = foldr go id
9090

9191
type HieM = ReaderT HieState Hsc
9292

93-
-- | Construct an 'HieFile' from the outputs of the typechecker.
94-
mkHieFile :: ModSummary
95-
-> TcGblEnv
96-
-> RenamedSource
97-
-> BS.ByteString
98-
-> Hsc HieFile
99-
mkHieFile ms ts rs src = do
100-
let tc_binds = tcg_binds ts
101-
(asts', arr) <- getCompressedAsts tc_binds rs
102-
let Just src_file = ml_hs_file $ ms_location ms
103-
return $ HieFile
104-
{ hie_hs_file = src_file
105-
, hie_module = ms_mod ms
106-
, hie_types = arr
107-
, hie_asts = asts'
108-
-- mkIfaceExports sorts the AvailInfos for stability
109-
, hie_exports = mkIfaceExports (tcg_exports ts)
110-
, hie_hs_src = src
111-
}
112-
113-
getCompressedAsts :: TypecheckedSource -> RenamedSource
114-
-> Hsc (HieASTs TypeIndex, A.Array TypeIndex HieTypeFlat)
115-
getCompressedAsts ts rs = do
116-
asts <- enrichHie ts rs
117-
return $ compressTypes asts
118-
11993
enrichHie :: TypecheckedSource -> RenamedSource -> Hsc (HieASTs Type)
12094
enrichHie ts (hsGrp, imports, exports, _) = flip runReaderT initState $ do
12195
tasts <- toHie $ fmap (BC RegularBind ModuleScope) ts

Diff for: hie-compat/src-ghc901/Compat/HieAst.hs

-35
This file was deleted.

Diff for: hie-compat/src-reexport-ghc9/Compat/HieAst.hs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module Compat.HieAst ( enrichHie ) where
2+
3+
import GHC.Iface.Ext.Ast (enrichHie)

0 commit comments

Comments
 (0)