summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorZejun Wu <watashi@fb.com>2018-12-28 00:10:22 -0800
committerBen Gamari <ben@smart-cactus.org>2019-01-31 12:46:51 -0500
commit0593e9389c4e5fd4386ebd74a746ef9659401ac6 (patch)
tree04d4b9fe43d13034daacf59f511e8c239b235cbc /compiler
parent98ff3010a642366ab8e0c563fc20debc8858dc83 (diff)
downloadhaskell-0593e9389c4e5fd4386ebd74a746ef9659401ac6.tar.gz
Add -fdefer-diagnostics to defer and group diagnostic messages in make-mode
When loading many modules in parallel there can a lot of warnings and errors get mixed up with regular output. When the compilation fails, the relevant error message can be thousands of lines backward and is hard to find. When the compilation successes, warning message is likely to be ignored as it is not seen. We can address this by deferring the warning and error message after the compilation. We also put errors after warnings so it is more visible. This idea was originally proposed by Bartosz Nitka in https://phabricator.haskell.org/D4219.
Diffstat (limited to 'compiler')
-rw-r--r--compiler/main/DynFlags.hs2
-rw-r--r--compiler/main/GhcMake.hs39
2 files changed, 39 insertions, 2 deletions
diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs
index 78be688ec3..28d8bf8eed 100644
--- a/compiler/main/DynFlags.hs
+++ b/compiler/main/DynFlags.hs
@@ -582,6 +582,7 @@ data GeneralFlag
-- output style opts
| Opt_ErrorSpans -- Include full span info in error messages,
-- instead of just the start position.
+ | Opt_DeferDiagnostics
| Opt_DiagnosticsShowCaret -- Show snippets of offending code
| Opt_PprCaseAsLet
| Opt_PprShowTicks
@@ -4101,6 +4102,7 @@ fFlagsDeps = [
flagSpec "stg-cse" Opt_StgCSE,
flagSpec "stg-lift-lams" Opt_StgLiftLams,
flagSpec "cpr-anal" Opt_CprAnal,
+ flagSpec "defer-diagnostics" Opt_DeferDiagnostics,
flagSpec "defer-type-errors" Opt_DeferTypeErrors,
flagSpec "defer-typed-holes" Opt_DeferTypedHoles,
flagSpec "defer-out-of-scope-variables" Opt_DeferOutOfScopeVariables,
diff --git a/compiler/main/GhcMake.hs b/compiler/main/GhcMake.hs
index ae27d4e7fe..85925b3ef9 100644
--- a/compiler/main/GhcMake.hs
+++ b/compiler/main/GhcMake.hs
@@ -395,8 +395,8 @@ load' how_much mHscMessage mod_graph = do
| otherwise = upsweep
setSession hsc_env{ hsc_HPT = emptyHomePackageTable }
- (upsweep_ok, modsUpswept)
- <- upsweep_fn mHscMessage pruned_hpt stable_mods cleanup mg
+ (upsweep_ok, modsUpswept) <- withDeferredDiagnostics $
+ upsweep_fn mHscMessage pruned_hpt stable_mods cleanup mg
-- Make modsDone be the summaries for each home module now
-- available; this should equal the domain of hpt3.
@@ -2457,6 +2457,41 @@ preprocessFile hsc_env src_fn mb_phase (Just (buf, _time))
-- Error messages
-----------------------------------------------------------------------------
+-- Defer and group warning, error and fatal messages so they will not get lost
+-- in the regular output.
+withDeferredDiagnostics :: GhcMonad m => m a -> m a
+withDeferredDiagnostics f = do
+ dflags <- getDynFlags
+ if not $ gopt Opt_DeferDiagnostics dflags
+ then f
+ else do
+ warnings <- liftIO $ newIORef []
+ errors <- liftIO $ newIORef []
+ fatals <- liftIO $ newIORef []
+
+ let deferDiagnostics _dflags !reason !severity !srcSpan !style !msg = do
+ let action = putLogMsg dflags reason severity srcSpan style msg
+ case severity of
+ SevWarning -> atomicModifyIORef' warnings $ \i -> (action: i, ())
+ SevError -> atomicModifyIORef' errors $ \i -> (action: i, ())
+ SevFatal -> atomicModifyIORef' fatals $ \i -> (action: i, ())
+ _ -> action
+
+ printDeferredDiagnostics = liftIO $
+ forM_ [warnings, errors, fatals] $ \ref -> do
+ -- This IORef can leak when the dflags leaks, so let us always
+ -- reset the content.
+ actions <- atomicModifyIORef' ref $ \i -> ([], i)
+ sequence_ $ reverse actions
+
+ setLogAction action = modifySession $ \hsc_env ->
+ hsc_env{ hsc_dflags = (hsc_dflags hsc_env){ log_action = action } }
+
+ gbracket
+ (setLogAction deferDiagnostics)
+ (\_ -> setLogAction (log_action dflags) >> printDeferredDiagnostics)
+ (\_ -> f)
+
noModError :: DynFlags -> SrcSpan -> ModuleName -> FindResult -> ErrMsg
-- ToDo: we don't have a proper line number for this error
noModError dflags loc wanted_mod err