Skip to content

Commit 2118a61

Browse files
authored
Merge branch 'master' into hls-wrapper-lsp-server
2 parents bfc6ed2 + 2121495 commit 2118a61

File tree

30 files changed

+927
-301
lines changed

30 files changed

+927
-301
lines changed

exe/Plugins.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ idePlugins recorder includeExamples = pluginDescToIdePlugins allPlugins
160160
CallHierarchy.descriptor :
161161
#endif
162162
#if class
163-
Class.descriptor "class" :
163+
Class.descriptor pluginRecorder "class" :
164164
#endif
165165
#if haddockComments
166166
HaddockComments.descriptor "haddockComments" :

ghcide/exe/Arguments.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ data Arguments = Arguments
1515
,argsOTMemoryProfiling :: Bool
1616
,argsTesting :: Bool
1717
,argsDisableKick :: Bool
18+
,argsVerifyCoreFile :: Bool
1819
,argsThreads :: Int
1920
,argsVerbose :: Bool
2021
,argsCommand :: Command
@@ -37,6 +38,7 @@ arguments plugins = Arguments
3738
<*> switch (long "ot-memory-profiling" <> help "Record OpenTelemetry info to the eventlog. Needs the -l RTS flag to have an effect")
3839
<*> switch (long "test" <> help "Enable additional lsp messages used by the testsuite")
3940
<*> switch (long "test-no-kick" <> help "Disable kick. Useful for testing cancellation")
41+
<*> switch (long "verify-core-file" <> help "Verify core trips by roundtripping after serialization. Slow, only useful for testing purposes")
4042
<*> option auto (short 'j' <> help "Number of threads (0: automatic)" <> metavar "NUM" <> value 0 <> showDefault)
4143
<*> switch (short 'd' <> long "verbose" <> help "Include internal events in logging output")
4244
<*> (commandP plugins <|> lspCommand <|> checkCommand)

ghcide/exe/Main.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ main = withTelemetryLogger $ \telemetryLogger -> do
142142
, optCheckParents = pure $ checkParents config
143143
, optCheckProject = pure $ checkProject config
144144
, optRunSubset = not argsConservativeChangeTracking
145+
, optVerifyCoreFile = argsVerifyCoreFile
145146
}
146147
, IDEMain.argsMonitoring = OpenTelemetry.monitoring <> EKG.monitoring logger argsMonitoringPort
147148
}

ghcide/ghcide.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ library
180180
Development.IDE.GHC.Compat.Units
181181
Development.IDE.GHC.Compat.Util
182182
Development.IDE.Core.Compile
183+
Development.IDE.GHC.CoreFile
183184
Development.IDE.GHC.Dump
184185
Development.IDE.GHC.Error
185186
Development.IDE.GHC.ExactPrint

ghcide/src/Development/IDE/Core/Compile.hs

Lines changed: 312 additions & 191 deletions
Large diffs are not rendered by default.

ghcide/src/Development/IDE/Core/FileStore.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ getModificationTimeImpl missingFileDiags file = do
150150
-- But interface files are private, in that only HLS writes them.
151151
-- So we implement watching ourselves, and bypass the need for alwaysRerun.
152152
isInterface :: NormalizedFilePath -> Bool
153-
isInterface f = takeExtension (fromNormalizedFilePath f) `elem` [".hi", ".hi-boot"]
153+
isInterface f = takeExtension (fromNormalizedFilePath f) `elem` [".hi", ".hi-boot", ".hie", ".hie-boot", ".core"]
154154

155155
-- | Reset the GetModificationTime state of interface files
156156
resetInterfaceStore :: ShakeExtras -> NormalizedFilePath -> STM ()

ghcide/src/Development/IDE/Core/RuleTypes.hs

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module Development.IDE.Core.RuleTypes(
1717
) where
1818

1919
import Control.DeepSeq
20+
import Control.Exception (assert)
2021
import Control.Lens
2122
import Data.Aeson.Types (Value)
2223
import Data.Hashable
@@ -26,6 +27,7 @@ import Data.Typeable
2627
import Development.IDE.GHC.Compat hiding
2728
(HieFileResult)
2829
import Development.IDE.GHC.Compat.Util
30+
import Development.IDE.GHC.CoreFile
2931
import Development.IDE.GHC.Util
3032
import Development.IDE.Graph
3133
import Development.IDE.Import.DependencyInformation
@@ -35,9 +37,7 @@ import GHC.Generics (Generic)
3537

3638
import qualified Data.Binary as B
3739
import Data.ByteString (ByteString)
38-
import qualified Data.ByteString.Lazy as LBS
3940
import Data.Text (Text)
40-
import Data.Time
4141
import Development.IDE.Import.FindImports (ArtifactsLocation)
4242
import Development.IDE.Spans.Common
4343
import Development.IDE.Spans.LocalBindings
@@ -91,6 +91,26 @@ data GenerateCore = GenerateCore
9191
instance Hashable GenerateCore
9292
instance 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+
94114
data GetImportMap = GetImportMap
95115
deriving (Eq, Show, Typeable, Generic)
96116
instance 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
}
145166
instance 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

168191
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{..}
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

183203
instance NFData HiFileResult where
184204
rnf = rwhnf

0 commit comments

Comments
 (0)