on bbdcbdd help sign in
186 lines 6.5 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.State.Shake
31import Development.IDE.Types.SpanInfo
34-- NOTATION
35-- Foo+ means Foo for the dependencies
36-- Foo* means Foo for me and Foo+
38-- | Kick off things
39type instance RuleResult OfInterest = IdeResult ()
41-- | The parse tree for the file using GetFileContents
42type instance RuleResult GetParsedModule = IdeResult ParsedModule
44-- | The dependency information produced by following the imports recursively.
45-- This rule will succeed even if there is an error, e.g., a module could not be located,
46-- a module could not be parsed or an import cycle.
47type instance RuleResult GetDependencyInformation = IdeResult DependencyInformation
49-- | Transitive module and pkg dependencies based on the information produced by GetDependencyInformation.
50-- This rule is also responsible for calling ReportImportCycles for each file in the transitive closure.
51type instance RuleResult GetDependencies = IdeResult TransitiveDependencies
53-- | The type checked version of this file, requires TypeCheck+
54type instance RuleResult TypeCheck = IdeResult TcModuleResult
56-- | The result of loading a module from a package.
57type instance RuleResult LoadPackage = IdeResult LoadPackageResult
59-- | Information about what spans occur where, requires TypeCheck
60type instance RuleResult GetSpanInfo = IdeResult [SpanInfo]
62-- | Convert to Core, requires TypeCheck*
63type instance RuleResult GenerateCore = IdeResult GhcModule
65-- | We capture the subset of `DynFlags` that is computed by package initialization in a rule to
66-- make session initialization cheaper by reusing it.
67type instance RuleResult GeneratePackageState = IdeResult Compile.PackageState
69-- | Resolve the imports in a module to the list of either external packages or absolute file paths
70-- for modules in the same package.
71type instance RuleResult GetLocatedImports = IdeResult [(Located ModuleName, Maybe Import)]
73-- | This rule is used to report import cycles. It depends on GetDependencyInformation.
74-- We cannot report the cycles directly from GetDependencyInformation since
75-- we can only report diagnostics for the current file.
76type instance RuleResult ReportImportCycles = IdeResult ()
79data OfInterest = OfInterest
80 deriving (Eq, Show, Typeable, Generic)
81instance Binary OfInterest
82instance Hashable OfInterest
83instance NFData OfInterest
85data GetParsedModule = GetParsedModule
86 deriving (Eq, Show, Typeable, Generic)
87instance Binary GetParsedModule
88instance Hashable GetParsedModule
89instance NFData GetParsedModule
91data GetLocatedImports = GetLocatedImports
92 deriving (Eq, Show, Typeable, Generic)
93instance Binary GetLocatedImports
94instance Hashable GetLocatedImports
95instance NFData GetLocatedImports
97data GetDependencyInformation = GetDependencyInformation
98 deriving (Eq, Show, Typeable, Generic)
99instance Binary GetDependencyInformation
100instance Hashable GetDependencyInformation
101instance NFData GetDependencyInformation
103data ReportImportCycles = ReportImportCycles
104 deriving (Eq, Show, Typeable, Generic)
105instance Binary ReportImportCycles
106instance Hashable ReportImportCycles
107instance NFData ReportImportCycles
109data GetDependencies = GetDependencies
110 deriving (Eq, Show, Typeable, Generic)
111instance Binary GetDependencies
112instance Hashable GetDependencies
113instance NFData GetDependencies
115data TypeCheck = TypeCheck
116 deriving (Eq, Show, Typeable, Generic)
117instance Binary TypeCheck
118instance Hashable TypeCheck
119instance NFData TypeCheck
121data LoadPackage = LoadPackage InstalledUnitId
122 deriving (Eq, Show, Typeable, Generic)
123instance Binary LoadPackage
124instance Hashable LoadPackage
125instance NFData LoadPackage
127data GetSpanInfo = GetSpanInfo
128 deriving (Eq, Show, Typeable, Generic)
129instance Binary GetSpanInfo
130instance Hashable GetSpanInfo
131instance NFData GetSpanInfo
133data GenerateCore = GenerateCore
134 deriving (Eq, Show, Typeable, Generic)
135instance Binary GenerateCore
136instance Hashable GenerateCore
137instance NFData GenerateCore
139data GeneratePackageState = GeneratePackageState [FilePath] Bool [(String, [(String, String)])]
140 deriving (Eq, Show, Typeable, Generic)
141instance Binary GeneratePackageState
142instance Hashable GeneratePackageState
143instance NFData GeneratePackageState
145------------------------------------------------------------
146-- Orphan Instances
148instance NFData (GenLocated SrcSpan ModuleName) where
149 rnf = rwhnf
151instance Show TcModuleResult where
152 show = show . pm_mod_summary . tm_parsed_module . Compile.tmrModule
154instance NFData TcModuleResult where
155 rnf = rwhnf
157instance Show ModSummary where
158 show = show . ms_mod
160instance Show ParsedModule where
161 show = show . pm_mod_summary
163instance NFData ModSummary where
164 rnf = rwhnf
166instance NFData ParsedModule where
167 rnf = rwhnf
169instance NFData SpanInfo where
170 rnf = rwhnf
172instance NFData Import where
173 rnf = rwhnf
175instance Binary InstalledUnitId where
176 get = fmap stringToInstalledUnitId Binary.get
177 put = Binary.put . installedUnitIdString
179instance Hashable InstalledUnitId where
180 hashWithSalt salt = hashWithSalt salt . installedUnitIdString
182instance Show LoadPackageResult where
183 show = installedUnitIdString . lprInstalledUnitId
185instance NFData LoadPackageResult where
186 rnf = rwhnf