Skip to content

Commit 65e9f0c

Browse files
committed
Merge branch 'master' into rebeccat/ghc94
2 parents 61aca10 + ff28990 commit 65e9f0c

File tree

28 files changed

+534
-449
lines changed

28 files changed

+534
-449
lines changed

ghcide/ghcide.cabal

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,6 @@ library
229229
if flag(ghc-patched-unboxed-bytecode)
230230
cpp-options: -DGHC_PATCHED_UNBOXED_BYTECODE
231231

232-
if impl(ghc < 8.10)
233-
exposed-modules:
234-
Development.IDE.GHC.Compat.CPP
235-
236232
if impl(ghc >= 9)
237233
ghc-options: -Wunused-packages
238234

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

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,11 @@ typecheckModule :: IdeDefer
171171
typecheckModule (IdeDefer defer) hsc tc_helpers pm = do
172172
let modSummary = pm_mod_summary pm
173173
dflags = ms_hspp_opts modSummary
174-
mmodSummary' <- catchSrcErrors (hsc_dflags hsc) "typecheck (initialize plugins)"
174+
initialized <- catchSrcErrors (hsc_dflags hsc) "typecheck (initialize plugins)"
175175
(initPlugins hsc modSummary)
176-
case mmodSummary' of
176+
case initialized of
177177
Left errs -> return (errs, Nothing)
178-
Right modSummary' -> do
178+
Right (modSummary', hsc) -> do
179179
(warnings, etcm) <- withWarnings "typecheck" $ \tweak ->
180180
let
181181
session = tweak (hscSetFlags dflags hsc)
@@ -472,7 +472,7 @@ mkHiFileResultCompile se session' tcm simplified_guts = catchErrs $ do
472472
Nothing
473473
#endif
474474

475-
#else
475+
#else
476476
let !partial_iface = force (mkPartialIface session details simplified_guts)
477477
final_iface <- mkFullIface session partial_iface
478478
#endif
@@ -563,11 +563,6 @@ mkHiFileResultCompile se session' tcm simplified_guts = catchErrs $ do
563563
. (("Error during " ++ T.unpack source) ++) . show @SomeException
564564
]
565565

566-
initPlugins :: HscEnv -> ModSummary -> IO ModSummary
567-
initPlugins session modSummary = do
568-
session1 <- liftIO $ initializePlugins (hscSetFlags (ms_hspp_opts modSummary) session)
569-
return modSummary{ms_hspp_opts = hsc_dflags session1}
570-
571566
-- | Whether we should run the -O0 simplifier when generating core.
572567
--
573568
-- This is required for template Haskell to work but we disable this in DAML.
@@ -1095,7 +1090,9 @@ getModSummaryFromImports
10951090
-> Maybe Util.StringBuffer
10961091
-> ExceptT [FileDiagnostic] IO ModSummaryResult
10971092
getModSummaryFromImports env fp modTime contents = do
1098-
(contents, opts, dflags) <- preprocessor env fp contents
1093+
(contents, opts, env) <- preprocessor env fp contents
1094+
1095+
let dflags = hsc_dflags env
10991096

11001097
-- The warns will hopefully be reported when we actually parse the module
11011098
(_warns, L main_loc hsmod) <- parseHeader dflags fp contents
@@ -1154,9 +1151,9 @@ getModSummaryFromImports env fp modTime contents = do
11541151
then mkHomeModLocation dflags (pathToModuleName fp) fp
11551152
else mkHomeModLocation dflags mod fp
11561153

1157-
let modl = mkHomeModule (hscHomeUnit (hscSetFlags dflags env)) mod
1154+
let modl = mkHomeModule (hscHomeUnit env) mod
11581155
sourceType = if "-boot" `isSuffixOf` takeExtension fp then HsBootFile else HsSrcFile
1159-
msrModSummary =
1156+
msrModSummary2 =
11601157
ModSummary
11611158
{ ms_mod = modl
11621159
, ms_hie_date = Nothing
@@ -1181,7 +1178,8 @@ getModSummaryFromImports env fp modTime contents = do
11811178
, ms_textual_imps = textualImports
11821179
}
11831180

