Skip to content

Commit 93b394f

Browse files
committed
Classify core rule input types
1 parent d89ba1a commit 93b394f

1 file changed

Lines changed: 49 additions & 1 deletion

File tree

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

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,35 +69,49 @@ encodeLinkableType (Just ObjectLinkable) = "2"
6969
-- Foo* means Foo for me and Foo+
7070

7171
-- | The parse tree for the file using GetFileContents
72+
--
73+
-- Project-only for now because parinsg goes through GetModSummary / GhcSession
74+
-- Dependency files should use GetHieAst from dist, not project parsing
7275
type instance RuleResult GetParsedModule = ParsedModule
76+
type instance RuleInput GetParsedModule = ProjectHaskellFiles
7377

7478
-- | The parse tree for the file using GetFileContents,
7579
-- all comments included using Opt_KeepRawTokenStream
7680
type instance RuleResult GetParsedModuleWithComments = ParsedModule
81+
type instance RuleInput GetParsedModuleWithComments = ProjectHaskellFiles
7782

7883
type instance RuleResult GetModuleGraph = DependencyInformation
84+
type instance RuleInput GetModuleGraph = NoFile
7985

8086
-- | it only compute the fingerprint of the module graph for a file and its dependencies
8187
-- we need this to trigger recompilation when the sub module graph for a file changes
8288
type instance RuleResult GetModuleGraphTransDepsFingerprints = Fingerprint
89+
type instance RuleInput GetModuleGraphTransDepsFingerprints = NoFile
90+
8391
type instance RuleResult GetModuleGraphTransReverseDepsFingerprints = Fingerprint
92+
type instance RuleInput GetModuleGraphTransReverseDepsFingerprints = NoFile
93+
8494
type instance RuleResult GetModuleGraphImmediateReverseDepsFingerprints = Fingerprint
95+
type instance RuleInput GetModuleGraphImmediateReverseDepsFingerprints = NoFile
8596

8697
data GetKnownTargets = GetKnownTargets
8798
deriving (Show, Generic, Eq, Ord)
8899
instance Hashable GetKnownTargets
89100
instance NFData GetKnownTargets
90101
type instance RuleResult GetKnownTargets = KnownTargets
102+
type instance RuleInput GetKnownTargets = NoFile
91103

92104
-- | Convert to Core, requires TypeCheck*
93105
type instance RuleResult GenerateCore = ModGuts
106+
type instance RuleInput GenerateCore = ProjectHaskellFiles
94107

95108
data GenerateCore = GenerateCore
96109
deriving (Eq, Show, Generic)
97110
instance Hashable GenerateCore
98111
instance NFData GenerateCore
99112

100113
type instance RuleResult GetLinkable = LinkableResult
114+
type instance RuleInput GetLinkable = ProjectHaskellFiles
101115

102116
data LinkableResult
103117
= LinkableResult
@@ -123,6 +137,8 @@ instance Hashable GetImportMap
123137
instance NFData GetImportMap
124138

125139
type instance RuleResult GetImportMap = ImportMap
140+
type instance RuleInput GetImportMap = ProjectHaskellFiles
141+
126142
newtype ImportMap = ImportMap
127143
{ importMap :: M.Map ModuleName NormalizedFilePath -- ^ Where are the modules imported by this file located?
128144
} deriving stock Show
@@ -245,12 +261,19 @@ instance Show HieAstResult where
245261

246262
-- | The type checked version of this file, requires TypeCheck+
247263
type instance RuleResult TypeCheck = TcModuleResult
264+
type instance RuleInput TypeCheck = ProjectHaskellFiles
248265

249266
-- | The uncompressed HieAST
267+
--
268+
-- This is intentionally broader than TypeCheck. For project files it may be
269+
-- generated from a fresh typecheck, For dependecy files it should be loaded
270+
-- from indexed .hie data
250271
type instance RuleResult GetHieAst = HieAstResult
272+
type instance RuleInput GetHieAst = AllHaskellFiles
251273

252274
-- | A IntervalMap telling us what is in scope at each point
253275
type instance RuleResult GetBindings = Bindings
276+
type instance RuleInput GetBindings = ProjectHaskellFiles
254277

