Skip to content

Commit f6623bc

Browse files
committed
9.2 compat for unloading and hie file generation
1 parent 4c84520 commit f6623bc

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ generateObjectCode session summary guts = do
325325
withWarnings "object" $ \tweak -> do
326326
let env' = tweak (hscSetFlags (ms_hspp_opts summary) session)
327327
target = platformDefaultBackend (hsc_dflags env')
328-
newFlags = setBackend target $ updOptLevel 0 $ (hsc_dflags env') { outputFile = Just dot_o }
328+
newFlags = setBackend target $ updOptLevel 0 $ setOutputFile dot_o $ hsc_dflags env'
329329
session' = hscSetFlags newFlags session
330330
#if MIN_VERSION_ghc(9,0,1)
331331
(outputFilename, _mStub, _foreign_files, _cinfos) <- hscGenHardCode session' guts
@@ -454,7 +454,7 @@ atomicFileWrite targetPath write = do
454454

455455
generateHieAsts :: HscEnv -> TcModuleResult -> IO ([FileDiagnostic], Maybe (HieASTs Type))
456456
generateHieAsts hscEnv tcm =
457-
handleGenerationErrors' dflags "extended interface generation" $ runHsc hscEnv $ do
457+
handleGenerationErrors' dflags "extended interface generation" $ runHsc hscEnv $
458458
-- These varBinds use unitDataConId but it could be anything as the id name is not used
459459
-- during the hie file generation process. It's a workaround for the fact that the hie modules
460460
-- don't export an interface which allows for additional information to be added to hie files.
@@ -465,9 +465,13 @@ generateHieAsts hscEnv tcm =
465465
top_ev_binds = tcg_ev_binds ts :: Util.Bag EvBind
466466
insts = tcg_insts ts :: [ClsInst]
467467
tcs = tcg_tcs ts :: [TyCon]
468-
Just <$> GHC.enrichHie (fake_splice_binds `Util.unionBags` real_binds) (tmrRenamed tcm) top_ev_binds insts tcs
468+
in
469+
#if MIN_VERSION_ghc(9,2,0)
470+
fmap (join . snd) $ liftIO $ initDs hscEnv ts $
471+
#endif
472+
Just <$> GHC.enrichHie (fake_splice_binds `Util.unionBags` real_binds) (tmrRenamed tcm) top_ev_binds insts tcs
469473
#else
470-
Just <$> GHC.enrichHie (fake_splice_binds `Util.unionBags` real_binds) (tmrRenamed tcm)
474+
in Just <$> GHC.enrichHie (fake_splice_binds `Util.unionBags` real_binds) (tmrRenamed tcm)
471475
#endif
472476
where
473477
dflags = hsc_dflags hscEnv

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ module Development.IDE.GHC.Compat.Core (
3434
refLevelHoleFits,
3535
maxRefHoleFits,
3636
maxValidHoleFits,
37+
setOutputFile,
3738
#if MIN_VERSION_ghc(8,8,0)
3839
CommandLineOption,
3940
#if !MIN_VERSION_ghc(9,2,0)
@@ -237,7 +238,7 @@ module Development.IDE.GHC.Compat.Core (
237238
-- * Linker
238239
Unlinked(..),
239240
Linkable(..),
240-
Linker.unload,
241+
unload,
241242
initDynLinker,
242243
-- * Hooks
243244
Hooks,
@@ -502,7 +503,7 @@ import GHC.IfaceToCore
502503
import GHC.Parser
503504
import GHC.Parser.Header hiding (getImports)
504505
#if MIN_VERSION_ghc(9,2,0)
505-
import GHC.Linker.Loader as Linker
506+
import qualified GHC.Linker.Loader as Linker
506507
import GHC.Linker.Types
507508
import GHC.Parser.Lexer hiding (initParserState)
508509
import GHC.Platform.Ways
@@ -930,3 +931,20 @@ loadDLL env =
930931
#else
931932
GHCi.loadDLL (GHCi.hscInterp env)
932933
#endif
934+
935+
unload :: HscEnv -> [Linkable] -> IO ()
936+
unload hsc_env linkables =
937+
Linker.unload
938+
#if MIN_VERSION_ghc(9,2,0)
939+
(GHCi.hscInterp hsc_env)
940+
#endif
941+
hsc_env linkables
942+
943+
setOutputFile :: FilePath -> DynFlags -> DynFlags
944+
setOutputFile f d = d {
945+
#if MIN_VERSION_ghc(9,2,0)
946+
outputFile_ = Just f
947+
#else
948+
outputFile = Just f
949+
#endif
950+
}

0 commit comments

Comments
 (0)