1184-
msrFingerprint <- liftIO $ computeFingerprint opts msrModSummary
1181+
msrFingerprint <- liftIO $ computeFingerprint opts msrModSummary2
1182+
(msrModSummary, msrHscEnv) <- liftIO $ initPlugins env msrModSummary2
11851183
return ModSummaryResult{..}
11861184
where
11871185
-- Compute a fingerprint from the contents of `ModSummary`,
@@ -1222,7 +1220,7 @@ parseHeader dflags filename contents = do
12221220
PFailedWithErrorMessages msgs ->
12231221
throwE $ diagFromErrMsgs "parser" dflags $ msgs dflags
12241222
POk pst rdr_module -> do
1225-
let (warns, errs) = getMessages' pst dflags
1223+
let (warns, errs) = renderMessages $ getPsMessages pst dflags
12261224

12271225
-- Just because we got a `POk`, it doesn't mean there
12281226
-- weren't errors! To clarify, the GHC parser
@@ -1257,9 +1255,18 @@ parseFileContents env customPreprocessor filename ms = do
12571255
POk pst rdr_module ->
12581256
let
12591257
hpm_annotations = mkApiAnns pst
1260-
(warns, errs) = getMessages' pst dflags
1258+
psMessages = getPsMessages pst dflags
12611259
in
12621260
do
1261+
let IdePreprocessedSource preproc_warns errs parsed = customPreprocessor rdr_module
1262+
1263+
unless (null errs) $
1264+
throwE $ diagFromStrings "parser" DsError errs
1265+
1266+
let preproc_warnings = diagFromStrings "parser" DsWarning preproc_warns
1267+
(parsed', msgs) <- liftIO $ applyPluginsParsedResultAction env dflags ms hpm_annotations parsed psMessages
1268+
let (warns, errs) = renderMessages msgs
1269+
12631270
-- Just because we got a `POk`, it doesn't mean there
12641271
-- weren't errors! To clarify, the GHC parser
12651272
-- distinguishes between fatal and non-fatal
@@ -1272,14 +1279,6 @@ parseFileContents env customPreprocessor filename ms = do
12721279
unless (null errs) $
12731280
throwE $ diagFromErrMsgs "parser" dflags errs
12741281

1275-
-- Ok, we got here. It's safe to continue.
1276-
let IdePreprocessedSource preproc_warns errs parsed = customPreprocessor rdr_module
1277-
1278-
unless (null errs) $
1279-
throwE $ diagFromStrings "parser" DsError errs
1280-
1281-
let preproc_warnings = diagFromStrings "parser" DsWarning preproc_warns
1282-
parsed' <- liftIO $ applyPluginsParsedResultAction env dflags ms hpm_annotations parsed
12831282

12841283
-- To get the list of extra source files, we take the list
12851284
-- that the parser gave us,

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

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,30 +36,30 @@ import GHC.Utils.Outputable (renderWithContext)
3636

3737
-- | Given a file and some contents, apply any necessary preprocessors,
3838
-- e.g. unlit/cpp. Return the resulting buffer and the DynFlags it implies.
39-
preprocessor :: HscEnv -> FilePath -> Maybe Util.StringBuffer -> ExceptT [FileDiagnostic] IO (Util.StringBuffer, [String], DynFlags)
40-
preprocessor env0 filename mbContents = do
39+
preprocessor :: HscEnv -> FilePath -> Maybe Util.StringBuffer -> ExceptT [FileDiagnostic] IO (Util.StringBuffer, [String], HscEnv)
40+
preprocessor env filename mbContents = do
4141
-- Perform unlit
4242
(isOnDisk, contents) <-
4343
if isLiterate filename then do
44-
newcontent <- liftIO $ runLhs env0 filename mbContents
44+
newcontent <- liftIO $ runLhs env filename mbContents
4545
return (False, newcontent)
4646
else do
4747
contents <- liftIO $ maybe (Util.hGetStringBuffer filename) return mbContents
4848
let isOnDisk = isNothing mbContents
4949
return (isOnDisk, contents)
5050

5151
-- Perform cpp
52-
(opts, dflags) <- ExceptT $ parsePragmasIntoDynFlags env0 filename contents
53-
let env1 = hscSetFlags dflags env0
54-
let logger = hsc_logger env1
55-
(isOnDisk, contents, opts, dflags) <-
52+
(opts, env) <- ExceptT $ parsePragmasIntoHscEnv env filename contents
53+
let dflags = hsc_dflags env
54+
let logger = hsc_logger env
55+
(isOnDisk, contents, opts, env) <-
5656
if not $ xopt LangExt.Cpp dflags then
57-
return (isOnDisk, contents, opts, dflags)
57+
return (isOnDisk, contents, opts, env)
5858
else do
5959
cppLogs <- liftIO $ newIORef []
6060
let newLogger = pushLogHook (const (logActionCompat $ logAction cppLogs)) logger
6161
contents <- ExceptT
62-
$ (Right <$> (runCpp (putLogHook newLogger env1) filename
62+
$ (Right <$> (runCpp (putLogHook newLogger env) filename
6363
$ if isOnDisk then Nothing else Just contents))
6464
`catch`
6565
( \(e :: Util.GhcException) -> do
@@ -68,16 +68,16 @@ preprocessor env0 filename mbContents = do
6868
[] -> throw e
6969
diags -> return $ Left diags
7070
)
71-
(opts, dflags) <- ExceptT $ parsePragmasIntoDynFlags env1 filename contents
72-
return (False, contents, opts, dflags)
71+
(opts, env) <- ExceptT $ parsePragmasIntoHscEnv env filename contents
72+
return (False, contents, opts, env)
7373

7474
-- Perform preprocessor
7575
if not $ gopt Opt_Pp dflags then
76-
return (contents, opts, dflags)
76+
return (contents, opts, env)
7777
else do
78-
contents <- liftIO $ runPreprocessor env1 filename $ if isOnDisk then Nothing else Just contents
79-
(opts, dflags) <- ExceptT $ parsePragmasIntoDynFlags env1 filename contents
80-
return (contents, opts, dflags)
78+
contents <- liftIO $ runPreprocessor env filename $ if isOnDisk then Nothing else Just contents
79+
(opts, env) <- ExceptT $ parsePragmasIntoHscEnv env filename contents
80+
return (contents, opts, env)
8181
where
8282
logAction :: IORef [CPPLog] -> LogActionCompat
8383
logAction cppLogs dflags _reason severity srcSpan _style msg = do
@@ -137,12 +137,12 @@ isLiterate x = takeExtension x `elem` [".lhs",".lhs-boot"]
137137

138138

139139
-- | This reads the pragma information directly from the provided buffer.
140-
parsePragmasIntoDynFlags
140+
parsePragmasIntoHscEnv
141141
:: HscEnv
142142
-> FilePath
143143
-> Util.StringBuffer
144-
-> IO (Either [FileDiagnostic] ([String], DynFlags))
145-
parsePragmasIntoDynFlags env fp contents = catchSrcErrors dflags0 "pragmas" $ do
144+
-> IO (Either [FileDiagnostic] ([String], HscEnv))
145+
parsePragmasIntoHscEnv env fp contents = catchSrcErrors dflags0 "pragmas" $ do
146146
#if MIN_VERSION_ghc(9,3,0)
147147
let (_warns,opts) = getOptions (initParserOpts dflags0) contents fp
148148
#else
@@ -154,7 +154,7 @@ parsePragmasIntoDynFlags env fp contents = catchSrcErrors dflags0 "pragmas" $ do
154154

155155
(dflags, _, _) <- parseDynamicFilePragma dflags0 opts
156156
hsc_env' <- initializePlugins (hscSetFlags dflags env)
157-
return (map unLoc opts, disableWarningsAsErrors (hsc_dflags hsc_env'))
157+
return (map unLoc opts, hscSetFlags (disableWarningsAsErrors $ hsc_dflags hsc_env') hsc_env')
158158
where dflags0 = hsc_dflags env
159159

160160
-- | Run (unlit) literate haskell preprocessor on a file, or buffer if set

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ data TcModuleResult = TcModuleResult
155155
, tmrTypechecked :: TcGblEnv
156156
, tmrTopLevelSplices :: Splices
157157
-- ^ Typechecked splice information
158-
, tmrDeferredError :: !Bool
158+
, tmrDeferredError :: !Bool
159159
-- ^ Did we defer any type errors for this module?
160160
, tmrRuntimeModules :: !(ModuleEnv ByteString)
161161
-- ^ Which modules did we need at runtime while compiling this file?
@@ -357,6 +357,12 @@ data ModSummaryResult = ModSummaryResult
357357
{ msrModSummary :: !ModSummary
358358
, msrImports :: [LImportDecl GhcPs]
359359
, msrFingerprint :: !Fingerprint
360+
, msrHscEnv :: !HscEnv
361+
-- ^ HscEnv for this particular ModSummary.
362+
-- Contains initialised plugins, parsed options, etc...
363+
--
364+
-- Implicit assumption: DynFlags in 'msrModSummary' are the same as
365+
-- the DynFlags in 'msrHscEnv'.
360366
}
361367

362368
instance Show ModSummaryResult where

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,7 @@ getParsedModuleRule :: Recorder (WithPriority Log) -> Rules ()
253253
getParsedModuleRule recorder =
254254
-- this rule does not have early cutoff since all its dependencies already have it
255255
define (cmapWithPrio LogShake recorder) $ \GetParsedModule file -> do
256-
ModSummaryResult{msrModSummary = ms'} <- use_ GetModSummary file
257-
sess <- use_ GhcSession file
258-
let hsc = hscEnv sess
256+
ModSummaryResult{msrModSummary = ms', msrHscEnv = hsc} <- use_ GetModSummary file
259257
opt <- getIdeOptions
260258
modify_dflags <- getModifyDynFlags dynFlagsModifyParser
261259
let ms = ms' { ms_hspp_opts = modify_dflags $ ms_hspp_opts ms' }
@@ -327,16 +325,15 @@ getParsedModuleWithCommentsRule recorder =
327325
-- The parse diagnostics are owned by the GetParsedModule rule
328326
-- For this reason, this rule does not produce any diagnostics
329327
defineNoDiagnostics (cmapWithPrio LogShake recorder) $ \GetParsedModuleWithComments file -> do
330-
ModSummaryResult{msrModSummary = ms} <- use_ GetModSummary file
331-
sess <- use_ GhcSession file
328+
ModSummaryResult{msrModSummary = ms, msrHscEnv = hsc} <- use_ GetModSummary file
332329
opt <- getIdeOptions
333330

334331
let ms' = withoutOption Opt_Haddock $ withOption Opt_KeepRawTokenStream ms
335332
modify_dflags <- getModifyDynFlags dynFlagsModifyParser
336333
let ms = ms' { ms_hspp_opts = modify_dflags $ ms_hspp_opts ms' }
337334
reset_ms pm = pm { pm_mod_summary = ms' }
338335

339-
liftIO $ fmap (fmap reset_ms) $ snd <$> getParsedModuleDefinition (hscEnv sess) opt file ms
336+
liftIO $ fmap (fmap reset_ms) $ snd <$> getParsedModuleDefinition hsc opt file ms
340337

341338
getModifyDynFlags :: (DynFlagsModifications -> a) -> Action a
342339
getModifyDynFlags f = do

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ shakeOpen recorder lspEnv defaultConfig idePlugins logger debouncer
658658
let readValuesCounter = fromIntegral . countRelevantKeys checkParents <$> getStateKeys shakeExtras
659659
readDirtyKeys = fromIntegral . countRelevantKeys checkParents . toListKeySet <$> readTVarIO(dirtyKeys shakeExtras)
660660
readIndexPending = fromIntegral . HMap.size <$> readTVarIO (indexPending $ hiedbWriter shakeExtras)
661-
readExportsMap = fromIntegral . HMap.size . getExportsMap <$> readTVarIO (exportsMap shakeExtras)
661+
readExportsMap = fromIntegral . ExportsMap.exportsMapSize <$> readTVarIO (exportsMap shakeExtras)
662662
readDatabaseCount = fromIntegral . countRelevantKeys checkParents . map fst <$> shakeGetDatabaseKeys shakeDb
663663
readDatabaseStep = fromIntegral <$> shakeGetBuildStep shakeDb
664664

ghcide/src/Development/IDE/GHC/Compat.hs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ module Development.IDE.GHC.Compat(
2626
disableWarningsAsErrors,
2727
reLoc,
2828
reLocA,
29-
getMessages',
29+
getPsMessages,
30+
renderMessages,
3031
pattern PFailedWithErrorMessages,
3132
isObjectLinkable,
3233

@@ -43,6 +44,8 @@ module Development.IDE.GHC.Compat(
4344
#endif
4445

4546
FastStringCompat,
47+
bytesFS,
48+
mkFastStringByteString,
4649
nodeInfo',
4750
getNodeIds,
4851
sourceNodeInfo,
@@ -53,6 +56,8 @@ module Development.IDE.GHC.Compat(
5356
mkAstNode,
5457
combineRealSrcSpans,
5558

59+
nonDetOccEnvElts,
60+
5661
isQualifiedImport,
5762
GhcVersion(..),
5863
ghcVersion,
@@ -206,6 +211,7 @@ import VarEnv (emptyInScopeSet,
206211
#endif
207212

208213
#if MIN_VERSION_ghc(9,0,0)
214+
import GHC.Data.FastString
209215
import GHC.Core
210216
import GHC.Data.StringBuffer
211217
import GHC.Driver.Session hiding (ExposePackage)
@@ -224,6 +230,7 @@ import GHC.Iface.Make (mkIfaceExports)
224230
import qualified GHC.SysTools.Tasks as SysTools
225231
import qualified GHC.Types.Avail as Avail
226232
#else
233+
import FastString
227234
import qualified Avail
228235
import DynFlags hiding (ExposePackage)
229236
import HscTypes
@@ -262,6 +269,12 @@ import GHC.Types.IPE
262269
#if MIN_VERSION_ghc(9,3,0)
263270
import GHC.Types.Error
264271
import GHC.Driver.Config.Stg.Pipeline
272+
import GHC.Driver.Plugins (PsMessages (..))
273+
#endif
274+
275+
#if !MIN_VERSION_ghc(9,3,0)
276+
nonDetOccEnvElts :: OccEnv a -> [a]
277+
nonDetOccEnvElts = occEnvElts
265278
#endif
266279

267280
type ModIfaceAnnotation = Annotation
@@ -372,25 +385,13 @@ corePrepExpr _ = GHC.corePrepExpr
372385
simplifyExpr df _ = GHC.simplifyExpr df
373386
#endif
374387

375-
#if MIN_VERSION_ghc(9,2,0)
376-
type ErrMsg = MsgEnvelope DecoratedSDoc
377-
#endif
378-
#if MIN_VERSION_ghc(9,3,0)
379-
type WarnMsg = MsgEnvelope DecoratedSDoc
380-
#endif
381-
382-
getMessages' :: PState -> DynFlags -> (Bag WarnMsg, Bag ErrMsg)
383-
getMessages' pst dflags =
388+
renderMessages :: PsMessages -> (Bag WarnMsg, Bag ErrMsg)
389+
renderMessages msgs =
384390
#if MIN_VERSION_ghc(9,3,0)
385-
bimap (fmap (fmap renderDiagnosticMessageWithHints) . getMessages) (fmap (fmap renderDiagnosticMessageWithHints) . getMessages) $ getPsMessages pst
391+
let renderMsgs extractor = (fmap . fmap) renderDiagnosticMessageWithHints . getMessages $ extractor msgs
392+
in (renderMsgs psWarnings, renderMsgs psErrors)
386393
#else
387-
#if MIN_VERSION_ghc(9,2,0)
388-
bimap (fmap pprWarning) (fmap pprError) $
389-
#endif
390-
getMessages pst
391-
#if !MIN_VERSION_ghc(9,2,0)
392-
dflags
393-
#endif
394+
msgs
394395
#endif
395396

396397
#if MIN_VERSION_ghc(9,2,0)

0 commit comments

Comments
 (0)