255278
data DocAndTyThingMap = DKMap
256279
{ getDocMap :: !DocMap
@@ -266,42 +289,56 @@ instance Show DocAndTyThingMap where
266289
show = const "docmap"
267290

268291
type instance RuleResult GetDocMap = DocAndTyThingMap
292+
type instance RuleInput GetDocMap = ProjectHaskellFiles
269293

270294
-- | A GHC session that we reuse.
271295
type instance RuleResult GhcSession = HscEnvEq
296+
type instance RuleInput GhcSession = ProjectHaskellFiles
272297

273298
-- | A GHC session preloaded with all the dependencies
274299
-- This rule is also responsible for calling ReportImportCycles for the direct dependencies
275300
type instance RuleResult GhcSessionDeps = HscEnvEq
301+
type instance RuleInput GhcSessionDeps = ProjectHaskellFiles
276302

277303
-- | Resolve the imports in a module to the file path of a module in the same package
278304
type instance RuleResult GetLocatedImports = [(Located ModuleName, Maybe ArtifactsLocation)]
305+
type instance RuleInput GetLocatedImports = ProjectHaskellFiles
279306

280307
-- | This rule is used to report import cycles. It depends on GetModuleGraph.
281308
-- We cannot report the cycles directly from GetModuleGraph since
282309
-- we can only report diagnostics for the current file.
283310
type instance RuleResult ReportImportCycles = ()
311+
type instance RuleInput ReportImportCycles = ProjectHaskellFiles
284312

285313
-- | Read the module interface file from disk. Throws an error for VFS files.
286314
-- This is an internal rule, use 'GetModIface' instead.
287315
type instance RuleResult GetModIfaceFromDisk = HiFileResult
316+
type instance RuleInput GetModIfaceFromDisk = ProjectHaskellFiles
288317

289318
-- | GetModIfaceFromDisk and index the `.hie` file into the database.
290319
-- This is an internal rule, use 'GetModIface' instead.
291320
type instance RuleResult GetModIfaceFromDiskAndIndex = HiFileResult
321+
type instance RuleInput GetModIfaceFromDiskAndIndex = ProjectHaskellFiles
292322

293323
-- | Get a module interface details, either from an interface file or a typechecked module
324+
--
325+
-- Project-only. Dependency navigation should not regenerate or load project
326+
-- interface state via this rule; it should use GetHieAst/hiedb data
294327
type instance RuleResult GetModIface = HiFileResult
328+
type instance RuleInput GetModIface = ProjectHaskellFiles
295329

296330
-- | Get the contents of a file, either dirty (if the buffer is modified) or Nothing to mean use from disk.
297331
type instance RuleResult GetFileContents = (FileVersion, Maybe Rope)
332+
type instance RuleInput GetFileContents = AllHaskellFiles
298333

299334
type instance RuleResult GetFileExists = Bool
335+
type instance RuleInput GetFileExists = AllHaskellFiles
300336

301337
type instance RuleResult GetFileHash = Fingerprint
338+
type instance RuleInput GetFileHash = AllHaskellFiles
302339

303340
type instance RuleResult AddWatchedFile = Bool
304-
341+
type instance RuleInput AddWatchedFile = AllHaskellFiles
305342

306343
-- The Shake key type for getModificationTime queries
307344
newtype GetModificationTime = GetModificationTime_
@@ -331,12 +368,14 @@ data GetPhysicalModificationTime = GetPhysicalModificationTime
331368

332369
-- | Get the modification time of a file on disk, ignoring any version in the VFS.
333370
type instance RuleResult GetPhysicalModificationTime = FileVersion
371+
type instance RuleInput GetPhysicalModificationTime = AllHaskellFiles
334372

335373
pattern GetModificationTime :: GetModificationTime
336374
pattern GetModificationTime = GetModificationTime_ {missingFileDiagnostics=True}
337375

338376
-- | Get the modification time of a file.
339377
type instance RuleResult GetModificationTime = FileVersion
378+
type instance RuleInput GetModificationTime = AllHaskellFiles
340379

341380
-- | Either the mtime from disk or an LSP version
342381
-- LSP versions always compare as greater than on disk versions
@@ -385,6 +424,7 @@ instance Hashable IsFileOfInterestResult
385424
instance NFData IsFileOfInterestResult
386425

387426
type instance RuleResult IsFileOfInterest = IsFileOfInterestResult
427+
type instance RuleInput IsFileOfInterest = AllHaskellFiles
388428

389429
data ModSummaryResult = ModSummaryResult
390430
{ msrModSummary :: !ModSummary
@@ -406,10 +446,15 @@ instance NFData ModSummaryResult where
406446

407447
-- | Generate a ModSummary that has enough information to be used to get .hi and .hie files.
408448
-- without needing to parse the entire source
449+
--
450+
-- Project-only because this depends on GhcSession and should not be used to
451+
-- pull dependency source files into the project build graph
409452
type instance RuleResult GetModSummary = ModSummaryResult
453+
type instance RuleInput GetModSummary = ProjectHaskellFiles
410454

411455
-- | Generate a ModSummary with the timestamps and preprocessed content elided, for more successful early cutoff
412456
type instance RuleResult GetModSummaryWithoutTimestamps = ModSummaryResult
457+
type instance RuleInput GetModSummaryWithoutTimestamps = ProjectHaskellFiles
413458

414459
data GetParsedModule = GetParsedModule
415460
deriving (Eq, Show, Generic)
@@ -428,6 +473,7 @@ instance NFData GetLocatedImports
428473

429474
-- | Does this module need to be compiled?
430475
type instance RuleResult NeedsCompilation = Maybe LinkableType
476+
type instance RuleInput NeedsCompilation = ProjectHaskellFiles
431477

432478
data NeedsCompilation = NeedsCompilation
433479
deriving (Eq, Show, Generic)
@@ -536,6 +582,7 @@ instance Hashable GetClientSettings
536582
instance NFData GetClientSettings
537583

538584
type instance RuleResult GetClientSettings = Hashed (Maybe Value)
585+
type instance RuleInput GetClientSettings = NoFile
539586

540587
data AddWatchedFile = AddWatchedFile deriving (Eq, Show, Generic)
541588
instance Hashable AddWatchedFile
@@ -546,6 +593,7 @@ instance NFData AddWatchedFile
546593
-- thread killed exception issues, so we lift it to a full rule.
547594
-- https://github.com/digital-asset/daml/pull/2808#issuecomment-529639547
548595
type instance RuleResult GhcSessionIO = IdeGhcSession
596+
type instance RuleInput GhcSessionIO = NoFile
549597

550598
data IdeGhcSession = IdeGhcSession
551599
{ loadSessionFun :: FilePath -> IO (IdeResult HscEnvEq, [FilePath])

0 commit comments

Comments
 (0)