Simon Hengel pushed to branch wip/sol/use-logInfo at Glasgow Haskell Compiler / GHC
Commits:
-
ab39da10
by Simon Hengel at 2025-08-26T17:25:13+07:00
7 changed files:
- compiler/GHC/Core/Lint.hs
- compiler/GHC/Driver/CodeOutput.hs
- compiler/GHC/Driver/Pipeline/Execute.hs
- compiler/GHC/Iface/Load.hs
- compiler/GHC/Linker/Loader.hs
- compiler/GHC/Stg/Lint.hs
- compiler/GHC/Tc/Utils/Monad.hs
Changes:
... | ... | @@ -26,6 +26,7 @@ module GHC.Core.Lint ( |
26 | 26 | -- ** Debug output
|
27 | 27 | EndPassConfig (..),
|
28 | 28 | endPassIO,
|
29 | + lintMessage,
|
|
29 | 30 | displayLintResults, dumpPassResult
|
30 | 31 | ) where
|
31 | 32 | |
... | ... | @@ -309,11 +310,6 @@ path does not result in allocation in the hot path. This can be surprisingly |
309 | 310 | impactful. Changing `lint_app` reduced allocations for one test program I was
|
310 | 311 | looking at by ~4%.
|
311 | 312 | |
312 | -Note [MCInfo for Lint]
|
|
313 | -~~~~~~~~~~~~~~~~~~~~~~
|
|
314 | -When printing a Lint message, use the MCInfo severity so that the
|
|
315 | -message is printed on stderr rather than stdout (#13342).
|
|
316 | - |
|
317 | 313 | ************************************************************************
|
318 | 314 | * *
|
319 | 315 | Beginning and ending passes
|
... | ... | @@ -321,6 +317,12 @@ message is printed on stderr rather than stdout (#13342). |
321 | 317 | ************************************************************************
|
322 | 318 | -}
|
323 | 319 | |
320 | +lintMessage :: Logger -> SDoc -> IO ()
|
|
321 | +lintMessage logger =
|
|
322 | + -- Note: Use logInfo when printing a Lint message, so that the message is
|
|
323 | + -- printed on stderr rather than stdout (#13342).
|
|
324 | + logInfo logger . withPprStyle defaultDumpStyle
|
|
325 | + |
|
324 | 326 | -- | Configuration for boilerplate operations at the end of a
|
325 | 327 | -- compilation pass producing Core.
|
326 | 328 | data EndPassConfig = EndPassConfig
|
... | ... | @@ -436,8 +438,7 @@ displayLintResults :: Logger |
436 | 438 | -> IO ()
|
437 | 439 | displayLintResults logger display_warnings pp_what pp_pgm (warns, errs)
|
438 | 440 | | not (isEmptyBag errs)
|
439 | - = do { logMsg logger Err.MCInfo noSrcSpan -- See Note [MCInfo for Lint]
|
|
440 | - $ withPprStyle defaultDumpStyle
|
|
441 | + = do { lintMessage logger
|
|
441 | 442 | (vcat [ lint_banner "errors" pp_what, Err.pprMessageBag errs
|
442 | 443 | , text "*** Offending Program ***"
|
443 | 444 | , pp_pgm
|
... | ... | @@ -447,8 +448,7 @@ displayLintResults logger display_warnings pp_what pp_pgm (warns, errs) |
447 | 448 | | not (isEmptyBag warns)
|
448 | 449 | , log_enable_debug (logFlags logger)
|
449 | 450 | , display_warnings
|
450 | - = logMsg logger Err.MCInfo noSrcSpan -- See Note [MCInfo for Lint]
|
|
451 | - $ withPprStyle defaultDumpStyle
|
|
451 | + = lintMessage logger
|
|
452 | 452 | (lint_banner "warnings" pp_what $$ Err.pprMessageBag (mapBag ($$ blankLine) warns))
|
453 | 453 | |
454 | 454 | | otherwise = return ()
|
... | ... | @@ -18,6 +18,7 @@ import GHC.Prelude |
18 | 18 | import GHC.Platform
|
19 | 19 | import GHC.ForeignSrcLang
|
20 | 20 | import GHC.Data.FastString
|
21 | +import GHC.Core.Lint ( lintMessage )
|
|
21 | 22 | |
22 | 23 | import GHC.CmmToAsm ( nativeCodeGen )
|
23 | 24 | import GHC.CmmToLlvm ( llvmCodeGen )
|
... | ... | @@ -55,7 +56,6 @@ import GHC.Utils.Panic.Plain ( pgmError ) |
55 | 56 | import GHC.Unit
|
56 | 57 | import GHC.Unit.Finder ( mkStubPaths )
|
57 | 58 | |
58 | -import GHC.Types.SrcLoc
|
|
59 | 59 | import GHC.Types.CostCentre
|
60 | 60 | import GHC.Types.ForeignStubs
|
61 | 61 | import GHC.Types.Unique.DSM
|
... | ... | @@ -109,10 +109,7 @@ codeOutput logger tmpfs llvm_config dflags unit_state this_mod filenm location g |
109 | 109 | (text "CmmLint"<+>brackets (ppr this_mod))
|
110 | 110 | (const ()) $ do
|
111 | 111 | { case cmmLint (targetPlatform dflags) cmm of
|
112 | - Just err -> do { logMsg logger
|
|
113 | - MCInfo -- See Note [MCInfo for Lint] in "GHC.Core.Lint"
|
|
114 | - noSrcSpan
|
|
115 | - $ withPprStyle defaultDumpStyle err
|
|
112 | + Just err -> do { lintMessage logger err
|
|
116 | 113 | ; ghcExit logger 1
|
117 | 114 | }
|
118 | 115 | Nothing -> return ()
|
... | ... | @@ -1162,7 +1162,7 @@ getHCFilePackages filename = |
1162 | 1162 | linkDynLibCheck :: Logger -> TmpFs -> DynFlags -> UnitEnv -> [String] -> [UnitId] -> IO ()
|
1163 | 1163 | linkDynLibCheck logger tmpfs dflags unit_env o_files dep_units = do
|
1164 | 1164 | when (haveRtsOptsFlags dflags) $
|
1165 | - logMsg logger MCInfo noSrcSpan
|
|
1165 | + logInfo logger
|
|
1166 | 1166 | $ withPprStyle defaultUserStyle
|
1167 | 1167 | (text "Warning: -rtsopts and -with-rtsopts have no effect with -shared." $$
|
1168 | 1168 | text " Call hs_init_ghc() from your main() function to set these options.")
|
... | ... | @@ -1105,7 +1105,7 @@ For some background on this choice see #15269. |
1105 | 1105 | showIface :: Logger -> DynFlags -> UnitState -> NameCache -> FilePath -> IO ()
|
1106 | 1106 | showIface logger dflags unit_state name_cache filename = do
|
1107 | 1107 | let profile = targetProfile dflags
|
1108 | - printer = logMsg logger MCOutput noSrcSpan . withPprStyle defaultDumpStyle
|
|
1108 | + printer = logOutput logger . withPprStyle defaultDumpStyle
|
|
1109 | 1109 | |
1110 | 1110 | -- skip the hi way check; we don't want to worry about profiled vs.
|
1111 | 1111 | -- non-profiled interfaces, for example.
|
... | ... | @@ -507,7 +507,7 @@ classifyLdInput logger platform f |
507 | 507 | | isObjectFilename platform f = return (Just (Objects [f]))
|
508 | 508 | | isDynLibFilename platform f = return (Just (DLLPath f))
|
509 | 509 | | otherwise = do
|
510 | - logMsg logger MCInfo noSrcSpan
|
|
510 | + logInfo logger
|
|
511 | 511 | $ withPprStyle defaultUserStyle
|
512 | 512 | (text ("Warning: ignoring unrecognised input `" ++ f ++ "'"))
|
513 | 513 | return Nothing
|
... | ... | @@ -104,6 +104,7 @@ import GHC.Stg.Utils |
104 | 104 | import GHC.Core.DataCon
|
105 | 105 | import GHC.Core ( AltCon(..) )
|
106 | 106 | import GHC.Core.Type
|
107 | +import GHC.Core.Lint ( lintMessage )
|
|
107 | 108 | |
108 | 109 | import GHC.Types.Basic ( TopLevelFlag(..), isTopLevel, isMarkedCbv )
|
109 | 110 | import GHC.Types.CostCentre ( isCurrentCCS )
|
... | ... | @@ -148,8 +149,7 @@ lintStgTopBindings platform logger diag_opts opts extra_vars this_mod unarised w |
148 | 149 | Nothing ->
|
149 | 150 | return ()
|
150 | 151 | Just msg -> do
|
151 | - logMsg logger Err.MCInfo noSrcSpan -- See Note [MCInfo for Lint] in "GHC.Core.Lint"
|
|
152 | - $ withPprStyle defaultDumpStyle
|
|
152 | + lintMessage logger
|
|
153 | 153 | (vcat [ text "*** Stg Lint ErrMsgs: in" <+>
|
154 | 154 | text whodunit <+> text "***",
|
155 | 155 | msg,
|
... | ... | @@ -2343,8 +2343,7 @@ failIfM msg = do |
2343 | 2343 | env <- getLclEnv
|
2344 | 2344 | let full_msg = (if_loc env <> colon) $$ nest 2 msg
|
2345 | 2345 | logger <- getLogger
|
2346 | - liftIO (logMsg logger MCFatal
|
|
2347 | - noSrcSpan $ withPprStyle defaultErrStyle full_msg)
|
|
2346 | + liftIO $ fatalErrorMsg logger full_msg
|
|
2348 | 2347 | failM
|
2349 | 2348 | |
2350 | 2349 | --------------------
|
... | ... | @@ -2376,10 +2375,7 @@ forkM doc thing_inside |
2376 | 2375 | logger <- getLogger
|
2377 | 2376 | let msg = hang (text "forkM failed:" <+> doc)
|
2378 | 2377 | 2 (text (show exn))
|
2379 | - liftIO $ logMsg logger
|
|
2380 | - MCFatal
|
|
2381 | - noSrcSpan
|
|
2382 | - $ withPprStyle defaultErrStyle msg
|
|
2378 | + liftIO $ fatalErrorMsg logger msg
|
|
2383 | 2379 | ; traceIf (text "} ending fork (badly)" <+> doc)
|
2384 | 2380 | ; pgmError "Cannot continue after interface file error" }
|
2385 | 2381 | }
|