@@ -17,6 +17,7 @@ module Development.IDE.Core.RuleTypes(
1717 ) where
1818
1919import Control.DeepSeq
20+ import Control.Exception (assert )
2021import Control.Lens
2122import Data.Aeson.Types (Value )
2223import Data.Hashable
@@ -26,6 +27,7 @@ import Data.Typeable
2627import Development.IDE.GHC.Compat hiding
2728 (HieFileResult )
2829import Development.IDE.GHC.Compat.Util
30+ import Development.IDE.GHC.CoreFile
2931import Development.IDE.GHC.Util
3032import Development.IDE.Graph
3133import Development.IDE.Import.DependencyInformation
@@ -35,9 +37,7 @@ import GHC.Generics (Generic)
3537
3638import qualified Data.Binary as B
3739import Data.ByteString (ByteString )
38- import qualified Data.ByteString.Lazy as LBS
3940import Data.Text (Text )
40- import Data.Time
4141import Development.IDE.Import.FindImports (ArtifactsLocation )
4242import Development.IDE.Spans.Common
4343import Development.IDE.Spans.LocalBindings
@@ -91,6 +91,26 @@ data GenerateCore = GenerateCore
9191instance Hashable GenerateCore
9292instance NFData GenerateCore
9393
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+
94114data GetImportMap = GetImportMap
95115 deriving (Eq , Show , Typeable , Generic )
96116instance Hashable GetImportMap
@@ -138,9 +158,10 @@ data TcModuleResult = TcModuleResult
138158 -- ^ Typechecked splice information
139159 , tmrDeferedError :: ! Bool
140160 -- ^ Did we defer any type errors for this module?
141- , tmrRuntimeModules :: ! (ModuleEnv UTCTime )
161+ , tmrRuntimeModules :: ! (ModuleEnv ByteString )
142162 -- ^ Which modules did we need at runtime while compiling this file?
143163 -- Used for recompilation checking in the presence of TH
164+ -- Stores the hash of their core file
144165 }
145166instance Show TcModuleResult where
146167 show = show . pm_mod_summary . tmrParsed
@@ -155,30 +176,29 @@ data HiFileResult = HiFileResult
155176 { hirModSummary :: ! ModSummary
156177 -- Bang patterns here are important to stop the result retaining
157178 -- 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
161183 -- ^ Fingerprint for the ModIface
162- , hirLinkableFp :: ByteString
163- -- ^ Fingerprint for the Linkable
164- , hirRuntimeModules :: ! (ModuleEnv UTCTime )
184+ , hirRuntimeModules :: ! (ModuleEnv ByteString )
165185 -- ^ 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
166189 }
167190
168191hiFileFingerPrint :: 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 {.. }
173200 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
182202
183203instance NFData HiFileResult where
184204 rnf = rwhnf
0 commit comments