on 85379f5 help sign in
182 lines 5.9 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 Development.IDE.Functions.FindImports (Import(..))
19import Development.IDE.Functions.DependencyInformation
20import Data.Hashable
21import Data.Typeable
22import Development.Shake hiding (Env, newCache)
23import GHC.Generics (Generic)
25import GHC
26import Development.IDE.Compat
27import Module
29import Development.IDE.Types.SpanInfo
32-- NOTATION
33-- Foo+ means Foo for the dependencies
34-- Foo* means Foo for me and Foo+
36-- | Kick off things
37type instance RuleResult OfInterest = ()
39-- | The parse tree for the file using GetFileContents
40type instance RuleResult GetParsedModule = ParsedModule
42-- | The dependency information produced by following the imports recursively.
43-- This rule will succeed even if there is an error, e.g., a module could not be located,
44-- a module could not be parsed or an import cycle.
45type instance RuleResult GetDependencyInformation = DependencyInformation
47-- | Transitive module and pkg dependencies based on the information produced by GetDependencyInformation.
48-- This rule is also responsible for calling ReportImportCycles for each file in the transitive closure.
49type instance RuleResult GetDependencies = TransitiveDependencies
51-- | The type checked version of this file, requires TypeCheck+
52type instance RuleResult TypeCheck = TcModuleResult
54-- | Information about what spans occur where, requires TypeCheck
55type instance RuleResult GetSpanInfo = [SpanInfo]
57-- | Convert to Core, requires TypeCheck*
58type instance RuleResult GenerateCore = GhcModule
60-- | A GHC session that we reuse.
61type instance RuleResult GhcSession = HscEnv
63-- | Resolve the imports in a module to the list of either external packages or absolute file paths
64-- for modules in the same package.
65type instance RuleResult GetLocatedImports = [(Located ModuleName, Maybe Import)]
67-- | This rule is used to report import cycles. It depends on GetDependencyInformation.
68-- We cannot report the cycles directly from GetDependencyInformation since
69-- we can only report diagnostics for the current file.
70type instance RuleResult ReportImportCycles = ()
72-- | Read the given HIE file.
73type instance RuleResult GetHieFile = HieFile
76data OfInterest = OfInterest
77 deriving (Eq, Show, Typeable, Generic)
78instance Hashable OfInterest
79instance NFData OfInterest
81data GetParsedModule = GetParsedModule
82 deriving (Eq, Show, Typeable, Generic)
83instance Hashable GetParsedModule
84instance NFData GetParsedModule
86data GetLocatedImports = GetLocatedImports
87 deriving (Eq, Show, Typeable, Generic)
88instance Hashable GetLocatedImports
89instance NFData GetLocatedImports
91data GetDependencyInformation = GetDependencyInformation
92 deriving (Eq, Show, Typeable, Generic)
93instance Hashable GetDependencyInformation
94instance NFData GetDependencyInformation
96data ReportImportCycles = ReportImportCycles
97 deriving (Eq, Show, Typeable, Generic)
98instance Hashable ReportImportCycles
99instance NFData ReportImportCycles
101data GetDependencies = GetDependencies
102 deriving (Eq, Show, Typeable, Generic)
103instance Hashable GetDependencies
104instance NFData GetDependencies
106data TypeCheck = TypeCheck
107 deriving (Eq, Show, Typeable, Generic)
108instance Hashable TypeCheck
109instance NFData TypeCheck
111data GetSpanInfo = GetSpanInfo
112 deriving (Eq, Show, Typeable, Generic)
113instance Hashable GetSpanInfo
114instance NFData GetSpanInfo
116data GenerateCore = GenerateCore
117 deriving (Eq, Show, Typeable, Generic)
118instance Hashable GenerateCore
119instance NFData GenerateCore
121data GhcSession = GhcSession
122 deriving (Eq, Show, Typeable, Generic)
123instance Hashable GhcSession
124instance NFData GhcSession
126-- Note that we embed the filepath here instead of using the filepath associated with Shake keys.
127-- Otherwise we will garbage collect the result since files in package dependencies will not be declared reachable.
128data GetHieFile = GetHieFile FilePath
129 deriving (Eq, Show, Typeable, Generic)
130instance Hashable GetHieFile
131instance NFData GetHieFile
133------------------------------------------------------------
134-- Orphan Instances
136instance NFData (GenLocated SrcSpan ModuleName) where
137 rnf = rwhnf
139instance Show TcModuleResult where
140 show = show . pm_mod_summary . tm_parsed_module . Compile.tmrModule
142instance NFData TcModuleResult where
143 rnf = rwhnf
145instance Show ModSummary where
146 show = show . ms_mod
148instance Show ParsedModule where
149 show = show . pm_mod_summary
151instance NFData ModSummary where
152 rnf = rwhnf
154instance Show HscEnv where
155 show _ = "HscEnv"
157instance NFData HscEnv where
158 rnf = rwhnf
160instance NFData ParsedModule where
161 rnf = rwhnf
163instance NFData SpanInfo where
164 rnf = rwhnf
166instance NFData Import where
167 rnf = rwhnf
169instance Hashable InstalledUnitId where
170 hashWithSalt salt = hashWithSalt salt . installedUnitIdString
172instance Show LoadPackageResult where
173 show = installedUnitIdString . lprInstalledUnitId
175instance NFData LoadPackageResult where
176 rnf = rwhnf
178instance Show HieFile where
179 show = show . hie_module
181instance NFData HieFile where
182 rnf = rwhnf