Skip to content

Commit abebf26

Browse files
authored
Fix regression in GhcSessionDeps (#2380)
* Fix regression in GhcSessionDeps We cannot use GetModIfaceWithoutLinkable since the session might be reused later to load a module that needs linkables Note that this does not have any effects on performance, since GetModIfaceWithoutLinkable is just a synonym for GetModIface that removes the linkable Fixes #2379 * add test files * delete unused bits * Tweak test for compat. with GHC 9.0.1
1 parent b7e3a64 commit abebf26

File tree

9 files changed

+36
-31
lines changed

9 files changed

+36
-31
lines changed

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

-9
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,6 @@ type instance RuleResult GetModIfaceFromDiskAndIndex = HiFileResult
252252
-- | Get a module interface details, either from an interface file or a typechecked module
253253
type instance RuleResult GetModIface = HiFileResult
254254

255-
-- | Get a module interface details, without the Linkable
256-
-- For better early cuttoff
257-
type instance RuleResult GetModIfaceWithoutLinkable = HiFileResult
258-
259255
-- | Get the contents of a file, either dirty (if the buffer is modified) or Nothing to mean use from disk.
260256
type instance RuleResult GetFileContents = (FileVersion, Maybe Text)
261257

@@ -430,11 +426,6 @@ data GetModIface = GetModIface
430426
instance Hashable GetModIface
431427
instance NFData GetModIface
432428

433-
data GetModIfaceWithoutLinkable = GetModIfaceWithoutLinkable
434-
deriving (Eq, Show, Typeable, Generic)
435-
instance Hashable GetModIfaceWithoutLinkable
436-
instance NFData GetModIfaceWithoutLinkable
437-
438429
data IsFileOfInterest = IsFileOfInterest
439430
deriving (Eq, Show, Typeable, Generic)
440431
instance Hashable IsFileOfInterest

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

+4-20
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ module Development.IDE.Core.Rules(
4141
loadGhcSession,
4242
getModIfaceFromDiskRule,
4343
getModIfaceRule,
44-
getModIfaceWithoutLinkableRule,
4544
getModSummaryRule,
4645
isHiFileStableRule,
4746
getModuleGraphRule,
@@ -688,13 +687,11 @@ loadGhcSession ghcSessionDepsConfig = do
688687

689688
data GhcSessionDepsConfig = GhcSessionDepsConfig
690689
{ checkForImportCycles :: Bool
691-
, forceLinkables :: Bool
692690
, fullModSummary :: Bool
693691
}
694692
instance Default GhcSessionDepsConfig where
695693
def = GhcSessionDepsConfig
696694
{ checkForImportCycles = True
697-
, forceLinkables = False
698695
, fullModSummary = False
699696
}
700697

@@ -707,17 +704,12 @@ ghcSessionDepsDefinition GhcSessionDepsConfig{..} env file = do
707704
Nothing -> return Nothing
708705
Just deps -> do
709706
when checkForImportCycles $ void $ uses_ ReportImportCycles deps
710-
ms:mss <- map msrModSummary <$> if fullModSummary
711-
then uses_ GetModSummary (file:deps)
712-
else uses_ GetModSummaryWithoutTimestamps (file:deps)
707+
mss <- map msrModSummary <$> if fullModSummary
708+
then uses_ GetModSummary deps
709+
else uses_ GetModSummaryWithoutTimestamps deps
713710

714711
depSessions <- map hscEnv <$> uses_ GhcSessionDeps deps
715-
let uses_th_qq =
716-
xopt LangExt.TemplateHaskell dflags || xopt LangExt.QuasiQuotes dflags
717-
dflags = ms_hspp_opts ms
718-
ifaces <- if uses_th_qq || forceLinkables
719-
then uses_ GetModIface deps
720-
else uses_ GetModIfaceWithoutLinkable deps
712+
ifaces <- uses_ GetModIface deps
721713

722714
let inLoadOrder = map hirHomeMod ifaces
723715
session' <- liftIO $ mergeEnvs hsc mss inLoadOrder depSessions
@@ -882,13 +874,6 @@ getModIfaceRule = defineEarlyCutoff $ Rule $ \GetModIface f -> do
882874
liftIO $ void $ modifyVar' compiledLinkables $ \old -> extendModuleEnv old mod time
883875
pure res
884876

885-
getModIfaceWithoutLinkableRule :: Rules ()
886-
getModIfaceWithoutLinkableRule = defineEarlyCutoff $ RuleNoDiagnostics $ \GetModIfaceWithoutLinkable f -> do
887-
mhfr <- use GetModIface f
888-
let mhfr' = fmap (\x -> x{ hirHomeMod = (hirHomeMod x){ hm_linkable = Just (error msg) } }) mhfr
889-
msg = "tried to look at linkable for GetModIfaceWithoutLinkable for " ++ show f
890-
pure (hirIfaceFp <$> mhfr', mhfr')
891-
892877
-- | Also generates and indexes the `.hie` file, along with the `.o` file if needed
893878
-- Invariant maintained is that if the `.hi` file was successfully written, then the
894879
-- `.hie` and `.o` file (if needed) were also successfully written
@@ -1089,7 +1074,6 @@ mainRule RulesConfig{..} = do
10891074
getModIfaceFromDiskRule
10901075
getModIfaceFromDiskAndIndexRule
10911076
getModIfaceRule
1092-
getModIfaceWithoutLinkableRule
10931077
getModSummaryRule
10941078
isHiFileStableRule
10951079
getModuleGraphRule

ghcide/test/data/THLoading/A.hs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module A where
2+
import B (bar)
3+
4+
foo :: ()
5+
foo = bar

ghcide/test/data/THLoading/B.hs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module B where
2+
3+
bar :: ()
4+
bar = ()

ghcide/test/data/THLoading/THA.hs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{-# LANGUAGE TemplateHaskell #-}
2+
module THA where
3+
import Language.Haskell.TH
4+
import A (foo)
5+
6+
th_a :: DecsQ
7+
th_a = [d| a = foo |]

ghcide/test/data/THLoading/THB.hs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{-# LANGUAGE TemplateHaskell #-}
2+
module THB where
3+
import THA
4+
5+
$th_a

ghcide/test/data/THLoading/hie.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cradle: {direct: {arguments: ["-package template-haskell", "THA", "THB", "A", "B"]}}

ghcide/test/exe/Main.hs

+9
Original file line numberDiff line numberDiff line change
@@ -4018,6 +4018,7 @@ thTests =
40184018
_ <- createDoc "B.hs" "haskell" sourceB
40194019
return ()
40204020
, thReloadingTest False
4021+
, thLoadingTest
40214022
, ignoreInWindowsBecause "Broken in windows" $ thReloadingTest True
40224023
-- Regression test for https://github.com/haskell/haskell-language-server/issues/891
40234024
, thLinkingTest False
@@ -4055,6 +4056,14 @@ thTests =
40554056
expectDiagnostics [ ( cPath, [(DsWarning, (3, 0), "Top-level binding with no type signature: a :: A")] ) ]
40564057
]
40574058

4059+
-- | Test that all modules have linkables
4060+
thLoadingTest :: TestTree
4061+
thLoadingTest = testCase "Loading linkables" $ runWithExtraFiles "THLoading" $ \dir -> do
4062+
let thb = dir </> "THB.hs"
4063+
_ <- openDoc thb "haskell"
4064+
expectNoMoreDiagnostics 1
4065+
4066+
40584067
-- | test that TH is reevaluated on typecheck
40594068
thReloadingTest :: Bool -> TestTree
40604069
thReloadingTest unboxed = testCase name $ runWithExtraFiles dir $ \dir -> do

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,7 @@ runGetSession st nfp = liftIO $ runAction "eval" st $ do
540540
((_, res),_) <- liftIO $ loadSessionFun fp
541541
let env = fromMaybe (error $ "Unknown file: " <> fp) res
542542
ghcSessionDepsConfig = def
543-
{ forceLinkables = True
544-
, checkForImportCycles = False
543+
{ checkForImportCycles = False
545544
, fullModSummary = True
546545
}
547546
res <- fmap hscEnvWithImportPaths <$> ghcSessionDepsDefinition ghcSessionDepsConfig env nfp

0 commit comments

Comments
 (0)