on af56be6 help sign in
168 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 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 Module
28import Development.IDE.Types.SpanInfo
31-- NOTATION
32-- Foo+ means Foo for the dependencies
33-- Foo* means Foo for me and Foo+
35-- | Kick off things
36type instance RuleResult OfInterest = ()
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-- | The result of loading a module from a package.
54type instance RuleResult LoadPackage = LoadPackageResult
56-- | Information about what spans occur where, requires TypeCheck
57type instance RuleResult GetSpanInfo = [SpanInfo]
59-- | Convert to Core, requires TypeCheck*
60type instance RuleResult GenerateCore = GhcModule
62-- | We capture the subset of `DynFlags` that is computed by package initialization in a rule to
63-- make session initialization cheaper by reusing it.
64type instance RuleResult LoadPackageState = Compile.PackageState
66-- | Resolve the imports in a module to the list of either external packages or absolute file paths
67-- for modules in the same package.
68type instance RuleResult GetLocatedImports = [(Located ModuleName, Maybe Import)]
70-- | This rule is used to report import cycles. It depends on GetDependencyInformation.
71-- We cannot report the cycles directly from GetDependencyInformation since
72-- we can only report diagnostics for the current file.
73type instance RuleResult ReportImportCycles = ()
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 LoadPackage = LoadPackage InstalledUnitId
112 deriving (Eq, Show, Typeable, Generic)
113instance Hashable LoadPackage
114instance NFData LoadPackage
116data GetSpanInfo = GetSpanInfo
117 deriving (Eq, Show, Typeable, Generic)
118instance Hashable GetSpanInfo
119instance NFData GetSpanInfo
121data GenerateCore = GenerateCore
122 deriving (Eq, Show, Typeable, Generic)
123instance Hashable GenerateCore
124instance NFData GenerateCore
126data LoadPackageState = LoadPackageState
127 deriving (Eq, Show, Typeable, Generic)
128instance Hashable LoadPackageState
129instance NFData LoadPackageState
131------------------------------------------------------------
132-- Orphan Instances
134instance NFData (GenLocated SrcSpan ModuleName) where
135 rnf = rwhnf
137instance Show TcModuleResult where
138 show = show . pm_mod_summary . tm_parsed_module . Compile.tmrModule
140instance NFData TcModuleResult where
141 rnf = rwhnf
143instance Show ModSummary where
144 show = show . ms_mod
146instance Show ParsedModule where
147 show = show . pm_mod_summary
149instance NFData ModSummary where
150 rnf = rwhnf
152instance NFData ParsedModule where
153 rnf = rwhnf
155instance NFData SpanInfo where
156 rnf = rwhnf
158instance NFData Import where
159 rnf = rwhnf
161instance Hashable InstalledUnitId where
162 hashWithSalt salt = hashWithSalt salt . installedUnitIdString
164instance Show LoadPackageResult where
165 show = installedUnitIdString . lprInstalledUnitId
167instance NFData LoadPackageResult where
168 rnf = rwhnf