Skip to content

Commit 89e6d19

Browse files
committed
Unify defintions of ghcSessionDeps
1 parent 69b580f commit 89e6d19

File tree

2 files changed

+29
-39
lines changed

2 files changed

+29
-39
lines changed

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

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -689,27 +689,29 @@ loadGhcSession = do
689689
Nothing -> LBS.toStrict $ B.encode (hash (snd val))
690690
return (Just cutoffHash, val)
691691

692-
defineNoDiagnostics $ \GhcSessionDeps file -> Just <$> ghcSessionDepsDefinition file
693-
694-
ghcSessionDepsDefinition :: NormalizedFilePath -> Action HscEnvEq
695-
ghcSessionDepsDefinition file = do
692+
defineNoDiagnostics $ \GhcSessionDeps file -> do
696693
env <- use_ GhcSession file
697-
let hsc = hscEnv env
698-
deps <- mapMaybe (fmap artifactFilePath . snd) <$> use_ GetLocatedImports file
699-
ms:mss <- map msrModSummary <$> uses_ GetModSummaryWithoutTimestamps (file:deps)
700-
701-
depSessions <- map hscEnv <$> uses_ GhcSessionDeps deps
702-
let uses_th_qq =
703-
xopt LangExt.TemplateHaskell dflags || xopt LangExt.QuasiQuotes dflags
704-
dflags = ms_hspp_opts ms
705-
ifaces <- if uses_th_qq
706-
then uses_ GetModIface deps
707-
else uses_ GetModIfaceWithoutLinkable deps
708-
709-
let inLoadOrder = map hirHomeMod ifaces
710-
session' <- liftIO $ mergeEnvs hsc mss inLoadOrder depSessions
711-
712-
liftIO $ newHscEnvEqWithImportPaths (envImportPaths env) session' []
694+
Just <$> ghcSessionDepsDefinition False env file
695+
696+
ghcSessionDepsDefinition :: Bool -> HscEnvEq -> NormalizedFilePath -> Action HscEnvEq
697+
ghcSessionDepsDefinition forceLinkable env file = do
698+
let hsc = hscEnv env
699+
deps <- mapMaybe (fmap artifactFilePath . snd) <$> use_ GetLocatedImports file
700+
_ <- uses_ ReportImportCycles deps
701+
ms:mss <- map msrModSummary <$> uses_ GetModSummaryWithoutTimestamps (file:deps)
702+
703+
depSessions <- map hscEnv <$> uses_ GhcSessionDeps deps
704+
let uses_th_qq =
705+
xopt LangExt.TemplateHaskell dflags || xopt LangExt.QuasiQuotes dflags
706+
dflags = ms_hspp_opts ms
707+
ifaces <- if uses_th_qq || forceLinkable
708+
then uses_ GetModIface deps
709+
else uses_ GetModIfaceWithoutLinkable deps
710+
711+
let inLoadOrder = map hirHomeMod ifaces
712+
session' <- liftIO $ mergeEnvs hsc mss inLoadOrder depSessions
713+
714+
liftIO $ newHscEnvEqWithImportPaths (envImportPaths env) session' []
713715

714716
-- | Load a iface from disk, or generate it if there isn't one or it is out of date
715717
-- This rule also ensures that the `.hie` and `.o` (if needed) files are written out.

plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ import Development.IDE (Action, GetDependencies (..),
5252
HscEnvEq, IdeState,
5353
ModSummaryResult (..),
5454
NeedsCompilation (NeedsCompilation),
55-
evalGhcEnv,
55+
evalGhcEnv, hscEnv,
5656
hscEnvWithImportPaths,
5757
prettyPrint, runAction,
5858
textToStringBuffer,
@@ -61,7 +61,8 @@ import Development.IDE (Action, GetDependencies (..),
6161
useWithStale_, use_, uses_)
6262
import Development.IDE.Core.Compile (loadModulesHome,
6363
setupFinderCache)
64-
import Development.IDE.Core.Rules (TransitiveDependencies (transitiveModuleDeps))
64+
import Development.IDE.Core.Rules (TransitiveDependencies (transitiveModuleDeps),
65+
ghcSessionDepsDefinition)
6566
import Development.IDE.GHC.Compat hiding (typeKind, unitState)
6667
import qualified Development.IDE.GHC.Compat as Compat
6768
import qualified Development.IDE.GHC.Compat as SrcLoc
@@ -533,30 +534,17 @@ prettyWarn Warn{..} =
533534
prettyPrint (SrcLoc.getLoc warnMsg) <> ": warning:\n"
534535
<> " " <> SrcLoc.unLoc warnMsg
535536

536-
ghcSessionDepsDefinition :: HscEnvEq -> NormalizedFilePath -> Action HscEnv
537-
ghcSessionDepsDefinition env file = do
538-
let hsc = hscEnvWithImportPaths env
539-
deps <- use_ GetDependencies file
540-
let tdeps = transitiveModuleDeps deps
541-
ifaces <- uses_ GetModIface tdeps
542-
liftIO $ assert (all (isJust . hm_linkable . hirHomeMod) ifaces) $ pure ()
543-
544-
-- Currently GetDependencies returns things in topological order so A comes before B if A imports B.
545-
-- We need to reverse this as GHC gets very unhappy otherwise and complains about broken interfaces.
546-
-- Long-term we might just want to change the order returned by GetDependencies
547-
let inLoadOrder = reverse (map hirHomeMod ifaces)
548-
549-
liftIO $ loadModulesHome inLoadOrder <$> setupFinderCache (map hirModSummary ifaces) hsc
550-
551537
runGetSession :: MonadIO m => IdeState -> NormalizedFilePath -> m HscEnv
552538
runGetSession st nfp = liftIO $ runAction "eval" st $ do
553539
-- Create a new GHC Session rather than reusing an existing one
554540
-- to avoid interfering with ghcide
541+
-- UPDATE: I suspect that this doesn't really work, we always get the same Session
542+
-- we probably cache hscEnvs in the Session state
555543
IdeGhcSession{loadSessionFun} <- useNoFile_ GhcSessionIO
556544
let fp = fromNormalizedFilePath nfp
557545
((_, res),_) <- liftIO $ loadSessionFun fp
558-
let hscEnv = fromMaybe (error $ "Unknown file: " <> fp) res
559-
ghcSessionDepsDefinition hscEnv nfp
546+
let env = fromMaybe (error $ "Unknown file: " <> fp) res
547+
hscEnv <$> ghcSessionDepsDefinition False env nfp
560548

561549
needsQuickCheck :: [(Section, Test)] -> Bool
562550
needsQuickCheck = any (isProperty . snd)

0 commit comments

Comments
 (0)