@@ -17,6 +17,7 @@ module Development.IDE.Core.RuleTypes(
17
17
) where
18
18
19
19
import Control.DeepSeq
20
+ import Control.Exception (assert )
20
21
import Control.Lens
21
22
import Data.Aeson.Types (Value )
22
23
import Data.Hashable
@@ -26,6 +27,7 @@ import Data.Typeable
26
27
import Development.IDE.GHC.Compat hiding
27
28
(HieFileResult )
28
29
import Development.IDE.GHC.Compat.Util
30
+ import Development.IDE.GHC.CoreFile
29
31
import Development.IDE.GHC.Util
30
32
import Development.IDE.Graph
31
33
import Development.IDE.Import.DependencyInformation
@@ -35,9 +37,7 @@ import GHC.Generics (Generic)
35
37
36
38
import qualified Data.Binary as B
37
39
import Data.ByteString (ByteString )
38
- import qualified Data.ByteString.Lazy as LBS
39
40
import Data.Text (Text )
40
- import Data.Time
41
41
import Development.IDE.Import.FindImports (ArtifactsLocation )
42
42
import Development.IDE.Spans.Common
43
43
import Development.IDE.Spans.LocalBindings
@@ -91,6 +91,26 @@ data GenerateCore = GenerateCore
91
91
instance Hashable GenerateCore
92
92
instance NFData GenerateCore
93
93
94
+ type instance RuleResult GetLinkable = LinkableResult
95
+
96
+ data LinkableResult
97
+ = LinkableResult
98
+ { linkableHomeMod :: ! HomeModInfo
99
+ , linkableHash :: ! ByteString
100
+ -- ^ The hash of the core file
101
+ }
102
+
103
+ instance Show LinkableResult where
104
+ show = show . mi_module . hm_iface . linkableHomeMod
105
+
106
+ instance NFData LinkableResult where
107
+ rnf = rwhnf
108
+
109
+ data GetLinkable = GetLinkable
110
+ deriving (Eq , Show , Typeable , Generic )
111
+ instance Hashable GetLinkable
112
+ instance NFData GetLinkable
113
+
94
114
data GetImportMap = GetImportMap
95
115
deriving (Eq , Show , Typeable , Generic )
96
116
instance Hashable GetImportMap
@@ -138,9 +158,10 @@ data TcModuleResult = TcModuleResult
138
158
-- ^ Typechecked splice information
139
159
, tmrDeferedError :: ! Bool
140
160
-- ^ Did we defer any type errors for this module?
141
- , tmrRuntimeModules :: ! (ModuleEnv UTCTime )
161
+ , tmrRuntimeModules :: ! (ModuleEnv ByteString )
142
162
-- ^ Which modules did we need at runtime while compiling this file?
143
163
-- Used for recompilation checking in the presence of TH
164
+ -- Stores the hash of their core file
144
165
}
145
166
instance Show TcModuleResult where
146
167
show = show . pm_mod_summary . tmrParsed
@@ -155,30 +176,29 @@ data HiFileResult = HiFileResult
155
176
{ hirModSummary :: ! ModSummary
156
177
-- Bang patterns here are important to stop the result retaining
157
178
-- a reference to a typechecked module
158
- , hirHomeMod :: ! HomeModInfo
159
- -- ^ Includes the Linkable iff we need object files
160
- , hirIfaceFp :: ByteString
179
+ , hirModIface :: ! ModIface
180
+ , hirModDetails :: ModDetails
181
+ -- ^ Populated lazily
182
+ , hirIfaceFp :: ! ByteString
161
183
-- ^ Fingerprint for the ModIface
162
- , hirLinkableFp :: ByteString
163
- -- ^ Fingerprint for the Linkable
164
- , hirRuntimeModules :: ! (ModuleEnv UTCTime )
184
+ , hirRuntimeModules :: ! (ModuleEnv ByteString )
165
185
-- ^ same as tmrRuntimeModules
186
+ , hirCoreFp :: ! (Maybe (CoreFile , ByteString ))
187
+ -- ^ If we wrote a core file for this module, then its contents (lazily deserialised)
188
+ -- along with its hash
166
189
}
167
190
168
191
hiFileFingerPrint :: HiFileResult -> ByteString
169
- hiFileFingerPrint HiFileResult {.. } = hirIfaceFp <> hirLinkableFp
170
-
171
- mkHiFileResult :: ModSummary -> HomeModInfo -> ModuleEnv UTCTime -> HiFileResult
172
- mkHiFileResult hirModSummary hirHomeMod hirRuntimeModules = HiFileResult {.. }
192
+ hiFileFingerPrint HiFileResult {.. } = hirIfaceFp <> maybe " " snd hirCoreFp
193
+
194
+ mkHiFileResult :: ModSummary -> ModIface -> ModDetails -> ModuleEnv ByteString -> Maybe (CoreFile , ByteString ) -> HiFileResult
195
+ mkHiFileResult hirModSummary hirModIface hirModDetails hirRuntimeModules hirCoreFp =
196
+ assert (case hirCoreFp of Just (CoreFile {cf_iface_hash}, _)
197
+ -> getModuleHash hirModIface == cf_iface_hash
198
+ _ -> True )
199
+ HiFileResult {.. }
173
200
where
174
- hirIfaceFp = fingerprintToBS . getModuleHash . hm_iface $ hirHomeMod -- will always be two bytes
175
- hirLinkableFp = case hm_linkable hirHomeMod of
176
- Nothing -> " "
177
- Just (linkableTime -> l) -> LBS. toStrict $
178
- B. encode (fromEnum $ utctDay l, fromEnum $ utctDayTime l)
179
-
180
- hirModIface :: HiFileResult -> ModIface
181
- hirModIface = hm_iface . hirHomeMod
201
+ hirIfaceFp = fingerprintToBS . getModuleHash $ hirModIface -- will always be two bytes
182
202
183
203
instance NFData HiFileResult where
184
204
rnf = rwhnf
0 commit comments