@@ -22,6 +22,7 @@ module Development.IDE.Core.Rules(
22
22
defineNoFile ,
23
23
defineEarlyCutOffNoFile ,
24
24
mainRule ,
25
+ RulesConfig (.. ),
25
26
getDependencies ,
26
27
getParsedModule ,
27
28
getParsedModuleWithComments ,
@@ -56,6 +57,7 @@ module Development.IDE.Core.Rules(
56
57
ghcSessionDepsDefinition ,
57
58
getParsedModuleDefinition ,
58
59
typeCheckRuleDefinition ,
60
+ GhcSessionDepsConfig (.. ),
59
61
) where
60
62
61
63
#if !MIN_VERSION_ghc(8,8,0)
@@ -138,7 +140,7 @@ import qualified Language.LSP.Server as LSP
138
140
import Language.LSP.Types (SMethod (SCustomMethod ))
139
141
import Language.LSP.VFS
140
142
import System.Directory (canonicalizePath , makeAbsolute )
141
- import Data.Default (def )
143
+ import Data.Default (def , Default )
142
144
import Ide.Plugin.Properties (HasProperty ,
143
145
KeyNameProxy ,
144
146
Properties ,
@@ -640,8 +642,8 @@ currentLinkables = do
640
642
where
641
643
go (mod , time) = LM time mod []
642
644
643
- loadGhcSession :: Rules ()
644
- loadGhcSession = do
645
+ loadGhcSession :: GhcSessionDepsConfig -> Rules ()
646
+ loadGhcSession ghcSessionDepsConfig = do
645
647
-- This function should always be rerun because it tracks changes
646
648
-- to the version of the collection of HscEnv's.
647
649
defineEarlyCutOffNoFile $ \ GhcSessionIO -> do
@@ -679,24 +681,34 @@ loadGhcSession = do
679
681
680
682
defineNoDiagnostics $ \ GhcSessionDeps file -> do
681
683
env <- use_ GhcSession file
682
- ghcSessionDepsDefinition False env file
683
-
684
- ghcSessionDepsDefinition :: Bool -> HscEnvEq -> NormalizedFilePath -> Action (Maybe HscEnvEq )
685
- ghcSessionDepsDefinition forceLinkable env file = do
684
+ ghcSessionDepsDefinition ghcSessionDepsConfig env file
685
+
686
+ data GhcSessionDepsConfig = GhcSessionDepsConfig
687
+ { checkForImportCycles :: Bool
688
+ , forceLinkables :: Bool
689
+ }
690
+ instance Default GhcSessionDepsConfig where
691
+ def = GhcSessionDepsConfig
692
+ { checkForImportCycles = True
693
+ , forceLinkables = False
694
+ }
695
+
696
+ ghcSessionDepsDefinition :: GhcSessionDepsConfig -> HscEnvEq -> NormalizedFilePath -> Action (Maybe HscEnvEq )
697
+ ghcSessionDepsDefinition GhcSessionDepsConfig {.. } env file = do
686
698
let hsc = hscEnv env
687
699
688
700
mbdeps <- mapM (fmap artifactFilePath . snd ) <$> use_ GetLocatedImports file
689
701
case mbdeps of
690
702
Nothing -> return Nothing
691
703
Just deps -> do
692
- _ <- uses_ ReportImportCycles deps
704
+ when checkForImportCycles $ void $ uses_ ReportImportCycles deps
693
705
ms: mss <- map msrModSummary <$> uses_ GetModSummaryWithoutTimestamps (file: deps)
694
706
695
707
depSessions <- map hscEnv <$> uses_ GhcSessionDeps deps
696
708
let uses_th_qq =
697
709
xopt LangExt. TemplateHaskell dflags || xopt LangExt. QuasiQuotes dflags
698
710
dflags = ms_hspp_opts ms
699
- ifaces <- if uses_th_qq || forceLinkable
711
+ ifaces <- if uses_th_qq || forceLinkables
700
712
then uses_ GetModIface deps
701
713
else uses_ GetModIfaceWithoutLinkable deps
702
714
@@ -1043,9 +1055,18 @@ writeHiFileAction hsc hiFile = do
1043
1055
resetInterfaceStore extras $ toNormalizedFilePath' targetPath
1044
1056
writeHiFile hsc hiFile
1045
1057
1058
+ data RulesConfig = RulesConfig
1059
+ { -- | Disable import cycle checking for improved performance in large codebases
1060
+ checkForImportCycles :: Bool
1061
+ -- | Disable TH for improved performance in large codebases
1062
+ , enableTemplateHaskell :: Bool
1063
+ }
1064
+
1065
+ instance Default RulesConfig where def = RulesConfig True True
1066
+
1046
1067
-- | A rule that wires per-file rules together
1047
- mainRule :: Rules ()
1048
- mainRule = do
1068
+ mainRule :: RulesConfig -> Rules ()
1069
+ mainRule RulesConfig { .. } = do
1049
1070
linkables <- liftIO $ newVar emptyModuleEnv
1050
1071
addIdeGlobal $ CompiledLinkables linkables
1051
1072
getParsedModuleRule
@@ -1055,7 +1076,7 @@ mainRule = do
1055
1076
reportImportCyclesRule
1056
1077
typeCheckRule
1057
1078
getDocMapRule
1058
- loadGhcSession
1079
+ loadGhcSession def{checkForImportCycles}
1059
1080
getModIfaceFromDiskRule
1060
1081
getModIfaceFromDiskAndIndexRule
1061
1082
getModIfaceRule
@@ -1073,8 +1094,10 @@ mainRule = do
1073
1094
-- * ObjectLinkable -> BCOLinkable : the prev linkable can be reused, signal "no change"
1074
1095
-- * Object/BCO -> NoLinkable : the prev linkable can be ignored, signal "no change"
1075
1096
-- * otherwise : the prev linkable cannot be reused, signal "value has changed"
1076
- defineEarlyCutoff $ RuleWithCustomNewnessCheck (<=) $ \ NeedsCompilation file ->
1077
- needsCompilationRule file
1097
+ if enableTemplateHaskell
1098
+ then defineEarlyCutoff $ RuleWithCustomNewnessCheck (<=) $ \ NeedsCompilation file ->
1099
+ needsCompilationRule file
1100
+ else defineNoDiagnostics $ \ NeedsCompilation _ -> return $ Just Nothing
1078
1101
generateCoreRule
1079
1102
getImportMapRule
1080
1103
getAnnotatedParsedSourceRule
0 commit comments