Simon Hengel pushed to branch wip/sol/remove-ddump-json at Glasgow Haskell Compiler / GHC

Commits:

30 changed files:

Changes:

  • compiler/GHC/Core/Lint.hs
    ... ... @@ -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 ()
    

  • compiler/GHC/Core/Opt/Monad.hs
    ... ... @@ -362,19 +362,22 @@ we aren't using annotations heavily.
    362 362
     ************************************************************************
    
    363 363
     -}
    
    364 364
     
    
    365
    -msg :: MessageClass -> SDoc -> CoreM ()
    
    366
    -msg msg_class doc = do
    
    365
    +msg :: Message -> CoreM ()
    
    366
    +msg msg = do
    
    367 367
         logger <- getLogger
    
    368
    -    loc    <- getSrcSpanM
    
    369 368
         name_ppr_ctx <- getNamePprCtx
    
    370
    -    let sty = case msg_class of
    
    371
    -                MCDiagnostic _ _ _ -> err_sty
    
    372
    -                MCDump             -> dump_sty
    
    373
    -                _                  -> user_sty
    
    374
    -        err_sty  = mkErrStyle name_ppr_ctx
    
    375
    -        user_sty = mkUserStyle name_ppr_ctx AllTheWay
    
    376
    -        dump_sty = mkDumpStyle name_ppr_ctx
    
    377
    -    liftIO $ logMsg logger msg_class loc (withPprStyle sty doc)
    
    369
    +    let m = case msg of
    
    370
    +                MCDump doc -> MCDump (dump_sty doc)
    
    371
    +                UnsafeMCDiagnostic span severity reason code doc diagnostic -> UnsafeMCDiagnostic span severity reason code (err_sty doc) diagnostic
    
    372
    +                MCOutput doc -> MCOutput (user_sty doc)
    
    373
    +                MCFatal doc -> MCFatal (user_sty doc)
    
    374
    +                MCInteractive doc -> MCInteractive (user_sty doc)
    
    375
    +                MCInfo doc -> MCInfo (user_sty doc)
    
    376
    +
    
    377
    +        err_sty  = withPprStyle $ mkErrStyle name_ppr_ctx
    
    378
    +        user_sty = withPprStyle $ mkUserStyle name_ppr_ctx AllTheWay
    
    379
    +        dump_sty = withPprStyle $ mkDumpStyle name_ppr_ctx
    
    380
    +    liftIO $ logMsg logger m
    
    378 381
     
    
    379 382
     -- | Output a String message to the screen
    
    380 383
     putMsgS :: String -> CoreM ()
    
    ... ... @@ -382,7 +385,7 @@ putMsgS = putMsg . text
    382 385
     
    
    383 386
     -- | Output a message to the screen
    
    384 387
     putMsg :: SDoc -> CoreM ()
    
    385
    -putMsg = msg MCInfo
    
    388
    +putMsg = msg . MCInfo
    
    386 389
     
    
    387 390
     diagnostic :: DiagnosticReason -> SDoc -> CoreM ()
    
    388 391
     diagnostic reason doc = do
    
    ... ... @@ -407,7 +410,7 @@ fatalErrorMsgS = fatalErrorMsg . text
    407 410
     
    
    408 411
     -- | Output a fatal error to the screen. Does not cause the compiler to die.
    
    409 412
     fatalErrorMsg :: SDoc -> CoreM ()
    
    410
    -fatalErrorMsg = msg MCFatal
    
    413
    +fatalErrorMsg = msg . MCFatal
    
    411 414
     
    
    412 415
     -- | Output a string debugging message at verbosity level of @-v@ or higher
    
    413 416
     debugTraceMsgS :: String -> CoreM ()
    
    ... ... @@ -415,4 +418,4 @@ debugTraceMsgS = debugTraceMsg . text
    415 418
     
    
    416 419
     -- | Outputs a debugging message at verbosity level of @-v@ or higher
    
    417 420
     debugTraceMsg :: SDoc -> CoreM ()
    
    418
    -debugTraceMsg = msg MCDump
    421
    +debugTraceMsg = msg . MCDump

  • compiler/GHC/Driver/CodeOutput.hs
    ... ... @@ -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 ()
    

  • compiler/GHC/Driver/Errors.hs
    ... ... @@ -46,19 +46,16 @@ printMessages logger msg_opts opts = mapM_ (printMessage logger msg_opts opts) .
    46 46
         sortMessages = sortMsgBag (Just opts) . getMessages
    
    47 47
     
    
    48 48
     printMessage :: forall a. (Diagnostic a) => Logger -> DiagnosticOpts a -> DiagOpts -> MsgEnvelope a -> IO ()
    
    49
    -printMessage logger msg_opts opts message
    
    50
    -  | log_diags_as_json = do
    
    51
    -      decorated <- decorateDiagnostic logflags messageClass location doc
    
    52
    -      let
    
    53
    -        rendered :: String
    
    54
    -        rendered = renderWithContext (log_default_user_context logflags) decorated
    
    55
    -
    
    56
    -        jsonMessage :: JsonDoc
    
    57
    -        jsonMessage = jsonDiagnostic rendered message
    
    49
    +printMessage logger msg_opts opts message = do
    
    50
    +  decorated <- decorateDiagnostic logflags location severity reason code doc
    
    51
    +  let
    
    52
    +    rendered :: String
    
    53
    +    rendered = renderWithContext (log_default_user_context logflags) decorated
    
    58 54
     
    
    59
    -      logJsonMsg logger messageClass jsonMessage
    
    55
    +    jsonMessage :: JsonDoc
    
    56
    +    jsonMessage = jsonDiagnostic rendered message
    
    60 57
     
    
    61
    -  | otherwise = logMsg logger messageClass location doc
    
    58
    +  logMsg logger $ UnsafeMCDiagnostic location severity reason code decorated jsonMessage
    
    62 59
       where
    
    63 60
         logflags :: LogFlags
    
    64 61
         logflags = logFlags logger
    
    ... ... @@ -66,9 +63,6 @@ printMessage logger msg_opts opts message
    66 63
         doc :: SDoc
    
    67 64
         doc = updSDocContext (\_ -> ctx) (messageWithHints diagnostic)
    
    68 65
     
    
    69
    -    messageClass :: MessageClass
    
    70
    -    messageClass = UnsafeMCDiagnostic severity (errMsgReason message) (diagnosticCode diagnostic)
    
    71
    -
    
    72 66
         style :: PprStyle
    
    73 67
         style = mkErrStyle (errMsgContext message)
    
    74 68
     
    
    ... ... @@ -84,6 +78,12 @@ printMessage logger msg_opts opts message
    84 78
         severity :: Severity
    
    85 79
         severity = errMsgSeverity message
    
    86 80
     
    
    81
    +    reason :: ResolvedDiagnosticReason
    
    82
    +    reason = errMsgReason message
    
    83
    +
    
    84
    +    code :: Maybe DiagnosticCode
    
    85
    +    code = diagnosticCode diagnostic
    
    86
    +
    
    87 87
         messageWithHints :: a -> SDoc
    
    88 88
         messageWithHints e =
    
    89 89
           let main_msg = formatBulleted $ diagnosticMessage msg_opts e
    
    ... ... @@ -93,8 +93,22 @@ printMessage logger msg_opts opts message
    93 93
                    hs  -> main_msg $$ hang (text "Suggested fixes:") 2
    
    94 94
                                            (formatBulleted  $ mkDecorated . map ppr $ hs)
    
    95 95
     
    
    96
    -    log_diags_as_json :: Bool
    
    97
    -    log_diags_as_json = log_diagnostics_as_json (logFlags logger)
    
    96
    +decorateDiagnostic :: LogFlags -> SrcSpan -> Severity -> ResolvedDiagnosticReason -> Maybe DiagnosticCode -> SDoc -> IO SDoc
    
    97
    +decorateDiagnostic logflags span severity reason code doc = addCaret
    
    98
    +  where
    
    99
    +    -- Pretty print the warning flag, if any (#10752)
    
    100
    +    message :: SDoc
    
    101
    +    message = formatDiagnostic (log_show_warn_groups logflags) span severity reason code doc
    
    102
    +
    
    103
    +    addCaret :: IO SDoc
    
    104
    +    addCaret = do
    
    105
    +      caretDiagnostic <-
    
    106
    +          if log_show_caret logflags
    
    107
    +          then getCaretDiagnostic severity span
    
    108
    +          else pure empty
    
    109
    +      return $ getPprStyle $ \style ->
    
    110
    +        withPprStyle (setStyleColoured True style)
    
    111
    +          (message $+$ caretDiagnostic $+$ blankLine)
    
    98 112
     
    
    99 113
     -- | Given a bag of diagnostics, turn them into an exception if
    
    100 114
     -- any has 'SevError', or print them out otherwise.
    

  • compiler/GHC/Driver/Flags.hs
    ... ... @@ -526,7 +526,6 @@ data DumpFlag
    526 526
        | Opt_D_dump_view_pattern_commoning
    
    527 527
        | Opt_D_verbose_core2core
    
    528 528
        | Opt_D_dump_debug
    
    529
    -   | Opt_D_dump_json
    
    530 529
        | Opt_D_ppr_debug
    
    531 530
        | Opt_D_no_debug_output
    
    532 531
        | Opt_D_dump_faststrings
    

  • compiler/GHC/Driver/Main.hs
    ... ... @@ -1835,7 +1835,7 @@ markUnsafeInfer tcg_env whyUnsafe = do
    1835 1835
                              ]
    
    1836 1836
         badFlags df   = concatMap (badFlag df) unsafeFlagsForInfer
    
    1837 1837
         badFlag df (ext,loc,on,_)
    
    1838
    -        | on df     = [mkLocMessage MCOutput (loc df) $
    
    1838
    +        | on df     = [formatLocMessage (loc df) $
    
    1839 1839
                                 text "-X" <> ppr ext <+> text "is not allowed in Safe Haskell"]
    
    1840 1840
             | otherwise = []
    
    1841 1841
         badInsts insts = concatMap badInst insts
    
    ... ... @@ -1844,9 +1844,10 @@ markUnsafeInfer tcg_env whyUnsafe = do
    1844 1844
         checkOverlap _             = True
    
    1845 1845
     
    
    1846 1846
         badInst ins | checkOverlap (overlapMode (is_flag ins))
    
    1847
    -                = [mkLocMessage MCOutput (nameSrcSpan $ getName $ is_dfun ins) $
    
    1847
    +                = [formatLocMessage (nameSrcSpan $ getName $ is_dfun ins) $
    
    1848 1848
                           ppr (overlapMode $ is_flag ins) <+>
    
    1849
    -                      text "overlap mode isn't allowed in Safe Haskell"]
    
    1849
    +                      text "overlap mode isn't allowed in Safe Haskell"
    
    1850
    +                      ]
    
    1850 1851
                     | otherwise = []
    
    1851 1852
     
    
    1852 1853
     -- | Figure out the final correct safe haskell mode
    

  • compiler/GHC/Driver/Make.hs
    ... ... @@ -1442,14 +1442,14 @@ withDeferredDiagnostics f = do
    1442 1442
         fatals <- liftIO $ newIORef []
    
    1443 1443
         logger <- getLogger
    
    1444 1444
     
    
    1445
    -    let deferDiagnostics _dflags !msgClass !srcSpan !msg = do
    
    1446
    -          let action = logMsg logger msgClass srcSpan msg
    
    1447
    -          case msgClass of
    
    1448
    -            MCDiagnostic SevWarning _reason _code
    
    1445
    +    let deferDiagnostics _dflags !msg = do
    
    1446
    +          let action = logMsg logger msg
    
    1447
    +          case msg of
    
    1448
    +            MCDiagnostic _ SevWarning _reason _code
    
    1449 1449
                   -> atomicModifyIORef' warnings $ \(!i) -> (action: i, ())
    
    1450
    -            MCDiagnostic SevError _reason _code
    
    1450
    +            MCDiagnostic _ SevError _reason _code
    
    1451 1451
                   -> atomicModifyIORef' errors   $ \(!i) -> (action: i, ())
    
    1452
    -            MCFatal
    
    1452
    +            MCFatal _
    
    1453 1453
                   -> atomicModifyIORef' fatals   $ \(!i) -> (action: i, ())
    
    1454 1454
                 _ -> action
    
    1455 1455
     
    

  • compiler/GHC/Driver/Monad.hs
    ... ... @@ -23,8 +23,6 @@ module GHC.Driver.Monad (
    23 23
             modifyLogger,
    
    24 24
             pushLogHookM,
    
    25 25
             popLogHookM,
    
    26
    -        pushJsonLogHookM,
    
    27
    -        popJsonLogHookM,
    
    28 26
             putLogMsgM,
    
    29 27
             putMsgM,
    
    30 28
             withTimingM,
    
    ... ... @@ -47,7 +45,6 @@ import GHC.Utils.Exception
    47 45
     import GHC.Utils.Error
    
    48 46
     import GHC.Utils.Logger
    
    49 47
     
    
    50
    -import GHC.Types.SrcLoc
    
    51 48
     import GHC.Types.SourceError
    
    52 49
     
    
    53 50
     import Control.Monad
    
    ... ... @@ -123,12 +120,6 @@ pushLogHookM = modifyLogger . pushLogHook
    123 120
     popLogHookM :: GhcMonad m => m ()
    
    124 121
     popLogHookM  = modifyLogger popLogHook
    
    125 122
     
    
    126
    -pushJsonLogHookM :: GhcMonad m => (LogJsonAction -> LogJsonAction) -> m ()
    
    127
    -pushJsonLogHookM = modifyLogger . pushJsonLogHook
    
    128
    -
    
    129
    -popJsonLogHookM :: GhcMonad m => m ()
    
    130
    -popJsonLogHookM = modifyLogger popJsonLogHook
    
    131
    -
    
    132 123
     -- | Put a log message
    
    133 124
     putMsgM :: GhcMonad m => SDoc -> m ()
    
    134 125
     putMsgM doc = do
    
    ... ... @@ -136,10 +127,10 @@ putMsgM doc = do
    136 127
         liftIO $ putMsg logger doc
    
    137 128
     
    
    138 129
     -- | Put a log message
    
    139
    -putLogMsgM :: GhcMonad m => MessageClass -> SrcSpan -> SDoc -> m ()
    
    140
    -putLogMsgM msg_class loc doc = do
    
    130
    +putLogMsgM :: GhcMonad m => Message -> m ()
    
    131
    +putLogMsgM message = do
    
    141 132
         logger <- getLogger
    
    142
    -    liftIO $ logMsg logger msg_class loc doc
    
    133
    +    liftIO $ logMsg logger message
    
    143 134
     
    
    144 135
     -- | Time an action
    
    145 136
     withTimingM :: GhcMonad m => SDoc -> (b -> ()) -> m b -> m b
    

  • compiler/GHC/Driver/Pipeline/Execute.hs
    ... ... @@ -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.")
    

  • compiler/GHC/Driver/Pipeline/LogQueue.hs
    ... ... @@ -18,7 +18,6 @@ import GHC.Prelude
    18 18
     import Control.Concurrent
    
    19 19
     import Data.IORef
    
    20 20
     import GHC.Types.Error
    
    21
    -import GHC.Types.SrcLoc
    
    22 21
     import GHC.Utils.Logger
    
    23 22
     import qualified Data.IntMap as IM
    
    24 23
     import Control.Concurrent.STM
    
    ... ... @@ -30,7 +29,7 @@ import Control.Monad
    30 29
     -- to. A 'Nothing' value contains the result of compilation, and denotes the
    
    31 30
     -- end of the message queue.
    
    32 31
     data LogQueue = LogQueue { logQueueId :: !Int
    
    33
    -                         , logQueueMessages :: !(IORef [Maybe (MessageClass, SrcSpan, SDoc, LogFlags)])
    
    32
    +                         , logQueueMessages :: !(IORef [Maybe (Message, LogFlags)])
    
    34 33
                              , logQueueSemaphore :: !(MVar ())
    
    35 34
                              }
    
    36 35
     
    
    ... ... @@ -45,12 +44,12 @@ finishLogQueue lq = do
    45 44
       writeLogQueueInternal lq Nothing
    
    46 45
     
    
    47 46
     
    
    48
    -writeLogQueue :: LogQueue -> (MessageClass,SrcSpan,SDoc, LogFlags) -> IO ()
    
    47
    +writeLogQueue :: LogQueue -> (Message, LogFlags) -> IO ()
    
    49 48
     writeLogQueue lq msg = do
    
    50 49
       writeLogQueueInternal lq (Just msg)
    
    51 50
     
    
    52 51
     -- | Internal helper for writing log messages
    
    53
    -writeLogQueueInternal :: LogQueue -> Maybe (MessageClass,SrcSpan,SDoc, LogFlags) -> IO ()
    
    52
    +writeLogQueueInternal :: LogQueue -> Maybe (Message, LogFlags) -> IO ()
    
    54 53
     writeLogQueueInternal (LogQueue _n ref sem) msg = do
    
    55 54
         atomicModifyIORef' ref $ \msgs -> (msg:msgs,())
    
    56 55
         _ <- tryPutMVar sem ()
    
    ... ... @@ -59,8 +58,8 @@ writeLogQueueInternal (LogQueue _n ref sem) msg = do
    59 58
     -- The log_action callback that is used to synchronize messages from a
    
    60 59
     -- worker thread.
    
    61 60
     parLogAction :: LogQueue -> LogAction
    
    62
    -parLogAction log_queue log_flags !msgClass !srcSpan !msg =
    
    63
    -    writeLogQueue log_queue (msgClass,srcSpan,msg, log_flags)
    
    61
    +parLogAction log_queue log_flags !msg =
    
    62
    +    writeLogQueue log_queue (msg, log_flags)
    
    64 63
     
    
    65 64
     -- Print each message from the log_queue using the global logger
    
    66 65
     printLogs :: Logger -> LogQueue -> IO ()
    
    ... ... @@ -72,8 +71,8 @@ printLogs !logger (LogQueue _n ref sem) = read_msgs
    72 71
     
    
    73 72
             print_loop [] = read_msgs
    
    74 73
             print_loop (x:xs) = case x of
    
    75
    -            Just (msgClass,srcSpan,msg,flags) -> do
    
    76
    -                logMsg (setLogFlags logger flags) msgClass srcSpan msg
    
    74
    +            Just (msg,flags) -> do
    
    75
    +                logMsg (setLogFlags logger flags) msg
    
    77 76
                     print_loop xs
    
    78 77
                 -- Exit the loop once we encounter the end marker.
    
    79 78
                 Nothing -> return ()
    

  • compiler/GHC/Driver/Session.hs
    ... ... @@ -1657,9 +1657,6 @@ dynamic_flags_deps = [
    1657 1657
             (NoArg (setGeneralFlag Opt_NoTypeableBinds))
    
    1658 1658
       , make_ord_flag defGhcFlag "ddump-debug"
    
    1659 1659
             (setDumpFlag Opt_D_dump_debug)
    
    1660
    -  , make_dep_flag defGhcFlag "ddump-json"
    
    1661
    -        (setDumpFlag Opt_D_dump_json)
    
    1662
    -        "Use `-fdiagnostics-as-json` instead"
    
    1663 1660
       , make_ord_flag defGhcFlag "dppr-debug"
    
    1664 1661
             (setDumpFlag Opt_D_ppr_debug)
    
    1665 1662
       , make_ord_flag defGhcFlag "ddebug-output"
    

  • compiler/GHC/Iface/Load.hs
    ... ... @@ -94,7 +94,6 @@ import GHC.Types.SourceFile
    94 94
     import GHC.Types.SafeHaskell
    
    95 95
     import GHC.Types.TypeEnv
    
    96 96
     import GHC.Types.Unique.DSet
    
    97
    -import GHC.Types.SrcLoc
    
    98 97
     import GHC.Types.TyThing
    
    99 98
     import GHC.Types.PkgQual
    
    100 99
     
    
    ... ... @@ -1105,7 +1104,7 @@ For some background on this choice see #15269.
    1105 1104
     showIface :: Logger -> DynFlags -> UnitState -> NameCache -> FilePath -> IO ()
    
    1106 1105
     showIface logger dflags unit_state name_cache filename = do
    
    1107 1106
        let profile = targetProfile dflags
    
    1108
    -       printer = logMsg logger MCOutput noSrcSpan . withPprStyle defaultDumpStyle
    
    1107
    +       printer = logOutput logger . withPprStyle defaultDumpStyle
    
    1109 1108
     
    
    1110 1109
        -- skip the hi way check; we don't want to worry about profiled vs.
    
    1111 1110
        -- non-profiled interfaces, for example.
    
    ... ... @@ -1119,7 +1118,7 @@ showIface logger dflags unit_state name_cache filename = do
    1119 1118
                                        neverQualifyModules
    
    1120 1119
                                        neverQualifyPackages
    
    1121 1120
                                        alwaysPrintPromTick
    
    1122
    -   logMsg logger MCDump noSrcSpan
    
    1121
    +   logMsg logger $ MCDump
    
    1123 1122
           $ withPprStyle (mkDumpStyle name_ppr_ctx)
    
    1124 1123
           $ pprModIface unit_state iface
    
    1125 1124
     
    

  • compiler/GHC/Linker/Deps.hs
    ... ... @@ -25,6 +25,7 @@ import GHC.Linker.Types
    25 25
     import GHC.Types.SrcLoc
    
    26 26
     import GHC.Types.Unique.DSet
    
    27 27
     import GHC.Types.Unique.DFM
    
    28
    +import GHC.Types.Error (formatFatalLocMessage)
    
    28 29
     
    
    29 30
     import GHC.Utils.Outputable
    
    30 31
     import GHC.Utils.Panic
    
    ... ... @@ -231,7 +232,7 @@ splice point about what we would prefer.
    231 232
     -}
    
    232 233
     
    
    233 234
     dieWith :: LinkDepsOpts -> SrcSpan -> SDoc -> IO a
    
    234
    -dieWith opts span msg = throwProgramError opts (mkLocMessage MCFatal span msg)
    
    235
    +dieWith opts span msg = throwProgramError opts (formatFatalLocMessage span msg)
    
    235 236
     
    
    236 237
     throwProgramError :: LinkDepsOpts -> SDoc -> IO a
    
    237 238
     throwProgramError opts doc = throwGhcExceptionIO (ProgramError (renderWithContext (ldPprOpts opts) doc))
    

  • compiler/GHC/Linker/Loader.hs
    ... ... @@ -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
    
    ... ... @@ -1638,9 +1638,8 @@ addEnvPaths name list
    1638 1638
     maybePutSDoc :: Logger -> SDoc -> IO ()
    
    1639 1639
     maybePutSDoc logger s
    
    1640 1640
         = when (logVerbAtLeast logger 2) $
    
    1641
    -          logMsg logger
    
    1641
    +          logMsg logger $
    
    1642 1642
                   MCInteractive
    
    1643
    -              noSrcSpan
    
    1644 1643
                   $ withPprStyle defaultUserStyle s
    
    1645 1644
     
    
    1646 1645
     maybePutStr :: Logger -> String -> IO ()
    

  • compiler/GHC/Runtime/Debugger.hs
    ... ... @@ -209,7 +209,7 @@ showTerm term = do
    209 209
                     setSession new_env
    
    210 210
     
    
    211 211
                     -- this disables logging of errors
    
    212
    -                let noop_log _ _ _ _ = return ()
    
    212
    +                let noop_log _ _ = return ()
    
    213 213
                     pushLogHookM (const noop_log)
    
    214 214
     
    
    215 215
                     return (hsc_env, bname)
    

  • compiler/GHC/Stg/Lint.hs
    ... ... @@ -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,
    

  • compiler/GHC/Tc/Utils/Monad.hs
    ... ... @@ -864,7 +864,7 @@ wrapDocLoc doc = do
    864 864
       if logHasDumpFlag logger Opt_D_ppr_debug
    
    865 865
         then do
    
    866 866
           loc <- getSrcSpanM
    
    867
    -      return (mkLocMessage MCOutput loc doc)
    
    867
    +      return (formatLocMessage loc doc)
    
    868 868
         else
    
    869 869
           return doc
    
    870 870
     
    
    ... ... @@ -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
         }
    

  • compiler/GHC/Types/Error.hs
    ... ... @@ -26,7 +26,7 @@ module GHC.Types.Error
    26 26
     
    
    27 27
        -- * Classifying Messages
    
    28 28
     
    
    29
    -   , MessageClass (MCDiagnostic, ..)
    
    29
    +   , Message (MCDiagnostic, ..)
    
    30 30
        , Severity (..)
    
    31 31
        , Diagnostic (..)
    
    32 32
        , UnknownDiagnostic (..)
    
    ... ... @@ -70,8 +70,8 @@ module GHC.Types.Error
    70 70
        , mapDecoratedSDoc
    
    71 71
     
    
    72 72
        , pprMessageBag
    
    73
    -   , mkLocMessage
    
    74
    -   , mkLocMessageWarningGroups
    
    73
    +   , formatLocMessage
    
    74
    +   , formatFatalLocMessage
    
    75 75
        , formatDiagnostic
    
    76 76
        , getCaretDiagnostic
    
    77 77
     
    
    ... ... @@ -479,22 +479,22 @@ data MsgEnvelope e = MsgEnvelope
    479 479
     -- | The class for a diagnostic message. The main purpose is to classify a
    
    480 480
     -- message within GHC, to distinguish it from a debug/dump message vs a proper
    
    481 481
     -- diagnostic, for which we include a 'DiagnosticReason'.
    
    482
    -data MessageClass
    
    483
    -  = MCOutput
    
    484
    -  | MCFatal
    
    485
    -  | MCInteractive
    
    482
    +data Message
    
    483
    +  = MCOutput SDoc
    
    484
    +  | MCFatal SDoc
    
    485
    +  | MCInteractive SDoc
    
    486 486
     
    
    487
    -  | MCDump
    
    487
    +  | MCDump SDoc
    
    488 488
         -- ^ Log message intended for compiler developers
    
    489 489
         -- No file\/line\/column stuff
    
    490 490
     
    
    491
    -  | MCInfo
    
    491
    +  | MCInfo SDoc
    
    492 492
         -- ^ Log messages intended for end users.
    
    493 493
         -- No file\/line\/column stuff.
    
    494 494
     
    
    495
    -  | UnsafeMCDiagnostic Severity ResolvedDiagnosticReason (Maybe DiagnosticCode)
    
    495
    +  | UnsafeMCDiagnostic SrcSpan Severity ResolvedDiagnosticReason (Maybe DiagnosticCode) SDoc JsonDoc
    
    496 496
         -- ^ Diagnostics from the compiler. This constructor is very powerful as
    
    497
    -    -- it allows the construction of a 'MessageClass' with a completely
    
    497
    +    -- it allows the construction of a 'Message' with a completely
    
    498 498
         -- arbitrary permutation of 'Severity' and 'DiagnosticReason'. As such,
    
    499 499
         -- users are encouraged to use higher level primitives
    
    500 500
         -- instead. Use this constructor directly only if you need to construct
    
    ... ... @@ -508,8 +508,8 @@ data MessageClass
    508 508
         -- should always have a 'DiagnosticCode'. See Note [Diagnostic codes].
    
    509 509
     
    
    510 510
     {-# COMPLETE MCOutput, MCFatal, MCInteractive, MCDump, MCInfo, MCDiagnostic #-}
    
    511
    -pattern MCDiagnostic :: Severity -> ResolvedDiagnosticReason -> Maybe DiagnosticCode -> MessageClass
    
    512
    -pattern MCDiagnostic severity reason code <- UnsafeMCDiagnostic severity reason code
    
    511
    +pattern MCDiagnostic :: SrcSpan -> Severity -> ResolvedDiagnosticReason -> Maybe DiagnosticCode -> Message
    
    512
    +pattern MCDiagnostic span severity reason code <- UnsafeMCDiagnostic span severity reason code _diagnostic _json
    
    513 513
     
    
    514 514
     {-
    
    515 515
     Note [Suppressing Messages]
    
    ... ... @@ -538,9 +538,6 @@ the "SevIgnore one" for a number of reasons:
    538 538
     
    
    539 539
     
    
    540 540
     -- | Used to describe warnings and errors
    
    541
    ---   o The message has a file\/line\/column heading,
    
    542
    ---     plus "warning:" or "error:",
    
    543
    ---     added by mkLocMessage
    
    544 541
     --   o With 'SevIgnore' the message is suppressed
    
    545 542
     --   o Output is intended for end users
    
    546 543
     data Severity
    
    ... ... @@ -563,15 +560,6 @@ instance ToJson Severity where
    563 560
       json SevWarning = JSString "Warning"
    
    564 561
       json SevError = JSString "Error"
    
    565 562
     
    
    566
    -instance ToJson MessageClass where
    
    567
    -  json MCOutput = JSString "MCOutput"
    
    568
    -  json MCFatal  = JSString "MCFatal"
    
    569
    -  json MCInteractive = JSString "MCInteractive"
    
    570
    -  json MCDump = JSString "MCDump"
    
    571
    -  json MCInfo = JSString "MCInfo"
    
    572
    -  json (MCDiagnostic sev reason code) =
    
    573
    -    JSString $ renderWithContext defaultSDocContext (ppr $ text "MCDiagnostic" <+> ppr sev <+> ppr reason <+> ppr code)
    
    574
    -
    
    575 563
     instance ToJson DiagnosticCode where
    
    576 564
       json c = JSInt (fromIntegral (diagnosticCodeNumber c))
    
    577 565
     
    
    ... ... @@ -646,35 +634,14 @@ showMsgEnvelope err =
    646 634
     pprMessageBag :: Bag SDoc -> SDoc
    
    647 635
     pprMessageBag msgs = vcat (punctuate blankLine (bagToList msgs))
    
    648 636
     
    
    649
    -mkLocMessage
    
    650
    -  :: MessageClass                       -- ^ What kind of message?
    
    651
    -  -> SrcSpan                            -- ^ location
    
    652
    -  -> SDoc                               -- ^ message
    
    653
    -  -> SDoc
    
    654
    -mkLocMessage = mkLocMessageWarningGroups True
    
    655
    -
    
    656
    --- | Make an error message with location info, specifying whether to show
    
    657
    --- warning groups (if applicable).
    
    658
    -mkLocMessageWarningGroups
    
    659
    -  :: Bool                               -- ^ Print warning groups (if applicable)?
    
    660
    -  -> MessageClass                       -- ^ What kind of message?
    
    661
    -  -> SrcSpan                            -- ^ location
    
    662
    -  -> SDoc                               -- ^ message
    
    663
    -  -> SDoc
    
    664
    -mkLocMessageWarningGroups show_warn_groups msg_class locn msg
    
    665
    -  = case msg_class of
    
    666
    -    MCDiagnostic severity reason code -> formatDiagnostic show_warn_groups locn severity reason code msg
    
    667
    -    _ -> sdocOption sdocColScheme $ \col_scheme ->
    
    668
    -      let
    
    669
    -          msg_colour = getMessageClassColour msg_class col_scheme
    
    670
    -
    
    671
    -          msg_title = coloured msg_colour $
    
    672
    -            case msg_class of
    
    673
    -              MCFatal                     -> text "fatal"
    
    674
    -              _                           -> empty
    
    675
    -
    
    637
    +formatFatalLocMessage :: SrcSpan -> SDoc -> SDoc
    
    638
    +formatFatalLocMessage locn msg = sdocOption sdocColScheme $ \col_scheme ->
    
    639
    +      let msg_title = coloured (Col.sFatal col_scheme) $ text "fatal"
    
    676 640
           in formatLocMessageWarningGroups locn msg_title empty empty msg
    
    677 641
     
    
    642
    +formatLocMessage :: SrcSpan -> SDoc -> SDoc
    
    643
    +formatLocMessage span = formatLocMessageWarningGroups span empty empty empty
    
    644
    +
    
    678 645
     formatDiagnostic
    
    679 646
       :: Bool                               -- ^ Print warning groups?
    
    680 647
       -> SrcSpan                            -- ^ location
    
    ... ... @@ -784,13 +751,7 @@ formatLocMessageWarningGroups locn msg_title code_doc warning_flag_doc msg
    784 751
                        code_doc <+> warning_flag_doc
    
    785 752
     
    
    786 753
           in coloured (Col.sMessage col_scheme)
    
    787
    -                  (hang (coloured (Col.sHeader col_scheme) header) 4
    
    788
    -                        msg)
    
    789
    -
    
    790
    -getMessageClassColour :: MessageClass -> Col.Scheme -> Col.PprColour
    
    791
    -getMessageClassColour (MCDiagnostic severity _reason _code)   = getSeverityColour severity
    
    792
    -getMessageClassColour MCFatal                                 = Col.sFatal
    
    793
    -getMessageClassColour _                                       = const mempty
    
    754
    +                  $ hang (coloured (Col.sHeader col_scheme) header) 4 msg
    
    794 755
     
    
    795 756
     getSeverityColour :: Severity -> Col.Scheme -> Col.PprColour
    
    796 757
     getSeverityColour severity = case severity of
    
    ... ... @@ -798,9 +759,9 @@ getSeverityColour severity = case severity of
    798 759
       SevWarning -> Col.sWarning
    
    799 760
       SevIgnore -> const mempty
    
    800 761
     
    
    801
    -getCaretDiagnostic :: MessageClass -> SrcSpan -> IO SDoc
    
    762
    +getCaretDiagnostic :: Severity -> SrcSpan -> IO SDoc
    
    802 763
     getCaretDiagnostic _ (UnhelpfulSpan _) = pure empty
    
    803
    -getCaretDiagnostic msg_class (RealSrcSpan span _) =
    
    764
    +getCaretDiagnostic severity (RealSrcSpan span _) =
    
    804 765
       caretDiagnostic <$> getSrcLine (srcSpanFile span) row
    
    805 766
       where
    
    806 767
         getSrcLine fn i =
    
    ... ... @@ -833,7 +794,7 @@ getCaretDiagnostic msg_class (RealSrcSpan span _) =
    833 794
         caretDiagnostic Nothing = empty
    
    834 795
         caretDiagnostic (Just srcLineWithNewline) =
    
    835 796
           sdocOption sdocColScheme$ \col_scheme ->
    
    836
    -      let sevColour = getMessageClassColour msg_class col_scheme
    
    797
    +      let sevColour = getSeverityColour severity col_scheme
    
    837 798
               marginColour = Col.sMargin col_scheme
    
    838 799
           in
    
    839 800
           coloured marginColour (text marginSpace) <>
    

  • compiler/GHC/Utils/Error.hs
    ... ... @@ -14,7 +14,7 @@ module GHC.Utils.Error (
    14 14
             -- * Messages
    
    15 15
             Diagnostic(..),
    
    16 16
             MsgEnvelope(..),
    
    17
    -        MessageClass(..),
    
    17
    +        Message(..),
    
    18 18
             SDoc,
    
    19 19
             DecoratedSDoc(unDecorated),
    
    20 20
             Messages,
    
    ... ... @@ -28,7 +28,7 @@ module GHC.Utils.Error (
    28 28
     
    
    29 29
             -- ** Construction
    
    30 30
             DiagOpts (..), emptyDiagOpts, diag_wopt, diag_fatal_wopt,
    
    31
    -        emptyMessages, mkDecorated, mkLocMessage,
    
    31
    +        emptyMessages, mkDecorated,
    
    32 32
             mkMsgEnvelope, mkPlainMsgEnvelope, mkPlainErrorMsgEnvelope,
    
    33 33
             mkErrorMsgEnvelope,
    
    34 34
             mkLintWarning, diagReasonSeverity,
    
    ... ... @@ -282,9 +282,8 @@ unsafePprLocMsgEnvelope opts (MsgEnvelope { errMsgSpan = s
    282 282
                                    , errMsgContext   = name_ppr_ctx
    
    283 283
                                    , errMsgReason    = reason })
    
    284 284
       = withErrStyle name_ppr_ctx $
    
    285
    -      mkLocMessage
    
    286
    -        (UnsafeMCDiagnostic sev reason (diagnosticCode e))
    
    287
    -        s
    
    285
    +      formatDiagnostic True
    
    286
    +        s sev reason (diagnosticCode e)
    
    288 287
             (formatBulleted $ diagnosticMessage opts e)
    
    289 288
     
    
    290 289
     sortMsgBag :: Maybe DiagOpts -> Bag (MsgEnvelope e) -> [MsgEnvelope e]
    
    ... ... @@ -314,7 +313,7 @@ ghcExit logger val
    314 313
     
    
    315 314
     fatalErrorMsg :: Logger -> SDoc -> IO ()
    
    316 315
     fatalErrorMsg logger msg =
    
    317
    -    logMsg logger MCFatal noSrcSpan $ withPprStyle defaultErrStyle msg
    
    316
    +    logMsg logger $ MCFatal (withPprStyle defaultErrStyle msg)
    
    318 317
     
    
    319 318
     compilationProgressMsg :: Logger -> SDoc -> IO ()
    
    320 319
     compilationProgressMsg logger msg = do
    
    ... ... @@ -475,11 +474,11 @@ printOutputForUser logger name_ppr_ctx msg
    475 474
       = logOutput logger (withUserStyle name_ppr_ctx AllTheWay msg)
    
    476 475
     
    
    477 476
     logInfo :: Logger -> SDoc -> IO ()
    
    478
    -logInfo logger msg = logMsg logger MCInfo noSrcSpan msg
    
    477
    +logInfo logger = logMsg logger . MCInfo
    
    479 478
     
    
    480 479
     -- | Like 'logInfo' but with 'SevOutput' rather then 'SevInfo'
    
    481 480
     logOutput :: Logger -> SDoc -> IO ()
    
    482
    -logOutput logger msg = logMsg logger MCOutput noSrcSpan msg
    
    481
    +logOutput logger = logMsg logger . MCOutput
    
    483 482
     
    
    484 483
     
    
    485 484
     prettyPrintGhcErrors :: ExceptionMonad m => Logger -> m a -> m a
    

  • compiler/GHC/Utils/Logger.hs
    ... ... @@ -24,7 +24,6 @@ module GHC.Utils.Logger
    24 24
         -- * Logger setup
    
    25 25
         , initLogger
    
    26 26
         , LogAction
    
    27
    -    , LogJsonAction
    
    28 27
         , DumpAction
    
    29 28
         , TraceAction
    
    30 29
         , DumpFormat (..)
    
    ... ... @@ -32,8 +31,6 @@ module GHC.Utils.Logger
    32 31
         -- ** Hooks
    
    33 32
         , popLogHook
    
    34 33
         , pushLogHook
    
    35
    -    , popJsonLogHook
    
    36
    -    , pushJsonLogHook
    
    37 34
         , popDumpHook
    
    38 35
         , pushDumpHook
    
    39 36
         , popTraceHook
    
    ... ... @@ -55,15 +52,11 @@ module GHC.Utils.Logger
    55 52
         , putLogMsg
    
    56 53
         , defaultLogAction
    
    57 54
         , defaultLogActionWithHandles
    
    58
    -    , defaultLogJsonAction
    
    59 55
         , defaultLogActionHPrintDoc
    
    60 56
         , defaultLogActionHPutStrDoc
    
    61 57
         , logMsg
    
    62
    -    , logJsonMsg
    
    63 58
         , logDumpMsg
    
    64 59
     
    
    65
    -    , decorateDiagnostic
    
    66
    -
    
    67 60
         -- * Dumping
    
    68 61
         , defaultDumpAction
    
    69 62
         , putDumpFile
    
    ... ... @@ -85,16 +78,14 @@ where
    85 78
     import GHC.Prelude
    
    86 79
     import GHC.Driver.Flags
    
    87 80
     import GHC.Types.Error
    
    88
    -import GHC.Types.SrcLoc
    
    89 81
     
    
    90 82
     import qualified GHC.Utils.Ppr as Pretty
    
    91 83
     import GHC.Utils.Outputable
    
    92
    -import GHC.Utils.Json
    
    93 84
     import GHC.Utils.Panic
    
    85
    +import GHC.Utils.Json (renderJSON)
    
    94 86
     
    
    95 87
     import GHC.Data.EnumSet (EnumSet)
    
    96 88
     import qualified GHC.Data.EnumSet as EnumSet
    
    97
    -import GHC.Data.FastString
    
    98 89
     
    
    99 90
     import System.Directory
    
    100 91
     import System.FilePath  ( takeDirectory, (</>) )
    
    ... ... @@ -182,16 +173,9 @@ setLogFlags logger flags = logger { logFlags = flags }
    182 173
     ---------------------------------------------------------------
    
    183 174
     
    
    184 175
     type LogAction = LogFlags
    
    185
    -              -> MessageClass
    
    186
    -              -> SrcSpan
    
    187
    -              -> SDoc
    
    176
    +              -> Message
    
    188 177
                   -> IO ()
    
    189 178
     
    
    190
    -type LogJsonAction = LogFlags
    
    191
    -                   -> MessageClass
    
    192
    -                   -> JsonDoc
    
    193
    -                   -> IO ()
    
    194
    -
    
    195 179
     type DumpAction = LogFlags
    
    196 180
                    -> PprStyle
    
    197 181
                    -> DumpFlag
    
    ... ... @@ -229,9 +213,6 @@ data Logger = Logger
    229 213
         { log_hook   :: [LogAction -> LogAction]
    
    230 214
             -- ^ Log hooks stack
    
    231 215
     
    
    232
    -    , json_log_hook :: [LogJsonAction -> LogJsonAction]
    
    233
    -        -- ^ Json log hooks stack
    
    234
    -
    
    235 216
         , dump_hook  :: [DumpAction -> DumpAction]
    
    236 217
             -- ^ Dump hooks stack
    
    237 218
     
    
    ... ... @@ -267,7 +248,6 @@ initLogger = do
    267 248
         dumps <- newMVar Map.empty
    
    268 249
         return $ Logger
    
    269 250
             { log_hook        = []
    
    270
    -        , json_log_hook   = []
    
    271 251
             , dump_hook       = []
    
    272 252
             , trace_hook      = []
    
    273 253
             , generated_dumps = dumps
    
    ... ... @@ -279,10 +259,6 @@ initLogger = do
    279 259
     putLogMsg :: Logger -> LogAction
    
    280 260
     putLogMsg logger = foldr ($) defaultLogAction (log_hook logger)
    
    281 261
     
    
    282
    --- | Log a JsonDoc
    
    283
    -putJsonLogMsg :: Logger -> LogJsonAction
    
    284
    -putJsonLogMsg logger = foldr ($) defaultLogJsonAction (json_log_hook logger)
    
    285
    -
    
    286 262
     -- | Dump something
    
    287 263
     putDumpFile :: Logger -> DumpAction
    
    288 264
     putDumpFile logger =
    
    ... ... @@ -307,15 +283,6 @@ popLogHook logger = case log_hook logger of
    307 283
         []   -> panic "popLogHook: empty hook stack"
    
    308 284
         _:hs -> logger { log_hook = hs }
    
    309 285
     
    
    310
    --- | Push a json log hook
    
    311
    -pushJsonLogHook :: (LogJsonAction -> LogJsonAction) -> Logger -> Logger
    
    312
    -pushJsonLogHook h logger = logger { json_log_hook = h:json_log_hook logger }
    
    313
    -
    
    314
    -popJsonLogHook :: Logger -> Logger
    
    315
    -popJsonLogHook logger = case json_log_hook logger of
    
    316
    -    []   -> panic "popJsonLogHook: empty hook stack"
    
    317
    -    _:hs -> logger { json_log_hook = hs}
    
    318
    -
    
    319 286
     -- | Push a dump hook
    
    320 287
     pushDumpHook :: (DumpAction -> DumpAction) -> Logger -> Logger
    
    321 288
     pushDumpHook h logger = logger { dump_hook = h:dump_hook logger }
    
    ... ... @@ -344,8 +311,8 @@ makeThreadSafe logger = do
    344 311
             with_lock :: forall a. IO a -> IO a
    
    345 312
             with_lock act = withMVar lock (const act)
    
    346 313
     
    
    347
    -        log action logflags msg_class loc doc =
    
    348
    -            with_lock (action logflags msg_class loc doc)
    
    314
    +        log action logflags message =
    
    315
    +            with_lock (action logflags message)
    
    349 316
     
    
    350 317
             dmp action logflags sty opts str fmt doc =
    
    351 318
                 with_lock (action logflags sty opts str fmt doc)
    
    ... ... @@ -359,49 +326,6 @@ makeThreadSafe logger = do
    359 326
                $ pushTraceHook trc
    
    360 327
                $ logger
    
    361 328
     
    
    362
    --- See Note [JSON Error Messages]
    
    363
    -defaultLogJsonAction :: LogJsonAction
    
    364
    -defaultLogJsonAction logflags msg_class jsdoc =
    
    365
    -  case msg_class of
    
    366
    -      MCOutput                     -> printOut msg
    
    367
    -      MCDump                       -> printOut (msg $$ blankLine)
    
    368
    -      MCInteractive                -> putStrSDoc msg
    
    369
    -      MCInfo                       -> printErrs msg
    
    370
    -      MCFatal                      -> printErrs msg
    
    371
    -      MCDiagnostic SevIgnore _ _   -> pure () -- suppress the message
    
    372
    -      MCDiagnostic _sev _rea _code -> printErrs msg
    
    373
    -  where
    
    374
    -    printOut   = defaultLogActionHPrintDoc  logflags False stdout
    
    375
    -    printErrs  = defaultLogActionHPrintDoc  logflags False stderr
    
    376
    -    putStrSDoc = defaultLogActionHPutStrDoc logflags False stdout
    
    377
    -    msg = renderJSON jsdoc
    
    378
    -
    
    379
    --- See Note [JSON Error Messages]
    
    380
    --- this is to be removed
    
    381
    -jsonLogActionWithHandle :: Handle {-^ Standard out -} -> LogAction
    
    382
    -jsonLogActionWithHandle _ _ (MCDiagnostic SevIgnore _ _) _ _ = return () -- suppress the message
    
    383
    -jsonLogActionWithHandle out logflags msg_class srcSpan msg
    
    384
    -  =
    
    385
    -    defaultLogActionHPutStrDoc logflags True out
    
    386
    -      (withPprStyle PprCode (doc $$ text ""))
    
    387
    -    where
    
    388
    -      str = renderWithContext (log_default_user_context logflags) msg
    
    389
    -      doc = renderJSON $
    
    390
    -              JSObject [ ( "span", spanToDumpJSON srcSpan )
    
    391
    -                       , ( "doc" , JSString str )
    
    392
    -                       , ( "messageClass", json msg_class )
    
    393
    -                       ]
    
    394
    -      spanToDumpJSON :: SrcSpan -> JsonDoc
    
    395
    -      spanToDumpJSON s = case s of
    
    396
    -                 (RealSrcSpan rss _) -> JSObject [ ("file", json file)
    
    397
    -                                                , ("startLine", json $ srcSpanStartLine rss)
    
    398
    -                                                , ("startCol", json $ srcSpanStartCol rss)
    
    399
    -                                                , ("endLine", json $ srcSpanEndLine rss)
    
    400
    -                                                , ("endCol", json $ srcSpanEndCol rss)
    
    401
    -                                                ]
    
    402
    -                   where file = unpackFS $ srcSpanFile rss
    
    403
    -                 UnhelpfulSpan _ -> JSNull
    
    404
    -
    
    405 329
     -- | The default 'LogAction' prints to 'stdout' and 'stderr'.
    
    406 330
     --
    
    407 331
     -- To replicate the default log action behaviour with different @out@ and @err@
    
    ... ... @@ -412,72 +336,24 @@ defaultLogAction = defaultLogActionWithHandles stdout stderr
    412 336
     -- | The default 'LogAction' parametrized over the standard output and standard error handles.
    
    413 337
     -- Allows clients to replicate the log message formatting of GHC with custom handles.
    
    414 338
     defaultLogActionWithHandles :: Handle {-^ Handle for standard output -} -> Handle {-^ Handle for standard errors -} -> LogAction
    
    415
    -defaultLogActionWithHandles out err logflags msg_class srcSpan msg
    
    416
    -  | log_dopt Opt_D_dump_json logflags = jsonLogActionWithHandle out logflags msg_class srcSpan msg
    
    417
    -  | otherwise = case msg_class of
    
    418
    -      MCOutput                     -> printOut msg
    
    419
    -      MCDump                       -> printOut (msg $$ blankLine)
    
    420
    -      MCInteractive                -> putStrSDoc msg
    
    421
    -      MCInfo                       -> printErrs msg
    
    422
    -      MCFatal                      -> printErrs msg
    
    423
    -      MCDiagnostic SevIgnore _ _   -> pure () -- suppress the message
    
    424
    -      MCDiagnostic _sev _rea _code -> decorateDiagnostic logflags msg_class srcSpan msg >>= printErrs
    
    339
    +defaultLogActionWithHandles out err logflags message
    
    340
    +  = case message of
    
    341
    +      MCOutput msg -> printOut msg
    
    342
    +      MCDump msg -> printOut (msg $$ blankLine)
    
    343
    +      MCInteractive msg -> putStrSDoc msg
    
    344
    +      MCInfo msg -> printErrs msg
    
    345
    +      MCFatal msg -> printErrs msg
    
    346
    +      MCDiagnostic _ SevIgnore _ _ -> pure () -- suppress the message
    
    347
    +      UnsafeMCDiagnostic _span _severity _reason _code doc json -> do
    
    348
    +        if log_diagnostics_as_json logflags then do
    
    349
    +          printErrs (renderJSON json)
    
    350
    +        else do
    
    351
    +          printErrs doc
    
    425 352
         where
    
    426 353
           printOut   = defaultLogActionHPrintDoc  logflags False out
    
    427 354
           printErrs  = defaultLogActionHPrintDoc  logflags False err
    
    428 355
           putStrSDoc = defaultLogActionHPutStrDoc logflags False out
    
    429 356
     
    
    430
    --- This function is used by `defaultLogActionWithHandles` for non-JSON output,
    
    431
    --- and also by `GHC.Driver.Errors.printMessages` to produce the `rendered`
    
    432
    --- message on `-fdiagnostics-as-json`.
    
    433
    ---
    
    434
    --- We would want to eventually consolidate this.  However, this is currently
    
    435
    --- not feasible for the following reasons:
    
    436
    ---
    
    437
    --- 1. Some parts of the compiler sidestep `printMessages`, for that reason we
    
    438
    ---    can not decorate the message in `printMessages`.
    
    439
    ---
    
    440
    --- 2. GHC uses two different code paths for JSON and non-JSON diagnostics.  For
    
    441
    ---    that reason we can not decorate the message in `defaultLogActionWithHandles`.
    
    442
    ---
    
    443
    ---    See also Note [JSON Error Messages]:
    
    444
    ---
    
    445
    ---      `jsonLogAction` should be removed along with -ddump-json
    
    446
    ---
    
    447
    --- Also note that (1) is the reason why some parts of the compiler produce
    
    448
    --- diagnostics that don't respect `-fdiagnostics-as-json`.
    
    449
    ---
    
    450
    --- The plan as I see it is as follows:
    
    451
    ---
    
    452
    ---  1. Refactor all places in the compiler that report diagnostics to go
    
    453
    ---     through `GHC.Driver.Errors.printMessages`.
    
    454
    ---
    
    455
    ---     (It's easy to find all those places by looking for who creates
    
    456
    ---     MCDiagnostic, either directly or via `mkMCDiagnostic` or
    
    457
    ---     `errorDiagnostic`.)
    
    458
    ---
    
    459
    ---  2. Get rid of `-ddump-json`, `jsonLogAction` and consolidate message
    
    460
    ---     decoration at one place (either `printMessages` or
    
    461
    ---     `defaultLogActionWithHandles`)
    
    462
    ---
    
    463
    --- This story is tracked by #24113.
    
    464
    -decorateDiagnostic :: LogFlags -> MessageClass -> SrcSpan -> SDoc -> IO SDoc
    
    465
    -decorateDiagnostic logflags msg_class srcSpan msg = addCaret
    
    466
    -    where
    
    467
    -      -- Pretty print the warning flag, if any (#10752)
    
    468
    -      message :: SDoc
    
    469
    -      message = mkLocMessageWarningGroups (log_show_warn_groups logflags) msg_class srcSpan msg
    
    470
    -
    
    471
    -      addCaret :: IO SDoc
    
    472
    -      addCaret = do
    
    473
    -        caretDiagnostic <-
    
    474
    -            if log_show_caret logflags
    
    475
    -            then getCaretDiagnostic msg_class srcSpan
    
    476
    -            else pure empty
    
    477
    -        return $ getPprStyle $ \style ->
    
    478
    -          withPprStyle (setStyleColoured True style)
    
    479
    -            (message $+$ caretDiagnostic $+$ blankLine)
    
    480
    -
    
    481 357
     -- | Like 'defaultLogActionHPutStrDoc' but appends an extra newline.
    
    482 358
     defaultLogActionHPrintDoc :: LogFlags -> Bool -> Handle -> SDoc -> IO ()
    
    483 359
     defaultLogActionHPrintDoc logflags asciiSpace h d
    
    ... ... @@ -491,28 +367,6 @@ defaultLogActionHPutStrDoc logflags asciiSpace h d
    491 367
       -- calls to this log-action can output all on the same line
    
    492 368
       = printSDoc (log_default_user_context logflags) (Pretty.PageMode asciiSpace) h d
    
    493 369
     
    
    494
    ---
    
    495
    --- Note [JSON Error Messages]
    
    496
    --- ~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    497
    ---
    
    498
    --- When the user requests the compiler output to be dumped as json
    
    499
    --- we used to collect them all in an IORef and then print them at the end.
    
    500
    --- This doesn't work very well with GHCi. (See #14078) So instead we now
    
    501
    --- use the simpler method of just outputting a JSON document inplace to
    
    502
    --- stdout.
    
    503
    ---
    
    504
    --- Before the compiler calls log_action, it has already turned the `ErrMsg`
    
    505
    --- into a formatted message. This means that we lose some possible
    
    506
    --- information to provide to the user but refactoring log_action is quite
    
    507
    --- invasive as it is called in many places. So, for now I left it alone
    
    508
    --- and we can refine its behaviour as users request different output.
    
    509
    ---
    
    510
    --- The recent work here replaces the purpose of flag -ddump-json with
    
    511
    --- -fdiagnostics-as-json. For temporary backwards compatibility while
    
    512
    --- -ddump-json is being deprecated, `jsonLogAction` has been added in, but
    
    513
    --- it should be removed along with -ddump-json. Similarly, the guard in
    
    514
    --- `defaultLogAction` should be removed. This cleanup is tracked in #24113.
    
    515
    -
    
    516 370
     -- | Default action for 'dumpAction' hook
    
    517 371
     defaultDumpAction :: DumpCache -> LogAction -> DumpAction
    
    518 372
     defaultDumpAction dumps log_action logflags sty flag title _fmt doc =
    
    ... ... @@ -545,10 +399,10 @@ dumpSDocWithStyle dumps log_action sty logflags flag hdr doc =
    545 399
     
    
    546 400
         -- write the dump to stdout
    
    547 401
         writeDump Nothing = do
    
    548
    -        let (doc', msg_class)
    
    549
    -              | null hdr  = (doc, MCOutput)
    
    550
    -              | otherwise = (mkDumpDoc hdr doc, MCDump)
    
    551
    -        log_action logflags msg_class noSrcSpan (withPprStyle sty doc')
    
    402
    +        let message
    
    403
    +              | null hdr  = MCOutput (withPprStyle sty doc)
    
    404
    +              | otherwise = MCDump (withPprStyle sty $ mkDumpDoc hdr doc)
    
    405
    +        log_action logflags message
    
    552 406
     
    
    553 407
     
    
    554 408
     -- | Run an action with the handle of a 'DumpFlag' if we are outputting to a
    
    ... ... @@ -638,11 +492,8 @@ defaultTraceAction logflags title doc x =
    638 492
     
    
    639 493
     
    
    640 494
     -- | Log something
    
    641
    -logMsg :: Logger -> MessageClass -> SrcSpan -> SDoc -> IO ()
    
    642
    -logMsg logger mc loc msg = putLogMsg logger (logFlags logger) mc loc msg
    
    643
    -
    
    644
    -logJsonMsg :: Logger -> MessageClass -> JsonDoc -> IO ()
    
    645
    -logJsonMsg logger mc = putJsonLogMsg logger (logFlags logger) mc
    
    495
    +logMsg :: Logger -> Message -> IO ()
    
    496
    +logMsg logger = putLogMsg logger (logFlags logger)
    
    646 497
     
    
    647 498
     -- | Dump something
    
    648 499
     logDumpFile :: Logger -> PprStyle -> DumpFlag -> String -> DumpFormat -> SDoc -> IO ()
    
    ... ... @@ -654,7 +505,7 @@ logTraceMsg logger hdr doc a = putTraceMsg logger (logFlags logger) hdr doc a
    654 505
     
    
    655 506
     -- | Log a dump message (not a dump file)
    
    656 507
     logDumpMsg :: Logger -> String -> SDoc -> IO ()
    
    657
    -logDumpMsg logger hdr doc = logMsg logger MCDump noSrcSpan
    
    508
    +logDumpMsg logger hdr doc = logMsg logger $ MCDump
    
    658 509
       (withPprStyle defaultDumpStyle
    
    659 510
       (mkDumpDoc hdr doc))
    
    660 511
     
    

  • docs/users_guide/debugging.rst
    ... ... @@ -55,13 +55,6 @@ Dumping out compiler intermediate structures
    55 55
         ``Main.p.dump-simpl`` and ``Main.dump-simpl`` instead of overwriting the
    
    56 56
         output of one way with the output of another.
    
    57 57
     
    
    58
    -.. ghc-flag:: -ddump-json
    
    59
    -    :shortdesc: *(deprecated)* Use :ghc-flag:`-fdiagnostics-as-json` instead
    
    60
    -    :type: dynamic
    
    61
    -
    
    62
    -    This flag was previously used to generated JSON formatted GHC diagnostics,
    
    63
    -    but has been deprecated. Instead, use :ghc-flag:`-fdiagnostics-as-json`.
    
    64
    -
    
    65 58
     .. ghc-flag:: -dshow-passes
    
    66 59
         :shortdesc: Print out each pass name as it happens
    
    67 60
         :type: dynamic
    

  • ghc/GHCi/UI.hs
    ... ... @@ -498,8 +498,6 @@ interactiveUI config srcs maybe_exprs = do
    498 498
     
    
    499 499
        installInteractiveHomeUnits
    
    500 500
     
    
    501
    -   -- Update the LogAction. Ensure we don't override the user's log action lest
    
    502
    -   -- we break -ddump-json (#14078)
    
    503 501
        lastErrLocationsRef <- liftIO $ newIORef []
    
    504 502
        pushLogHookM (ghciLogAction lastErrLocationsRef)
    
    505 503
     
    
    ... ... @@ -835,10 +833,10 @@ resetLastErrorLocations = do
    835 833
     
    
    836 834
     ghciLogAction :: IORef [(FastString, Int)] -> LogAction -> LogAction
    
    837 835
     ghciLogAction lastErrLocations old_log_action
    
    838
    -              dflags msg_class srcSpan msg = do
    
    839
    -    old_log_action dflags msg_class srcSpan msg
    
    840
    -    case msg_class of
    
    841
    -        MCDiagnostic SevError _reason _code -> case srcSpan of
    
    836
    +              dflags msg = do
    
    837
    +    old_log_action dflags msg
    
    838
    +    case msg of
    
    839
    +        MCDiagnostic srcSpan SevError _reason _code -> case srcSpan of
    
    842 840
                 RealSrcSpan rsp _ -> modifyIORef lastErrLocations
    
    843 841
                     (++ [(srcLocFile (realSrcSpanStart rsp), srcLocLine (realSrcSpanStart rsp))])
    
    844 842
                 _ -> return ()
    

  • testsuite/tests/driver/T16167.stderr
    1
    +{"version":"1.2","ghcVersion":"ghc-9.15.20250819","span":{"file":"T16167.hs","start":{"line":1,"column":8},"end":{"line":1,"column":9}},"severity":"Error","code":58481,"rendered":"T16167.hs:1:8: error: [GHC-58481] parse error on input \u2018f\u2019\n","message":["parse error on input \u2018f\u2019"],"hints":[]}
    
    1 2
     *** Exception: ExitFailure 1

  • testsuite/tests/driver/T16167.stdout deleted
    1
    -{"span":null,"doc":"-ddump-json is deprecated: Use `-fdiagnostics-as-json` instead","messageClass":"MCDiagnostic SevWarning WarningWithFlags Opt_WarnDeprecatedFlags :| [] Just GHC-53692"}
    
    2
    -{"span":{"file":"T16167.hs","startLine":1,"startCol":8,"endLine":1,"endCol":9},"doc":"parse error on input \u2018f\u2019","messageClass":"MCDiagnostic SevError ErrorWithoutFlag Just GHC-58481"}

  • testsuite/tests/driver/all.T
    ... ... @@ -274,12 +274,11 @@ test('T12752pass', normal, compile, ['-DSHOULD_PASS=1 -Wcpp-undef'])
    274 274
     test('T12955', normal, makefile_test, [])
    
    275 275
     
    
    276 276
     test('T12971', [when(opsys('mingw32'), fragile(17945)), ignore_stdout], makefile_test, [])
    
    277
    -test('json_dump', normal, compile_fail, ['-ddump-json'])
    
    278 277
     test('json', normalise_version('ghc'), compile_fail, ['-fdiagnostics-as-json'])
    
    279 278
     test('json_warn', normalise_version('ghc'), compile, ['-fdiagnostics-as-json -Wunused-matches -Wx-partial'])
    
    280
    -test('json2', normalise_version('ghc-internal', 'base','ghc-prim'), compile, ['-ddump-types -ddump-json -Wno-unsupported-llvm-version'])
    
    279
    +test('json2', normalise_version('ghc-internal', 'base','ghc-prim'), compile, ['-ddump-types -fdiagnostics-as-json -Wno-unsupported-llvm-version'])
    
    281 280
     test('T16167', [normalise_version('ghc'),req_interp,exit_code(1)], run_command,
    
    282
    -     ['{compiler} -x hs -e ":set prog T16167.hs" -ddump-json T16167.hs'])
    
    281
    +     ['{compiler} -x hs -e ":set prog T16167.hs" -fdiagnostics-as-json T16167.hs'])
    
    283 282
     test('T13604', [], makefile_test, [])
    
    284 283
     test('T13604a',
    
    285 284
       [ js_broken(22261) # require HPC support
    

  • testsuite/tests/driver/json2.stderr
    1
    -{"span":null,"doc":"-ddump-json is deprecated: Use `-fdiagnostics-as-json` instead","messageClass":"MCDiagnostic SevWarning WarningWithFlags Opt_WarnDeprecatedFlags :| [] Just GHC-53692"}
    
    2
    -{"span":null,"doc":"TYPE SIGNATURES\n  foo :: forall a. a -> a\nDependent modules: []\nDependent packages: [(normal, base-4.21.0.0)]","messageClass":"MCOutput"}
    1
    +TYPE SIGNATURES
    
    2
    +  foo :: forall a. a -> a
    
    3
    +Dependent modules: []
    
    4
    +Dependent packages: [(normal, base-4.21.0.0)]

  • testsuite/tests/driver/json_dump.hs deleted
    1
    -module Foo where
    
    2
    -
    
    3
    -import Data.List
    
    4
    -
    
    5
    -id1 :: a -> a
    
    6
    -id1 = 5

  • testsuite/tests/driver/json_dump.stderr deleted
    1
    -{"span":null,"doc":"-ddump-json is deprecated: Use `-fdiagnostics-as-json` instead","messageClass":"MCDiagnostic SevWarning WarningWithFlags Opt_WarnDeprecatedFlags :| [] Just GHC-53692"}
    
    2
    -{"span":{"file":"json_dump.hs","startLine":6,"startCol":7,"endLine":6,"endCol":8},"doc":"\u2022 No instance for \u2018Num (a -> a)\u2019 arising from the literal \u20185\u2019\n    (maybe you haven't applied a function to enough arguments?)\n\u2022 In the expression: 5\n  In an equation for \u2018id1\u2019: id1 = 5","messageClass":"MCDiagnostic SevError ErrorWithoutFlag Just GHC-39999"}

  • testsuite/tests/ghc-api/T7478/T7478.hs
    ... ... @@ -24,11 +24,11 @@ compileInGhc targets handlerOutput = do
    24 24
         flags0 <- getSessionDynFlags
    
    25 25
         let flags = flags0 {verbosity = 1 }
    
    26 26
         setSessionDynFlags flags
    
    27
    -    let collectSrcError handlerOutput _flags MCOutput _srcspan msg
    
    27
    +    let collectSrcError _flags (MCOutput msg)
    
    28 28
               = handlerOutput $ GHC.showSDocForUser flags emptyUnitState alwaysQualify msg
    
    29
    -        collectSrcError _ _ _ _ _
    
    29
    +        collectSrcError _ _
    
    30 30
               = return ()
    
    31
    -    pushLogHookM (const (collectSrcError handlerOutput))
    
    31
    +    pushLogHookM (const collectSrcError)
    
    32 32
         -- Set up targets.
    
    33 33
         oldTargets <- getTargets
    
    34 34
         let oldFiles = map fileFromTarget oldTargets
    

  • testsuite/tests/plugins/hooks-plugin/Hooks/LogPlugin.hs
    ... ... @@ -19,6 +19,6 @@ hooksP opts hsc_env = do
    19 19
       return hsc_env'
    
    20 20
     
    
    21 21
     logHook :: LogAction -> LogAction
    
    22
    -logHook action logFlags messageClass srcSpan msgDoc = do
    
    22
    +logHook action logFlags message = do
    
    23 23
       putStrLn "Log hook called"
    
    24
    -  action logFlags messageClass srcSpan msgDoc
    24
    +  action logFlags message