summaryrefslogtreecommitdiff
path: root/compiler/simplCore
diff options
context:
space:
mode:
authorSylvain Henry <sylvain@haskus.fr>2019-01-03 18:31:08 +0100
committerSylvain Henry <sylvain@haskus.fr>2019-12-18 13:43:37 +0100
commit58655b9da7599135395417a042f53cfa13b2151d (patch)
treecceacdd2c9848e49d5ebc6ba19d209cc823349a2 /compiler/simplCore
parenta8f7ecd54821493dc061c55ceebb7e271b17056e (diff)
downloadhaskell-58655b9da7599135395417a042f53cfa13b2151d.tar.gz
Add GHC-API logging hooks
* Add 'dumpAction' hook to DynFlags. It allows GHC API users to catch dumped intermediate codes and information. The format of the dump (Core, Stg, raw text, etc.) is now reported allowing easier automatic handling. * Add 'traceAction' hook to DynFlags. Some dumps go through the trace mechanism (for instance unfoldings that have been considered for inlining). This is problematic because: 1) dumps aren't written into files even with -ddump-to-file on 2) dumps are written on stdout even with GHC API 3) in this specific case, dumping depends on unsafe globally stored DynFlags which is bad for GHC API users We introduce 'traceAction' hook which allows GHC API to catch those traces and to avoid using globally stored DynFlags. * Avoid dumping empty logs via dumpAction/traceAction (but still write empty files to keep the existing behavior)
Diffstat (limited to 'compiler/simplCore')
-rw-r--r--compiler/simplCore/CoreMonad.hs13
-rw-r--r--compiler/simplCore/FloatOut.hs4
-rw-r--r--compiler/simplCore/SimplCore.hs5
-rw-r--r--compiler/simplCore/SimplMonad.hs1
-rw-r--r--compiler/simplCore/Simplify.hs25
5 files changed, 33 insertions, 15 deletions
diff --git a/compiler/simplCore/CoreMonad.hs b/compiler/simplCore/CoreMonad.hs
index 620f24c680..04898921de 100644
--- a/compiler/simplCore/CoreMonad.hs
+++ b/compiler/simplCore/CoreMonad.hs
@@ -61,14 +61,14 @@ import qualified IOEnv ( liftIO )
import Var
import Outputable
import FastString
-import qualified ErrUtils as Err
-import ErrUtils( Severity(..) )
+import ErrUtils( Severity(..), DumpFormat (..), dumpOptionsFromFlag )
import UniqSupply
import MonadUtils
import NameCache
import NameEnv
import SrcLoc
import Data.Bifunctor ( bimap )
+import ErrUtils (dumpAction)
import Data.List
import Data.Ord
import Data.Dynamic
@@ -825,9 +825,10 @@ debugTraceMsg :: SDoc -> CoreM ()
debugTraceMsg = msg SevDump NoReason
-- | Show some labelled 'SDoc' if a particular flag is set or at a verbosity level of @-v -ddump-most@ or higher
-dumpIfSet_dyn :: DumpFlag -> String -> SDoc -> CoreM ()
-dumpIfSet_dyn flag str doc
+dumpIfSet_dyn :: DumpFlag -> String -> DumpFormat -> SDoc -> CoreM ()
+dumpIfSet_dyn flag str fmt doc
= do { dflags <- getDynFlags
; unqual <- getPrintUnqualified
- ; when (dopt flag dflags) $ liftIO $
- Err.dumpSDoc dflags unqual flag str doc }
+ ; when (dopt flag dflags) $ liftIO $ do
+ let sty = mkDumpStyle dflags unqual
+ dumpAction dflags sty (dumpOptionsFromFlag flag) str fmt doc }
diff --git a/compiler/simplCore/FloatOut.hs b/compiler/simplCore/FloatOut.hs
index 015d096a0a..c0110fa1d9 100644
--- a/compiler/simplCore/FloatOut.hs
+++ b/compiler/simplCore/FloatOut.hs
@@ -19,7 +19,7 @@ import CoreArity ( etaExpand )
import CoreMonad ( FloatOutSwitches(..) )
import DynFlags
-import ErrUtils ( dumpIfSet_dyn )
+import ErrUtils ( dumpIfSet_dyn, DumpFormat (..) )
import Id ( Id, idArity, idType, isBottomingId,
isJoinId, isJoinId_maybe )
import SetLevels
@@ -174,11 +174,13 @@ floatOutwards float_sws dflags us pgm
} ;
dumpIfSet_dyn dflags Opt_D_verbose_core2core "Levels added:"
+ FormatCore
(vcat (map ppr annotated_w_levels));
let { (tlets, ntlets, lams) = get_stats (sum_stats fss) };
dumpIfSet_dyn dflags Opt_D_dump_simpl_stats "FloatOut stats:"
+ FormatText
(hcat [ int tlets, text " Lets floated to top level; ",
int ntlets, text " Lets floated elsewhere; from ",
int lams, text " Lambda groups"]);
diff --git a/compiler/simplCore/SimplCore.hs b/compiler/simplCore/SimplCore.hs
index 149a079a0a..19465082dc 100644
--- a/compiler/simplCore/SimplCore.hs
+++ b/compiler/simplCore/SimplCore.hs
@@ -36,7 +36,7 @@ import FloatIn ( floatInwards )
import FloatOut ( floatOutwards )
import FamInstEnv
import Id
-import ErrUtils ( withTiming, withTimingD )
+import ErrUtils ( withTiming, withTimingD, DumpFormat (..) )
import BasicTypes ( CompilerPhase(..), isDefaultInlinePragma, defaultInlinePragma )
import VarSet
import VarEnv
@@ -90,6 +90,7 @@ core2core hsc_env guts@(ModGuts { mg_module = mod
; Err.dumpIfSet_dyn dflags Opt_D_dump_simpl_stats
"Grand total simplifier statistics"
+ FormatText
(pprSimplCount stats)
; return guts2 }
@@ -576,6 +577,7 @@ simplifyExpr dflags expr
"Simplifier statistics" (pprSimplCount counts)
; Err.dumpIfSet_dyn dflags Opt_D_dump_simpl "Simplified expression"
+ FormatCore
(pprCoreExpr expr')
; return expr'
@@ -688,6 +690,7 @@ simplifyPgmIO pass@(CoreDoSimplify max_iterations mode)
binds
} ;
Err.dumpIfSet_dyn dflags Opt_D_dump_occur_anal "Occurrence analysis"
+ FormatCore
(pprCoreBindings tagged_binds);
-- Get any new rules, and extend the rule base
diff --git a/compiler/simplCore/SimplMonad.hs b/compiler/simplCore/SimplMonad.hs
index 32c277cc55..271f75e49b 100644
--- a/compiler/simplCore/SimplMonad.hs
+++ b/compiler/simplCore/SimplMonad.hs
@@ -141,6 +141,7 @@ traceSmpl :: String -> SDoc -> SimplM ()
traceSmpl herald doc
= do { dflags <- getDynFlags
; liftIO $ Err.dumpIfSet_dyn dflags Opt_D_dump_simpl_trace "Simpl Trace"
+ FormatText
(hang (text herald) 2 doc) }
{-
diff --git a/compiler/simplCore/Simplify.hs b/compiler/simplCore/Simplify.hs
index 01e417ffaa..f5d8f1aeb0 100644
--- a/compiler/simplCore/Simplify.hs
+++ b/compiler/simplCore/Simplify.hs
@@ -260,7 +260,8 @@ simplRecOrTopPair env top_lvl is_rec mb_cont old_bndr new_bndr rhs
| not (dopt Opt_D_verbose_core2core dflags)
= thing_inside
| otherwise
- = pprTrace ("SimplBind " ++ what) (ppr old_bndr) thing_inside
+ = traceAction dflags ("SimplBind " ++ what)
+ (ppr old_bndr) thing_inside
--------------------------
simplLazyBind :: SimplEnv
@@ -1793,14 +1794,20 @@ completeCall env var cont
interesting_cont = interestingCallContext env call_cont
active_unf = activeUnfolding (getMode env) var
+ log_inlining doc
+ = liftIO $ dumpAction dflags
+ (mkUserStyle dflags alwaysQualify AllTheWay)
+ (dumpOptionsFromFlag Opt_D_dump_inlinings)
+ "" FormatText doc
+
dump_inline unfolding cont
| not (dopt Opt_D_dump_inlinings dflags) = return ()
| not (dopt Opt_D_verbose_core2core dflags)
= when (isExternalName (idName var)) $
- liftIO $ printOutputForUser dflags alwaysQualify $
+ log_inlining $
sep [text "Inlining done:", nest 4 (ppr var)]
| otherwise
- = liftIO $ printOutputForUser dflags alwaysQualify $
+ = liftIO $ log_inlining $
sep [text "Inlining done: " <> ppr var,
nest 4 (vcat [text "Inlined fn: " <+> nest 2 (ppr unfolding),
text "Cont: " <+> ppr cont])]
@@ -2065,17 +2072,21 @@ tryRules env rules fn args call_cont
nodump
| dopt Opt_D_dump_rule_rewrites dflags
- = liftIO $ dumpSDoc dflags alwaysQualify Opt_D_dump_rule_rewrites "" empty
+ = liftIO $ do
+ touchDumpFile dflags (dumpOptionsFromFlag Opt_D_dump_rule_rewrites)
| dopt Opt_D_dump_rule_firings dflags
- = liftIO $ dumpSDoc dflags alwaysQualify Opt_D_dump_rule_firings "" empty
+ = liftIO $ do
+ touchDumpFile dflags (dumpOptionsFromFlag Opt_D_dump_rule_firings)
| otherwise
= return ()
log_rule dflags flag hdr details
- = liftIO . dumpSDoc dflags alwaysQualify flag "" $
- sep [text hdr, nest 4 details]
+ = liftIO $ do
+ let sty = mkDumpStyle dflags alwaysQualify
+ dumpAction dflags sty (dumpOptionsFromFlag flag) "" FormatText $
+ sep [text hdr, nest 4 details]
trySeqRules :: SimplEnv
-> OutExpr -> InExpr -- Scrutinee and RHS