on 210de4e help sign in
184 lines 6.0 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.IDE.Types.Diagnostics
23import Data.Set(Set)
24import Development.Shake hiding (Env, newCache)
25import GHC.Generics (Generic)
27import GHC
28import Development.IDE.Compat
29import Module
31import Development.IDE.Types.SpanInfo
34-- NOTATION
35-- Foo+ means Foo for the dependencies
36-- Foo* means Foo for me and Foo+
38-- | The parse tree for the file using GetFileContents
39type instance RuleResult GetParsedModule = ParsedModule
41-- | The dependency information produced by following the imports recursively.
42-- This rule will succeed even if there is an error, e.g., a module could not be located,
43-- a module could not be parsed or an import cycle.
44type instance RuleResult GetDependencyInformation = DependencyInformation
46-- | Transitive module and pkg dependencies based on the information produced by GetDependencyInformation.
47-- This rule is also responsible for calling ReportImportCycles for each file in the transitive closure.
48type instance RuleResult GetDependencies = TransitiveDependencies
50-- | The type checked version of this file, requires TypeCheck+
51type instance RuleResult TypeCheck = TcModuleResult
53-- | Information about what spans occur where, requires TypeCheck
54type instance RuleResult GetSpanInfo = [SpanInfo]
56-- | Convert to Core, requires TypeCheck*
57type instance RuleResult GenerateCore = GhcModule
59-- | A GHC session that we reuse.
60type instance RuleResult GhcSession = HscEnv
62-- | Resolve the imports in a module to the list of either external packages or absolute file paths
63-- for modules in the same package.
64type instance RuleResult GetLocatedImports = [(Located ModuleName, Maybe Import)]
66-- | This rule is used to report import cycles. It depends on GetDependencyInformation.
67-- We cannot report the cycles directly from GetDependencyInformation since
68-- we can only report diagnostics for the current file.
69type instance RuleResult ReportImportCycles = ()
71-- | Read the given HIE file.
72type instance RuleResult GetHieFile = HieFile
75type instance RuleResult GetFilesOfInterest = Set NormalizedFilePath
78data GetFilesOfInterest = GetFilesOfInterest
79 deriving (Eq, Show, Typeable, Generic)
80instance Hashable GetFilesOfInterest
81instance NFData GetFilesOfInterest
83data GetParsedModule = GetParsedModule
84 deriving (Eq, Show, Typeable, Generic)
85instance Hashable GetParsedModule
86instance NFData GetParsedModule
88data GetLocatedImports = GetLocatedImports
89 deriving (Eq, Show, Typeable, Generic)
90instance Hashable GetLocatedImports
91instance NFData GetLocatedImports
93data GetDependencyInformation = GetDependencyInformation
94 deriving (Eq, Show, Typeable, Generic)
95instance Hashable GetDependencyInformation
96instance NFData GetDependencyInformation
98data ReportImportCycles = ReportImportCycles
99 deriving (Eq, Show, Typeable, Generic)
100instance Hashable ReportImportCycles
101instance NFData ReportImportCycles
103data GetDependencies = GetDependencies
104 deriving (Eq, Show, Typeable, Generic)
105instance Hashable GetDependencies
106instance NFData GetDependencies
108data TypeCheck = TypeCheck
109 deriving (Eq, Show, Typeable, Generic)
110instance Hashable TypeCheck
111instance NFData TypeCheck
113data GetSpanInfo = GetSpanInfo
114 deriving (Eq, Show, Typeable, Generic)
115instance Hashable GetSpanInfo
116instance NFData GetSpanInfo
118data GenerateCore = GenerateCore
119 deriving (Eq, Show, Typeable, Generic)
120instance Hashable GenerateCore
121instance NFData GenerateCore
123data GhcSession = GhcSession
124 deriving (Eq, Show, Typeable, Generic)
125instance Hashable GhcSession
126instance NFData GhcSession
128-- Note that we embed the filepath here instead of using the filepath associated with Shake keys.
129-- Otherwise we will garbage collect the result since files in package dependencies will not be declared reachable.
130data GetHieFile = GetHieFile FilePath
131 deriving (Eq, Show, Typeable, Generic)
132instance Hashable GetHieFile
133instance NFData GetHieFile
135------------------------------------------------------------
136-- Orphan Instances
138instance NFData (GenLocated SrcSpan ModuleName) where
139 rnf = rwhnf
141instance Show TcModuleResult where
142 show = show . pm_mod_summary . tm_parsed_module . Compile.tmrModule
144instance NFData TcModuleResult where
145 rnf = rwhnf
147instance Show ModSummary where
148 show = show . ms_mod
150instance Show ParsedModule where
151 show = show . pm_mod_summary
153instance NFData ModSummary where
154 rnf = rwhnf
156instance Show HscEnv where
157 show _ = "HscEnv"
159instance NFData HscEnv where
160 rnf = rwhnf
162instance NFData ParsedModule where
163 rnf = rwhnf
165instance NFData SpanInfo where
166 rnf = rwhnf
168instance NFData Import where
169 rnf = rwhnf
171instance Hashable InstalledUnitId where
172 hashWithSalt salt = hashWithSalt salt . installedUnitIdString
174instance Show LoadPackageResult where
175 show = installedUnitIdString . lprInstalledUnitId
177instance NFData LoadPackageResult where
178 rnf = rwhnf
180instance Show HieFile where
181 show = show . hie_module
183instance NFData HieFile where
184 rnf = rwhnf