Skip to content

Commit 0a411e2

Browse files
committed
9.2 compat for Development.IDE.Core.Compile
1 parent b430b94 commit 0a411e2

File tree

2 files changed

+74
-12
lines changed

2 files changed

+74
-12
lines changed

ghcide/src/Development/IDE/Core/Compile.hs

Lines changed: 61 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ import GHC.Tc.Gen.Splice
6868
import TcSplice
6969
#endif
7070

71+
#if MIN_VERSION_ghc(9,2,0)
72+
import qualified GHC.Types.Error as Error
73+
#endif
74+
7175
import Control.Exception (evaluate)
7276
import Control.Exception.Safe
7377
import Control.Lens hiding (List)
@@ -80,6 +84,7 @@ import qualified Data.DList as DL
8084
import Data.IORef
8185
import Data.List.Extra
8286
import qualified Data.Map.Strict as Map
87+
import qualified Data.IntMap.Strict as IntMap
8388
import Data.Maybe
8489
import qualified Data.Text as T
8590
import Data.Time (UTCTime, getCurrentTime)
@@ -102,6 +107,7 @@ import Data.Coerce
102107
import Data.Functor
103108
import qualified Data.HashMap.Strict as HashMap
104109
import Data.Map (Map)
110+
import Data.IntMap (IntMap)
105111
import Data.Tuple.Extra (dupe)
106112
import Data.Unique as Unique
107113
import Development.IDE.Core.Tracing (withTrace)
@@ -676,14 +682,23 @@ mergeEnvs env extraModSummaries extraMods envs = do
676682
prevFinderCache <- concatFC <$> mapM (readIORef . hsc_FC) envs
677683
let ims = map (Compat.installedModule (homeUnitId_ $ hsc_dflags env) . moduleName . ms_mod) extraModSummaries
678684
ifrs = zipWith (\ms -> InstalledFound (ms_location ms)) extraModSummaries ims
685+
-- We don't do any instantiation for backpack at this point of time, so it is OK to use
686+
-- 'extendModSummaryNoDeps'.
687+
-- This may have to change in the future.
688+
module_graph_nodes =
689+
#if MIN_VERSION_ghc(9,2,0)
690+
map extendModSummaryNoDeps $
691+
#endif
692+
extraModSummaries ++ nubOrdOn ms_mod (concatMap (mgModSummaries . hsc_mod_graph) envs)
693+
679694
newFinderCache <- newIORef $
680695
foldl'
681696
(\fc (im, ifr) -> Compat.extendInstalledModuleEnv fc im ifr) prevFinderCache
682697
$ zip ims ifrs
683698
return $ loadModulesHome extraMods $ env{
684699
hsc_HPT = foldMapBy mergeUDFM emptyUDFM hsc_HPT envs,
685700
hsc_FC = newFinderCache,
686-
hsc_mod_graph = mkModuleGraph $ extraModSummaries ++ nubOrdOn ms_mod (concatMap (mgModSummaries . hsc_mod_graph) envs)
701+
hsc_mod_graph = mkModuleGraph module_graph_nodes
687702
}
688703
where
689704
mergeUDFM = plusUDFM_C combineModules
@@ -732,8 +747,9 @@ getModSummaryFromImports env fp modTime contents = do
732747
implicit_prelude = xopt LangExt.ImplicitPrelude dflags
733748
implicit_imports = mkPrelImports mod main_loc
734749
implicit_prelude imps
750+
735751
convImport (L _ i) = (fmap sl_fs (ideclPkgQual i)
736-
, ideclName i)
752+
, reLoc $ ideclName i)
737753

