on bec100b help sign in
186 lines 6.3 kB history raw
1-- Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
2-- SPDX-License-Identifier: Apache-2.0
4{-# LANGUAGE FlexibleInstances #-}
5{-# LANGUAGE TypeFamilies #-}
6{-# OPTIONS_GHC -Wno-orphans #-}
8-- | A Shake implementation of the compiler service, built
9-- using the "Shaker" abstraction layer for in-memory use.
10--
11module Development.IDE.State.RuleTypes(
12 module Development.IDE.State.RuleTypes
13 ) where
15import Control.DeepSeq
16import Development.IDE.Functions.Compile (TcModuleResult, GhcModule, LoadPackageResult(..))
17import qualified Development.IDE.Functions.Compile as Compile
18import qualified Development.IDE.UtilGHC as Compile
19import Development.IDE.Functions.FindImports (Import(..))
20import Development.IDE.Functions.DependencyInformation
21import Data.Hashable
22import Data.Typeable
23import Development.Shake hiding (Env, newCache)
24import GHC.Generics (Generic)
26import GHC
27import HieTypes
28import Module
30import Development.IDE.Types.SpanInfo
33-- NOTATION
34-- Foo+ means Foo for the dependencies
35-- Foo* means Foo for me and Foo+
37-- | Kick off things
38type instance RuleResult OfInterest = ()
40-- | The parse tree for the file using GetFileContents
41type instance RuleResult GetParsedModule = ParsedModule
43-- | The dependency information produced by following the imports recursively.
44-- This rule will succeed even if there is an error, e.g., a module could not be located,
45-- a module could not be parsed or an import cycle.
46type instance RuleResult GetDependencyInformation = DependencyInformation
48-- | Transitive module and pkg dependencies based on the information produced by GetDependencyInformation.
49-- This rule is also responsible for calling ReportImportCycles for each file in the transitive closure.
50type instance RuleResult GetDependencies = TransitiveDependencies
52-- | The type checked version of this file, requires TypeCheck+
53type instance RuleResult TypeCheck = TcModuleResult
55-- | The result of loading a module from a package.
56type instance RuleResult LoadPackage = LoadPackageResult
58-- | Information about what spans occur where, requires TypeCheck
59type instance RuleResult GetSpanInfo = [SpanInfo]
61-- | Convert to Core, requires TypeCheck*
62type instance RuleResult GenerateCore = GhcModule
64-- | We capture the subset of `DynFlags` that is computed by package initialization in a rule to
65-- make session initialization cheaper by reusing it.
66type instance RuleResult LoadPackageState = Compile.PackageDynFlags
68-- | Resolve the imports in a module to the list of either external packages or absolute file paths
69-- for modules in the same package.
70type instance RuleResult GetLocatedImports = [(Located ModuleName, Maybe Import)]
72-- | This rule is used to report import cycles. It depends on GetDependencyInformation.
73-- We cannot report the cycles directly from GetDependencyInformation since
74-- we can only report diagnostics for the current file.
75type instance RuleResult ReportImportCycles = ()
77-- | Read the given HIE file.
78type instance RuleResult GetHieFile = HieFile
81data OfInterest = OfInterest
82 deriving (Eq, Show, Typeable, Generic)
83instance Hashable OfInterest
84instance NFData OfInterest
86data GetParsedModule = GetParsedModule
87 deriving (Eq, Show, Typeable, Generic)
88instance Hashable GetParsedModule
89instance NFData GetParsedModule
91data GetLocatedImports = GetLocatedImports
92 deriving (Eq, Show, Typeable, Generic)
93instance Hashable GetLocatedImports
94instance NFData GetLocatedImports
96data GetDependencyInformation = GetDependencyInformation
97 deriving (Eq, Show, Typeable, Generic)
98instance Hashable GetDependencyInformation
99instance NFData GetDependencyInformation
101data ReportImportCycles = ReportImportCycles
102 deriving (Eq, Show, Typeable, Generic)
103instance Hashable ReportImportCycles
104instance NFData ReportImportCycles
106data GetDependencies = GetDependencies
107 deriving (Eq, Show, Typeable, Generic)
108instance Hashable GetDependencies
109instance NFData GetDependencies
111data TypeCheck = TypeCheck
112 deriving (Eq, Show, Typeable, Generic)
113instance Hashable TypeCheck
114instance NFData TypeCheck
116data LoadPackage = LoadPackage InstalledUnitId
117 deriving (Eq, Show, Typeable, Generic)
118instance Hashable LoadPackage
119instance NFData LoadPackage
121data GetSpanInfo = GetSpanInfo
122 deriving (Eq, Show, Typeable, Generic)
123instance Hashable GetSpanInfo
124instance NFData GetSpanInfo
126data GenerateCore = GenerateCore
127 deriving (Eq, Show, Typeable, Generic)
128instance Hashable GenerateCore
129instance NFData GenerateCore
131data LoadPackageState = LoadPackageState
132 deriving (Eq, Show, Typeable, Generic)
133instance Hashable LoadPackageState
134instance NFData LoadPackageState
136-- Note that we embed the filepath here instead of using the filepath associated with Shake keys.
137-- Otherwise we will garbage collect the result since files in package dependencies will not be declared reachable.
138data GetHieFile = GetHieFile FilePath
139 deriving (Eq, Show, Typeable, Generic)
140instance Hashable GetHieFile
141instance NFData GetHieFile
143------------------------------------------------------------
144-- Orphan Instances
146instance NFData (GenLocated SrcSpan ModuleName) where
147 rnf = rwhnf
149instance Show TcModuleResult where
150 show = show . pm_mod_summary . tm_parsed_module . Compile.tmrModule
152instance NFData TcModuleResult where
153 rnf = rwhnf
155instance Show ModSummary where
156 show = show . ms_mod
158instance Show ParsedModule where
159 show = show . pm_mod_summary
161instance NFData ModSummary where
162 rnf = rwhnf
164instance NFData ParsedModule where
165 rnf = rwhnf
167instance NFData SpanInfo where
168 rnf = rwhnf
170instance NFData Import where
171 rnf = rwhnf
173instance Hashable InstalledUnitId where
174 hashWithSalt salt = hashWithSalt salt . installedUnitIdString
176instance Show LoadPackageResult where
177 show = installedUnitIdString . lprInstalledUnitId
179instance NFData LoadPackageResult where
180 rnf = rwhnf
182instance Show HieFile where
183 show = show . hie_module
185instance NFData HieFile where
186 rnf = rwhnf