on 5b4cfbb help sign in
185 lines 6.4 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.Binary (Binary)
21import qualified Data.Binary as Binary
22import Data.Hashable
23import Data.Typeable
24import Development.Shake hiding (Env, newCache)
25import GHC.Generics (Generic)
27import "ghc-lib" GHC
28import "ghc-lib-parser" 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 GeneratePackageState = Compile.PackageState
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 = ()
78data OfInterest = OfInterest
79 deriving (Eq, Show, Typeable, Generic)
80instance Binary OfInterest
81instance Hashable OfInterest
82instance NFData OfInterest
84data GetParsedModule = GetParsedModule
85 deriving (Eq, Show, Typeable, Generic)
86instance Binary GetParsedModule
87instance Hashable GetParsedModule
88instance NFData GetParsedModule
90data GetLocatedImports = GetLocatedImports
91 deriving (Eq, Show, Typeable, Generic)
92instance Binary GetLocatedImports
93instance Hashable GetLocatedImports
94instance NFData GetLocatedImports
96data GetDependencyInformation = GetDependencyInformation
97 deriving (Eq, Show, Typeable, Generic)
98instance Binary GetDependencyInformation
99instance Hashable GetDependencyInformation
100instance NFData GetDependencyInformation
102data ReportImportCycles = ReportImportCycles
103 deriving (Eq, Show, Typeable, Generic)
104instance Binary ReportImportCycles
105instance Hashable ReportImportCycles
106instance NFData ReportImportCycles
108data GetDependencies = GetDependencies
109 deriving (Eq, Show, Typeable, Generic)
110instance Binary GetDependencies
111instance Hashable GetDependencies
112instance NFData GetDependencies
114data TypeCheck = TypeCheck
115 deriving (Eq, Show, Typeable, Generic)
116instance Binary TypeCheck
117instance Hashable TypeCheck
118instance NFData TypeCheck
120data LoadPackage = LoadPackage InstalledUnitId
121 deriving (Eq, Show, Typeable, Generic)
122instance Binary LoadPackage
123instance Hashable LoadPackage
124instance NFData LoadPackage
126data GetSpanInfo = GetSpanInfo
127 deriving (Eq, Show, Typeable, Generic)
128instance Binary GetSpanInfo
129instance Hashable GetSpanInfo
130instance NFData GetSpanInfo
132data GenerateCore = GenerateCore
133 deriving (Eq, Show, Typeable, Generic)
134instance Binary GenerateCore
135instance Hashable GenerateCore
136instance NFData GenerateCore
138data GeneratePackageState = GeneratePackageState [FilePath] Bool [(String, [(String, String)])]
139 deriving (Eq, Show, Typeable, Generic)
140instance Binary GeneratePackageState
141instance Hashable GeneratePackageState
142instance NFData GeneratePackageState
144------------------------------------------------------------
145-- Orphan Instances
147instance NFData (GenLocated SrcSpan ModuleName) where
148 rnf = rwhnf
150instance Show TcModuleResult where
151 show = show . pm_mod_summary . tm_parsed_module . Compile.tmrModule
153instance NFData TcModuleResult where
154 rnf = rwhnf
156instance Show ModSummary where
157 show = show . ms_mod
159instance Show ParsedModule where
160 show = show . pm_mod_summary
162instance NFData ModSummary where
163 rnf = rwhnf
165instance NFData ParsedModule where
166 rnf = rwhnf
168instance NFData SpanInfo where
169 rnf = rwhnf
171instance NFData Import where
172 rnf = rwhnf
174instance Binary InstalledUnitId where
175 get = fmap stringToInstalledUnitId Binary.get
176 put = Binary.put . installedUnitIdString
178instance Hashable InstalledUnitId where
179 hashWithSalt salt = hashWithSalt salt . installedUnitIdString
181instance Show LoadPackageResult where
182 show = installedUnitIdString . lprInstalledUnitId
184instance NFData LoadPackageResult where
185 rnf = rwhnf