738754
srcImports = map convImport src_idecls
739755
textualImports = map convImport (implicit_imports ++ ordinary_imps)
@@ -805,13 +821,23 @@ parseHeader dflags filename contents = do
805821
case unP Compat.parseHeader (initParserState (initParserOpts dflags) contents loc) of
806822
#if MIN_VERSION_ghc(8,10,0)
807823
PFailed pst ->
808-
throwE $ diagFromErrMsgs "parser" dflags $ getErrorMessages pst dflags
824+
throwE $ diagFromErrMsgs "parser" dflags
825+
#if MIN_VERSION_ghc(9,2,0)
826+
$ fmap pprError
827+
#endif
828+
$ getErrorMessages pst
829+
#if !MIN_VERSION_ghc(9,2,0)
830+
dflags
831+
#endif
809832
#else
810833
PFailed _ locErr msgErr ->
811834
throwE $ diagFromErrMsg "parser" dflags $ mkPlainErrMsg dflags locErr msgErr
812835
#endif
813836
POk pst rdr_module -> do
814-
let (warns, errs) = getMessages pst dflags
837+
let (warns, errs) = getMessages pst
838+
#if !MIN_VERSION_ghc(9,2,0)
839+
dflags
840+
#endif
815841
-- Just because we got a `POk`, it doesn't mean there
816842
-- weren't errors! To clarify, the GHC parser
817843
-- distinguishes between fatal and non-fatal
@@ -842,15 +868,30 @@ parseFileContents env customPreprocessor filename ms = do
842868
contents = fromJust $ ms_hspp_buf ms
843869
case unP Compat.parseModule (initParserState (initParserOpts dflags) contents loc) of
844870
#if MIN_VERSION_ghc(8,10,0)
845-
PFailed pst -> throwE $ diagFromErrMsgs "parser" dflags $ getErrorMessages pst dflags
871+
PFailed pst -> throwE
872+
$ diagFromErrMsgs "parser" dflags
873+
#if MIN_VERSION_ghc(9,2,0)
874+
$ fmap pprError
875+
#endif
876+
$ getErrorMessages pst
877+
#if !MIN_VERSION_ghc(9,2,0)
878+
$ dflags
879+
#endif
846880
#else
847881
PFailed _ locErr msgErr ->
848882
throwE $ diagFromErrMsg "parser" dflags $ mkPlainErrMsg dflags locErr msgErr
849883
#endif
850884
POk pst rdr_module ->
851885
let
852886
hpm_annotations = mkApiAnns pst
853-
(warns, errs) = getMessages pst dflags
887+
(warns, errs) = id
888+
#if MIN_VERSION_ghc(9,2,0)
889+
$ bimap (fmap pprWarning) (fmap pprError)
890+
#endif
891+
$ getMessages pst
892+
#if !MIN_VERSION_ghc(9,2,0)
893+
$ dflags
894+
#endif
854895
in
855896
do
856897
-- Just because we got a `POk`, it doesn't mean there
@@ -977,23 +1018,31 @@ getDocsBatch
9771018
:: HscEnv
9781019
-> Module -- ^ a moudle where the names are in scope
9791020
-> [Name]
980-
-> IO [Either String (Maybe HsDocString, Map.Map Int HsDocString)]
1021+
-> IO [Either String (Maybe HsDocString, IntMap HsDocString)]
9811022
getDocsBatch hsc_env _mod _names = do
982-
((_warns,errs), res) <- initTc hsc_env HsSrcFile False _mod fakeSpan $ forM _names $ \name ->
1023+
(msgs, res) <- initTc hsc_env HsSrcFile False _mod fakeSpan $ forM _names $ \name ->
9831024
case nameModule_maybe name of
9841025
Nothing -> return (Left $ NameHasNoModule name)
9851026
Just mod -> do
9861027
ModIface { mi_doc_hdr = mb_doc_hdr
9871028
, mi_decl_docs = DeclDocMap dmap
9881029
, mi_arg_docs = ArgDocMap amap
9891030
} <- loadModuleInterface "getModuleInterface" mod
990-
if isNothing mb_doc_hdr && Map.null dmap && Map.null amap
1031+
if isNothing mb_doc_hdr && Map.null dmap && null amap
9911032
then pure (Left (NoDocsInIface mod $ compiled name))
992-
else pure (Right ( Map.lookup name dmap
993-
, Map.findWithDefault Map.empty name amap))
1033+
else pure (Right ( Map.lookup name dmap ,
1034+
#if !MIN_VERSION_ghc(9,2,0)
1035+
IntMap.fromAscList $ Map.toAscList $
1036+
#endif
1037+
Map.findWithDefault mempty name amap))
9941038
case res of
9951039
Just x -> return $ map (first $ T.unpack . showGhc) x
996-
Nothing -> throwErrors errs
1040+
Nothing -> throwErrors
1041+
#if MIN_VERSION_ghc(9,2,0)
1042+
$ Error.getErrorMessages msgs
1043+
#else
1044+
$ snd msgs
1045+
#endif
9971046
where
9981047
throwErrors = liftIO . throwIO . mkSrcErr
9991048
compiled n =

ghcide/src/Development/IDE/GHC/Compat.hs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,17 @@ module Development.IDE.GHC.Compat(
1515
setUpTypedHoles,
1616
upNameCache,
1717
disableWarningsAsErrors,
18+
reLoc,
1819

1920
#if !MIN_VERSION_ghc(9,0,1)
2021
RefMap,
2122
#endif
2223

24+
#if MIN_VERSION_ghc(9,2,0)
25+
extendModSummaryNoDeps,
26+
emsModSummary,
27+
#endif
28+
2329
nodeInfo',
2430
getNodeIds,
2531

@@ -72,6 +78,7 @@ import Development.IDE.GHC.Compat.Util
7278
import GHC.Data.StringBuffer
7379
import GHC.Driver.Session hiding (ExposePackage)
7480
#if MIN_VERSION_ghc(9,2,0)
81+
import GHC.Unit.Module.ModSummary
7582
import GHC.Driver.Env as Env
7683
import GHC.Unit.Module.ModIface
7784
#else
@@ -115,6 +122,11 @@ import Data.List (foldl')
115122
import qualified Data.Set as S
116123
#endif
117124

125+
#if !MIN_VERSION_ghc(9,2,0)
126+
reLoc :: Located a -> Located a
127+
reLoc = id
128+
#endif
129+
118130
#if !MIN_VERSION_ghc(8,8,0)
119131
hPutStringBuffer :: Handle -> StringBuffer -> IO ()
120132
hPutStringBuffer hdl (StringBuffer buf len cur)
@@ -128,6 +140,7 @@ supportsHieFiles = True
128140
hieExportNames :: HieFile -> [(SrcSpan, Name)]
129141
hieExportNames = nameListFromAvails . hie_exports
130142

143+
131144
upNameCache :: IORef NameCache -> (NameCache -> (NameCache, c)) -> IO c
132145
#if MIN_VERSION_ghc(8,8,0)
133146
upNameCache = updNameCache

0 commit comments

Comments
 (0)