summaryrefslogtreecommitdiff
path: root/compiler/GHC/Stg
diff options
context:
space:
mode:
authorSylvain Henry <sylvain@haskus.fr>2021-01-07 14:25:15 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-02-13 21:27:34 -0500
commit8e2f85f6b4662676f0d7addaff9bf2c7d751bb63 (patch)
tree6a5bea5db12d907874cdf26d709d829a3f3216ba /compiler/GHC/Stg
parent40983d2331fe34c0af6925db7588d5ac6a19ae36 (diff)
downloadhaskell-8e2f85f6b4662676f0d7addaff9bf2c7d751bb63.tar.gz
Refactor Logger
Before this patch, the only way to override GHC's default logging behavior was to set `log_action`, `dump_action` and `trace_action` fields in DynFlags. This patch introduces a new Logger abstraction and stores it in HscEnv instead. This is part of #17957 (avoid storing state in DynFlags). DynFlags are duplicated and updated per-module (because of OPTIONS_GHC pragma), so we shouldn't store global state in them. This patch also fixes a race in parallel "--make" mode which updated the `generatedDumps` IORef concurrently. Bump haddock submodule The increase in MultilayerModules is tracked in #19293. Metric Increase: MultiLayerModules
Diffstat (limited to 'compiler/GHC/Stg')
-rw-r--r--compiler/GHC/Stg/Lint.hs10
-rw-r--r--compiler/GHC/Stg/Pipeline.hs14
2 files changed, 14 insertions, 10 deletions
diff --git a/compiler/GHC/Stg/Lint.hs b/compiler/GHC/Stg/Lint.hs
index 32b213be45..0ee7381fe0 100644
--- a/compiler/GHC/Stg/Lint.hs
+++ b/compiler/GHC/Stg/Lint.hs
@@ -54,6 +54,7 @@ import GHC.Utils.Error ( Severity(..), mkLocMessage )
import GHC.Core.Type
import GHC.Types.RepType
import GHC.Types.SrcLoc
+import GHC.Utils.Logger
import GHC.Utils.Outputable
import GHC.Unit.Module ( Module )
import qualified GHC.Utils.Error as Err
@@ -61,20 +62,21 @@ import Control.Applicative ((<|>))
import Control.Monad
lintStgTopBindings :: forall a . (OutputablePass a, BinderP a ~ Id)
- => DynFlags
+ => Logger
+ -> DynFlags
-> Module -- ^ module being compiled
-> Bool -- ^ have we run Unarise yet?
-> String -- ^ who produced the STG?
-> [GenStgTopBinding a]
-> IO ()
-lintStgTopBindings dflags this_mod unarised whodunnit binds
+lintStgTopBindings logger dflags this_mod unarised whodunnit binds
= {-# SCC "StgLint" #-}
case initL this_mod unarised opts top_level_binds (lint_binds binds) of
Nothing ->
return ()
Just msg -> do
- putLogMsg dflags NoReason Err.SevDump noSrcSpan
+ putLogMsg logger dflags NoReason Err.SevDump noSrcSpan
$ withPprStyle defaultDumpStyle
(vcat [ text "*** Stg Lint ErrMsgs: in" <+>
text whodunnit <+> text "***",
@@ -82,7 +84,7 @@ lintStgTopBindings dflags this_mod unarised whodunnit binds
text "*** Offending Program ***",
pprGenStgTopBindings opts binds,
text "*** End of Offense ***"])
- Err.ghcExit dflags 1
+ Err.ghcExit logger dflags 1
where
opts = initStgPprOpts dflags
-- Bring all top-level binds into scope because CoreToStg does not generate
diff --git a/compiler/GHC/Stg/Pipeline.hs b/compiler/GHC/Stg/Pipeline.hs
index ea758e58db..c05450c0f7 100644
--- a/compiler/GHC/Stg/Pipeline.hs
+++ b/compiler/GHC/Stg/Pipeline.hs
@@ -30,6 +30,7 @@ import GHC.Utils.Error
import GHC.Types.Unique.Supply
import GHC.Utils.Outputable
import GHC.Utils.Panic
+import GHC.Utils.Logger
import Control.Monad
import Control.Monad.IO.Class
import Control.Monad.Trans.State.Strict
@@ -46,14 +47,15 @@ instance MonadUnique StgM where
runStgM :: Char -> StgM a -> IO a
runStgM mask (StgM m) = evalStateT m mask
-stg2stg :: DynFlags -- includes spec of what stg-to-stg passes to do
+stg2stg :: Logger
+ -> DynFlags -- includes spec of what stg-to-stg passes to do
-> Module -- module being compiled
-> [StgTopBinding] -- input program
-> IO [StgTopBinding] -- output program
-stg2stg dflags this_mod binds
+stg2stg logger dflags this_mod binds
= do { dump_when Opt_D_dump_stg_from_core "Initial STG:" binds
- ; showPass dflags "Stg2Stg"
+ ; showPass logger dflags "Stg2Stg"
-- Do the main business!
; binds' <- runStgM 'g' $
foldM do_stg_pass binds (getStgToDo dflags)
@@ -73,7 +75,7 @@ stg2stg dflags this_mod binds
where
stg_linter unarised
| gopt Opt_DoStgLinting dflags
- = lintStgTopBindings dflags this_mod unarised
+ = lintStgTopBindings logger dflags this_mod unarised
| otherwise
= \ _whodunnit _binds -> return ()
@@ -106,11 +108,11 @@ stg2stg dflags this_mod binds
opts = initStgPprOpts dflags
dump_when flag header binds
- = dumpIfSet_dyn dflags flag header FormatSTG (pprStgTopBindings opts binds)
+ = dumpIfSet_dyn logger dflags flag header FormatSTG (pprStgTopBindings opts binds)
end_pass what binds2
= liftIO $ do -- report verbosely, if required
- dumpIfSet_dyn dflags Opt_D_verbose_stg2stg what
+ dumpIfSet_dyn logger dflags Opt_D_verbose_stg2stg what
FormatSTG (vcat (map (pprStgTopBinding opts) binds2))
stg_linter False what binds2
return binds2