on 1c27ffe help sign in
169 lines 5.7 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 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-- | The result of loading a module from a package.
55type instance RuleResult LoadPackage = LoadPackageResult
57-- | Information about what spans occur where, requires TypeCheck
58type instance RuleResult GetSpanInfo = [SpanInfo]
60-- | Convert to Core, requires TypeCheck*
61type instance RuleResult GenerateCore = GhcModule
63-- | We capture the subset of `DynFlags` that is computed by package initialization in a rule to
64-- make session initialization cheaper by reusing it.
65type instance RuleResult LoadPackageState = Compile.PackageDynFlags
67-- | Resolve the imports in a module to the list of either external packages or absolute file paths
68-- for modules in the same package.
69type instance RuleResult GetLocatedImports = [(Located ModuleName, Maybe Import)]
71-- | This rule is used to report import cycles. It depends on GetDependencyInformation.
72-- We cannot report the cycles directly from GetDependencyInformation since
73-- we can only report diagnostics for the current file.
74type instance RuleResult ReportImportCycles = ()
77data OfInterest = OfInterest
78 deriving (Eq, Show, Typeable, Generic)
79instance Hashable OfInterest
80instance NFData OfInterest
82data GetParsedModule = GetParsedModule
83 deriving (Eq, Show, Typeable, Generic)
84instance Hashable GetParsedModule
85instance NFData GetParsedModule
87data GetLocatedImports = GetLocatedImports
88 deriving (Eq, Show, Typeable, Generic)
89instance Hashable GetLocatedImports
90instance NFData GetLocatedImports
92data GetDependencyInformation = GetDependencyInformation
93 deriving (Eq, Show, Typeable, Generic)
94instance Hashable GetDependencyInformation
95instance NFData GetDependencyInformation
97data ReportImportCycles = ReportImportCycles
98 deriving (Eq, Show, Typeable, Generic)
99instance Hashable ReportImportCycles
100instance NFData ReportImportCycles
102data GetDependencies = GetDependencies
103 deriving (Eq, Show, Typeable, Generic)
104instance Hashable GetDependencies
105instance NFData GetDependencies
107data TypeCheck = TypeCheck
108 deriving (Eq, Show, Typeable, Generic)
109instance Hashable TypeCheck
110instance NFData TypeCheck
112data LoadPackage = LoadPackage InstalledUnitId
113 deriving (Eq, Show, Typeable, Generic)
114instance Hashable LoadPackage
115instance NFData LoadPackage
117data GetSpanInfo = GetSpanInfo
118 deriving (Eq, Show, Typeable, Generic)
119instance Hashable GetSpanInfo
120instance NFData GetSpanInfo
122data GenerateCore = GenerateCore
123 deriving (Eq, Show, Typeable, Generic)
124instance Hashable GenerateCore
125instance NFData GenerateCore
127data LoadPackageState = LoadPackageState
128 deriving (Eq, Show, Typeable, Generic)
129instance Hashable LoadPackageState
130instance NFData LoadPackageState
132------------------------------------------------------------
133-- Orphan Instances
135instance NFData (GenLocated SrcSpan ModuleName) where
136 rnf = rwhnf
138instance Show TcModuleResult where
139 show = show . pm_mod_summary . tm_parsed_module . Compile.tmrModule
141instance NFData TcModuleResult where
142 rnf = rwhnf
144instance Show ModSummary where
145 show = show . ms_mod
147instance Show ParsedModule where
148 show = show . pm_mod_summary
150instance NFData ModSummary where
151 rnf = rwhnf
153instance NFData ParsedModule where
154 rnf = rwhnf
156instance NFData SpanInfo where
157 rnf = rwhnf
159instance NFData Import where
160 rnf = rwhnf
162instance Hashable InstalledUnitId where
163 hashWithSalt salt = hashWithSalt salt . installedUnitIdString
165instance Show LoadPackageResult where
166 show = installedUnitIdString . lprInstalledUnitId
168instance NFData LoadPackageResult where
169 rnf = rwhnf