Simon Hengel pushed to branch wip/sol/remove-ddump-json at Glasgow Haskell Compiler / GHC
Commits:
-
2ae6c686
by Simon Hengel at 2025-08-22T22:54:49+07:00
-
71d60bcd
by Simon Hengel at 2025-08-22T22:57:14+07:00
12 changed files:
- compiler/GHC/Core/Opt/Monad.hs
- compiler/GHC/Driver/Errors.hs
- compiler/GHC/Driver/Main.hs
- compiler/GHC/Driver/Make.hs
- compiler/GHC/Driver/Monad.hs
- compiler/GHC/Iface/Load.hs
- compiler/GHC/Linker/Loader.hs
- compiler/GHC/Types/Error.hs
- compiler/GHC/Utils/Error.hs
- compiler/GHC/Utils/Logger.hs
- ghc/GHCi/UI.hs
- testsuite/tests/ghc-api/T7478/T7478.hs
Changes:
| ... | ... | @@ -362,18 +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 | 368 | name_ppr_ctx <- getNamePprCtx
|
| 369 | - let sty = case msg_class of
|
|
| 370 | - MCDiagnostic _ _ _ _ -> err_sty
|
|
| 371 | - MCDump -> dump_sty
|
|
| 372 | - _ -> user_sty
|
|
| 373 | - err_sty = mkErrStyle name_ppr_ctx
|
|
| 374 | - user_sty = mkUserStyle name_ppr_ctx AllTheWay
|
|
| 375 | - dump_sty = mkDumpStyle name_ppr_ctx
|
|
| 376 | - liftIO $ logMsg logger (Message msg_class (withPprStyle sty doc))
|
|
| 369 | + let m = case msg of
|
|
| 370 | + UnsafeMCDiagnostic span severity reason code doc json -> UnsafeMCDiagnostic span severity reason code (err_sty doc) json
|
|
| 371 | + MCDump doc -> MCDump (dump_sty doc)
|
|
| 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
|
|
| 377 | 381 | |
| 378 | 382 | -- | Output a String message to the screen
|
| 379 | 383 | putMsgS :: String -> CoreM ()
|
| ... | ... | @@ -381,7 +385,7 @@ putMsgS = putMsg . text |
| 381 | 385 | |
| 382 | 386 | -- | Output a message to the screen
|
| 383 | 387 | putMsg :: SDoc -> CoreM ()
|
| 384 | -putMsg = msg MCInfo
|
|
| 388 | +putMsg = msg . MCInfo
|
|
| 385 | 389 | |
| 386 | 390 | diagnostic :: DiagnosticReason -> SDoc -> CoreM ()
|
| 387 | 391 | diagnostic reason doc = do
|
| ... | ... | @@ -406,7 +410,7 @@ fatalErrorMsgS = fatalErrorMsg . text |
| 406 | 410 | |
| 407 | 411 | -- | Output a fatal error to the screen. Does not cause the compiler to die.
|
| 408 | 412 | fatalErrorMsg :: SDoc -> CoreM ()
|
| 409 | -fatalErrorMsg = msg MCFatal
|
|
| 413 | +fatalErrorMsg = msg . MCFatal
|
|
| 410 | 414 | |
| 411 | 415 | -- | Output a string debugging message at verbosity level of @-v@ or higher
|
| 412 | 416 | debugTraceMsgS :: String -> CoreM ()
|
| ... | ... | @@ -414,4 +418,4 @@ debugTraceMsgS = debugTraceMsg . text |
| 414 | 418 | |
| 415 | 419 | -- | Outputs a debugging message at verbosity level of @-v@ or higher
|
| 416 | 420 | debugTraceMsg :: SDoc -> CoreM ()
|
| 417 | -debugTraceMsg = msg MCDump |
|
| 421 | +debugTraceMsg = msg . MCDump |
| ... | ... | @@ -47,18 +47,15 @@ printMessages logger msg_opts opts = mapM_ (printMessage logger msg_opts opts) . |
| 47 | 47 | |
| 48 | 48 | printMessage :: forall a. (Diagnostic a) => Logger -> DiagnosticOpts a -> DiagOpts -> MsgEnvelope a -> IO ()
|
| 49 | 49 | printMessage logger msg_opts opts message = do
|
| 50 | - decorated <- decorateDiagnostic logflags messageClass location doc
|
|
| 51 | - if log_diags_as_json then do
|
|
| 52 | - let
|
|
| 53 | - rendered :: String
|
|
| 54 | - rendered = renderWithContext (log_default_user_context logflags) decorated
|
|
| 55 | - |
|
| 56 | - jsonMessage :: JsonDoc
|
|
| 57 | - jsonMessage = jsonDiagnostic rendered message
|
|
| 58 | - |
|
| 59 | - logJsonMsg logger messageClass jsonMessage
|
|
| 60 | - else do
|
|
| 61 | - logMsg logger (Message messageClass decorated)
|
|
| 50 | + decorated <- decorateDiagnostic logflags location severity reason code doc
|
|
| 51 | + let
|
|
| 52 | + rendered :: String
|
|
| 53 | + rendered = renderWithContext (log_default_user_context logflags) decorated
|
|
| 54 | + |
|
| 55 | + jsonMessage :: JsonDoc
|
|
| 56 | + jsonMessage = jsonDiagnostic rendered message
|
|
| 57 | + |
|
| 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 = do |
| 66 | 63 | doc :: SDoc
|
| 67 | 64 | doc = updSDocContext (\_ -> ctx) (messageWithHints diagnostic)
|
| 68 | 65 | |
| 69 | - messageClass :: MessageClass
|
|
| 70 | - messageClass = UnsafeMCDiagnostic location 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 = do |
| 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,21 +93,18 @@ printMessage logger msg_opts opts message = do |
| 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)
|
|
| 98 | - |
|
| 99 | -decorateDiagnostic :: LogFlags -> MessageClass -> SrcSpan -> SDoc -> IO SDoc
|
|
| 100 | -decorateDiagnostic logflags msg_class srcSpan msg = addCaret
|
|
| 96 | +decorateDiagnostic :: LogFlags -> SrcSpan -> Severity -> ResolvedDiagnosticReason -> Maybe DiagnosticCode -> SDoc -> IO SDoc
|
|
| 97 | +decorateDiagnostic logflags span severity reason code doc = addCaret
|
|
| 101 | 98 | where
|
| 102 | 99 | -- Pretty print the warning flag, if any (#10752)
|
| 103 | 100 | message :: SDoc
|
| 104 | - message = mkLocMessageWarningGroups (log_show_warn_groups logflags) msg_class srcSpan msg
|
|
| 101 | + message = formatDiagnostic (log_show_warn_groups logflags) span severity reason code doc
|
|
| 105 | 102 | |
| 106 | 103 | addCaret :: IO SDoc
|
| 107 | 104 | addCaret = do
|
| 108 | 105 | caretDiagnostic <-
|
| 109 | 106 | if log_show_caret logflags
|
| 110 | - then getCaretDiagnostic msg_class srcSpan
|
|
| 107 | + then getCaretDiagnostic severity span
|
|
| 111 | 108 | else pure empty
|
| 112 | 109 | return $ getPprStyle $ \style ->
|
| 113 | 110 | withPprStyle (setStyleColoured True style)
|
| ... | ... | @@ -1846,7 +1846,8 @@ markUnsafeInfer tcg_env whyUnsafe = do |
| 1846 | 1846 | badInst ins | checkOverlap (overlapMode (is_flag ins))
|
| 1847 | 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
|
| ... | ... | @@ -1447,11 +1447,11 @@ withDeferredDiagnostics f = do |
| 1447 | 1447 | let deferDiagnostics _dflags !msg = do
|
| 1448 | 1448 | let action = logMsg logger msg
|
| 1449 | 1449 | case msg of
|
| 1450 | - Message (MCDiagnostic _ SevWarning _reason _code) _
|
|
| 1450 | + MCDiagnostic _ SevWarning _reason _code
|
|
| 1451 | 1451 | -> atomicModifyIORef' warnings $ \(!i) -> (action: i, ())
|
| 1452 | - Message (MCDiagnostic _ SevError _reason _code) _
|
|
| 1452 | + MCDiagnostic _ SevError _reason _code
|
|
| 1453 | 1453 | -> atomicModifyIORef' errors $ \(!i) -> (action: i, ())
|
| 1454 | - Message MCFatal _
|
|
| 1454 | + MCFatal _
|
|
| 1455 | 1455 | -> atomicModifyIORef' fatals $ \(!i) -> (action: i, ())
|
| 1456 | 1456 | _ -> action
|
| 1457 | 1457 |
| ... | ... | @@ -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.Error ( Message )
|
|
| 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
|
| ... | ... | @@ -96,7 +96,6 @@ import GHC.Types.TypeEnv |
| 96 | 96 | import GHC.Types.Unique.DSet
|
| 97 | 97 | import GHC.Types.TyThing
|
| 98 | 98 | import GHC.Types.PkgQual
|
| 99 | -import GHC.Types.Error (Message(..))
|
|
| 100 | 99 | |
| 101 | 100 | import GHC.Unit.External
|
| 102 | 101 | import GHC.Unit.Module
|
| ... | ... | @@ -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 $ Message MCDump
|
|
| 1121 | + logMsg logger $ MCDump
|
|
| 1123 | 1122 | $ withPprStyle (mkDumpStyle name_ppr_ctx)
|
| 1124 | 1123 | $ pprModIface unit_state iface
|
| 1125 | 1124 |
| ... | ... | @@ -72,7 +72,6 @@ import GHC.Types.Name.Env |
| 72 | 72 | import GHC.Types.SrcLoc
|
| 73 | 73 | import GHC.Types.Unique.DSet
|
| 74 | 74 | import GHC.Types.Unique.DFM
|
| 75 | -import GHC.Types.Error (Message(..))
|
|
| 76 | 75 | |
| 77 | 76 | import GHC.Utils.Outputable
|
| 78 | 77 | import GHC.Utils.Panic
|
| ... | ... | @@ -1639,7 +1638,7 @@ addEnvPaths name list |
| 1639 | 1638 | maybePutSDoc :: Logger -> SDoc -> IO ()
|
| 1640 | 1639 | maybePutSDoc logger s
|
| 1641 | 1640 | = when (logVerbAtLeast logger 2) $
|
| 1642 | - logMsg logger $ Message
|
|
| 1641 | + logMsg logger $
|
|
| 1643 | 1642 | MCInteractive
|
| 1644 | 1643 | $ withPprStyle defaultUserStyle s
|
| 1645 | 1644 |
| ... | ... | @@ -26,8 +26,7 @@ module GHC.Types.Error |
| 26 | 26 | |
| 27 | 27 | -- * Classifying Messages
|
| 28 | 28 | |
| 29 | - , Message (..)
|
|
| 30 | - , MessageClass (MCDiagnostic, ..)
|
|
| 29 | + , Message (MCDiagnostic, ..)
|
|
| 31 | 30 | , Severity (..)
|
| 32 | 31 | , Diagnostic (..)
|
| 33 | 32 | , UnknownDiagnostic (..)
|
| ... | ... | @@ -71,7 +70,6 @@ module GHC.Types.Error |
| 71 | 70 | , mapDecoratedSDoc
|
| 72 | 71 | |
| 73 | 72 | , pprMessageBag
|
| 74 | - , mkLocMessageWarningGroups
|
|
| 75 | 73 | , formatLocMessage
|
| 76 | 74 | , formatFatalLocMessage
|
| 77 | 75 | , formatDiagnostic
|
| ... | ... | @@ -478,27 +476,25 @@ data MsgEnvelope e = MsgEnvelope |
| 478 | 476 | -- See Note [Warnings controlled by multiple flags]
|
| 479 | 477 | } deriving (Functor, Foldable, Traversable)
|
| 480 | 478 | |
| 481 | -data Message = Message MessageClass SDoc
|
|
| 482 | - |
|
| 483 | 479 | -- | The class for a diagnostic message. The main purpose is to classify a
|
| 484 | 480 | -- message within GHC, to distinguish it from a debug/dump message vs a proper
|
| 485 | 481 | -- diagnostic, for which we include a 'DiagnosticReason'.
|
| 486 | -data MessageClass
|
|
| 487 | - = MCOutput
|
|
| 488 | - | MCFatal
|
|
| 489 | - | MCInteractive
|
|
| 482 | +data Message
|
|
| 483 | + = MCOutput SDoc
|
|
| 484 | + | MCFatal SDoc
|
|
| 485 | + | MCInteractive SDoc
|
|
| 490 | 486 | |
| 491 | - | MCDump
|
|
| 487 | + | MCDump SDoc
|
|
| 492 | 488 | -- ^ Log message intended for compiler developers
|
| 493 | 489 | -- No file\/line\/column stuff
|
| 494 | 490 | |
| 495 | - | MCInfo
|
|
| 491 | + | MCInfo SDoc
|
|
| 496 | 492 | -- ^ Log messages intended for end users.
|
| 497 | 493 | -- No file\/line\/column stuff.
|
| 498 | 494 | |
| 499 | - | UnsafeMCDiagnostic SrcSpan Severity ResolvedDiagnosticReason (Maybe DiagnosticCode)
|
|
| 495 | + | UnsafeMCDiagnostic SrcSpan Severity ResolvedDiagnosticReason (Maybe DiagnosticCode) SDoc JsonDoc
|
|
| 500 | 496 | -- ^ Diagnostics from the compiler. This constructor is very powerful as
|
| 501 | - -- it allows the construction of a 'MessageClass' with a completely
|
|
| 497 | + -- it allows the construction of a 'Message' with a completely
|
|
| 502 | 498 | -- arbitrary permutation of 'Severity' and 'DiagnosticReason'. As such,
|
| 503 | 499 | -- users are encouraged to use higher level primitives
|
| 504 | 500 | -- instead. Use this constructor directly only if you need to construct
|
| ... | ... | @@ -512,8 +508,8 @@ data MessageClass |
| 512 | 508 | -- should always have a 'DiagnosticCode'. See Note [Diagnostic codes].
|
| 513 | 509 | |
| 514 | 510 | {-# COMPLETE MCOutput, MCFatal, MCInteractive, MCDump, MCInfo, MCDiagnostic #-}
|
| 515 | -pattern MCDiagnostic :: SrcSpan -> Severity -> ResolvedDiagnosticReason -> Maybe DiagnosticCode -> MessageClass
|
|
| 516 | -pattern MCDiagnostic span severity reason code <- UnsafeMCDiagnostic span 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
|
|
| 517 | 513 | |
| 518 | 514 | {-
|
| 519 | 515 | Note [Suppressing Messages]
|
| ... | ... | @@ -638,23 +634,9 @@ showMsgEnvelope err = |
| 638 | 634 | pprMessageBag :: Bag SDoc -> SDoc
|
| 639 | 635 | pprMessageBag msgs = vcat (punctuate blankLine (bagToList msgs))
|
| 640 | 636 | |
| 641 | --- | Make an error message with location info, specifying whether to show
|
|
| 642 | --- warning groups (if applicable).
|
|
| 643 | -mkLocMessageWarningGroups
|
|
| 644 | - :: Bool -- ^ Print warning groups (if applicable)?
|
|
| 645 | - -> MessageClass -- ^ What kind of message?
|
|
| 646 | - -> SrcSpan -- ^ location
|
|
| 647 | - -> SDoc -- ^ message
|
|
| 648 | - -> SDoc
|
|
| 649 | -mkLocMessageWarningGroups show_warn_groups msg_class locn msg
|
|
| 650 | - = case msg_class of
|
|
| 651 | - MCDiagnostic span severity reason code -> formatDiagnostic show_warn_groups span severity reason code msg
|
|
| 652 | - MCFatal -> formatFatalLocMessage locn msg
|
|
| 653 | - _ -> formatLocMessage locn msg
|
|
| 654 | - |
|
| 655 | 637 | formatFatalLocMessage :: SrcSpan -> SDoc -> SDoc
|
| 656 | 638 | formatFatalLocMessage locn msg = sdocOption sdocColScheme $ \col_scheme ->
|
| 657 | - let msg_title = coloured (fatalColour col_scheme) $ text "fatal"
|
|
| 639 | + let msg_title = coloured (Col.sFatal col_scheme) $ text "fatal"
|
|
| 658 | 640 | in formatLocMessageWarningGroups locn msg_title empty empty msg
|
| 659 | 641 | |
| 660 | 642 | formatLocMessage :: SrcSpan -> SDoc -> SDoc
|
| ... | ... | @@ -769,16 +751,7 @@ formatLocMessageWarningGroups locn msg_title code_doc warning_flag_doc msg |
| 769 | 751 | code_doc <+> warning_flag_doc
|
| 770 | 752 | |
| 771 | 753 | in coloured (Col.sMessage col_scheme)
|
| 772 | - (hang (coloured (Col.sHeader col_scheme) header) 4
|
|
| 773 | - msg)
|
|
| 774 | - |
|
| 775 | -getMessageClassColour :: MessageClass -> Col.Scheme -> Col.PprColour
|
|
| 776 | -getMessageClassColour (MCDiagnostic _span severity _reason _code) = getSeverityColour severity
|
|
| 777 | -getMessageClassColour MCFatal = fatalColour
|
|
| 778 | -getMessageClassColour _ = const mempty
|
|
| 779 | - |
|
| 780 | -fatalColour :: Col.Scheme -> Col.PprColour
|
|
| 781 | -fatalColour = Col.sFatal
|
|
| 754 | + $ hang (coloured (Col.sHeader col_scheme) header) 4 msg
|
|
| 782 | 755 | |
| 783 | 756 | getSeverityColour :: Severity -> Col.Scheme -> Col.PprColour
|
| 784 | 757 | getSeverityColour severity = case severity of
|
| ... | ... | @@ -786,9 +759,9 @@ getSeverityColour severity = case severity of |
| 786 | 759 | SevWarning -> Col.sWarning
|
| 787 | 760 | SevIgnore -> const mempty
|
| 788 | 761 | |
| 789 | -getCaretDiagnostic :: MessageClass -> SrcSpan -> IO SDoc
|
|
| 762 | +getCaretDiagnostic :: Severity -> SrcSpan -> IO SDoc
|
|
| 790 | 763 | getCaretDiagnostic _ (UnhelpfulSpan _) = pure empty
|
| 791 | -getCaretDiagnostic msg_class (RealSrcSpan span _) =
|
|
| 764 | +getCaretDiagnostic severity (RealSrcSpan span _) =
|
|
| 792 | 765 | caretDiagnostic <$> getSrcLine (srcSpanFile span) row
|
| 793 | 766 | where
|
| 794 | 767 | getSrcLine fn i =
|
| ... | ... | @@ -821,7 +794,7 @@ getCaretDiagnostic msg_class (RealSrcSpan span _) = |
| 821 | 794 | caretDiagnostic Nothing = empty
|
| 822 | 795 | caretDiagnostic (Just srcLineWithNewline) =
|
| 823 | 796 | sdocOption sdocColScheme$ \col_scheme ->
|
| 824 | - let sevColour = getMessageClassColour msg_class col_scheme
|
|
| 797 | + let sevColour = getSeverityColour severity col_scheme
|
|
| 825 | 798 | marginColour = Col.sMargin col_scheme
|
| 826 | 799 | in
|
| 827 | 800 | coloured marginColour (text marginSpace) <>
|
| ... | ... | @@ -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,
|
| ... | ... | @@ -313,7 +313,7 @@ ghcExit logger val |
| 313 | 313 | |
| 314 | 314 | fatalErrorMsg :: Logger -> SDoc -> IO ()
|
| 315 | 315 | fatalErrorMsg logger msg =
|
| 316 | - logMsg logger $ Message MCFatal (withPprStyle defaultErrStyle msg)
|
|
| 316 | + logMsg logger $ MCFatal (withPprStyle defaultErrStyle msg)
|
|
| 317 | 317 | |
| 318 | 318 | compilationProgressMsg :: Logger -> SDoc -> IO ()
|
| 319 | 319 | compilationProgressMsg logger msg = do
|
| ... | ... | @@ -474,11 +474,11 @@ printOutputForUser logger name_ppr_ctx msg |
| 474 | 474 | = logOutput logger (withUserStyle name_ppr_ctx AllTheWay msg)
|
| 475 | 475 | |
| 476 | 476 | logInfo :: Logger -> SDoc -> IO ()
|
| 477 | -logInfo logger = logMsg logger . Message MCInfo
|
|
| 477 | +logInfo logger = logMsg logger . MCInfo
|
|
| 478 | 478 | |
| 479 | 479 | -- | Like 'logInfo' but with 'SevOutput' rather then 'SevInfo'
|
| 480 | 480 | logOutput :: Logger -> SDoc -> IO ()
|
| 481 | -logOutput logger = logMsg logger . Message MCOutput
|
|
| 481 | +logOutput logger = logMsg logger . MCOutput
|
|
| 482 | 482 | |
| 483 | 483 | |
| 484 | 484 | prettyPrintGhcErrors :: ExceptionMonad m => Logger -> m a -> m a
|
| ... | ... | @@ -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,11 +52,9 @@ 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 | 60 | -- * Dumping
|
| ... | ... | @@ -86,8 +81,8 @@ import GHC.Types.Error |
| 86 | 81 | |
| 87 | 82 | import qualified GHC.Utils.Ppr as Pretty
|
| 88 | 83 | import GHC.Utils.Outputable
|
| 89 | -import GHC.Utils.Json
|
|
| 90 | 84 | import GHC.Utils.Panic
|
| 85 | +import GHC.Utils.Json (renderJSON)
|
|
| 91 | 86 | |
| 92 | 87 | import GHC.Data.EnumSet (EnumSet)
|
| 93 | 88 | import qualified GHC.Data.EnumSet as EnumSet
|
| ... | ... | @@ -181,11 +176,6 @@ type LogAction = LogFlags |
| 181 | 176 | -> Message
|
| 182 | 177 | -> IO ()
|
| 183 | 178 | |
| 184 | -type LogJsonAction = LogFlags
|
|
| 185 | - -> MessageClass
|
|
| 186 | - -> JsonDoc
|
|
| 187 | - -> IO ()
|
|
| 188 | - |
|
| 189 | 179 | type DumpAction = LogFlags
|
| 190 | 180 | -> PprStyle
|
| 191 | 181 | -> DumpFlag
|
| ... | ... | @@ -223,9 +213,6 @@ data Logger = Logger |
| 223 | 213 | { log_hook :: [LogAction -> LogAction]
|
| 224 | 214 | -- ^ Log hooks stack
|
| 225 | 215 | |
| 226 | - , json_log_hook :: [LogJsonAction -> LogJsonAction]
|
|
| 227 | - -- ^ Json log hooks stack
|
|
| 228 | - |
|
| 229 | 216 | , dump_hook :: [DumpAction -> DumpAction]
|
| 230 | 217 | -- ^ Dump hooks stack
|
| 231 | 218 | |
| ... | ... | @@ -261,7 +248,6 @@ initLogger = do |
| 261 | 248 | dumps <- newMVar Map.empty
|
| 262 | 249 | return $ Logger
|
| 263 | 250 | { log_hook = []
|
| 264 | - , json_log_hook = []
|
|
| 265 | 251 | , dump_hook = []
|
| 266 | 252 | , trace_hook = []
|
| 267 | 253 | , generated_dumps = dumps
|
| ... | ... | @@ -273,10 +259,6 @@ initLogger = do |
| 273 | 259 | putLogMsg :: Logger -> LogAction
|
| 274 | 260 | putLogMsg logger = foldr ($) defaultLogAction (log_hook logger)
|
| 275 | 261 | |
| 276 | --- | Log a JsonDoc
|
|
| 277 | -putJsonLogMsg :: Logger -> LogJsonAction
|
|
| 278 | -putJsonLogMsg logger = foldr ($) defaultLogJsonAction (json_log_hook logger)
|
|
| 279 | - |
|
| 280 | 262 | -- | Dump something
|
| 281 | 263 | putDumpFile :: Logger -> DumpAction
|
| 282 | 264 | putDumpFile logger =
|
| ... | ... | @@ -301,15 +283,6 @@ popLogHook logger = case log_hook logger of |
| 301 | 283 | [] -> panic "popLogHook: empty hook stack"
|
| 302 | 284 | _:hs -> logger { log_hook = hs }
|
| 303 | 285 | |
| 304 | --- | Push a json log hook
|
|
| 305 | -pushJsonLogHook :: (LogJsonAction -> LogJsonAction) -> Logger -> Logger
|
|
| 306 | -pushJsonLogHook h logger = logger { json_log_hook = h:json_log_hook logger }
|
|
| 307 | - |
|
| 308 | -popJsonLogHook :: Logger -> Logger
|
|
| 309 | -popJsonLogHook logger = case json_log_hook logger of
|
|
| 310 | - [] -> panic "popJsonLogHook: empty hook stack"
|
|
| 311 | - _:hs -> logger { json_log_hook = hs}
|
|
| 312 | - |
|
| 313 | 286 | -- | Push a dump hook
|
| 314 | 287 | pushDumpHook :: (DumpAction -> DumpAction) -> Logger -> Logger
|
| 315 | 288 | pushDumpHook h logger = logger { dump_hook = h:dump_hook logger }
|
| ... | ... | @@ -353,22 +326,6 @@ makeThreadSafe logger = do |
| 353 | 326 | $ pushTraceHook trc
|
| 354 | 327 | $ logger
|
| 355 | 328 | |
| 356 | -defaultLogJsonAction :: LogJsonAction
|
|
| 357 | -defaultLogJsonAction logflags msg_class jsdoc =
|
|
| 358 | - case msg_class of
|
|
| 359 | - MCOutput -> printOut msg
|
|
| 360 | - MCDump -> printOut (msg $$ blankLine)
|
|
| 361 | - MCInteractive -> putStrSDoc msg
|
|
| 362 | - MCInfo -> printErrs msg
|
|
| 363 | - MCFatal -> printErrs msg
|
|
| 364 | - MCDiagnostic _ SevIgnore _ _ -> pure () -- suppress the message
|
|
| 365 | - MCDiagnostic _span _sev _rea _code -> printErrs msg
|
|
| 366 | - where
|
|
| 367 | - printOut = defaultLogActionHPrintDoc logflags False stdout
|
|
| 368 | - printErrs = defaultLogActionHPrintDoc logflags False stderr
|
|
| 369 | - putStrSDoc = defaultLogActionHPutStrDoc logflags False stdout
|
|
| 370 | - msg = renderJSON jsdoc
|
|
| 371 | - |
|
| 372 | 329 | -- | The default 'LogAction' prints to 'stdout' and 'stderr'.
|
| 373 | 330 | --
|
| 374 | 331 | -- To replicate the default log action behaviour with different @out@ and @err@
|
| ... | ... | @@ -381,13 +338,17 @@ defaultLogAction = defaultLogActionWithHandles stdout stderr |
| 381 | 338 | defaultLogActionWithHandles :: Handle {-^ Handle for standard output -} -> Handle {-^ Handle for standard errors -} -> LogAction
|
| 382 | 339 | defaultLogActionWithHandles out err logflags message
|
| 383 | 340 | = case message of
|
| 384 | - Message MCOutput msg -> printOut msg
|
|
| 385 | - Message MCDump msg -> printOut (msg $$ blankLine)
|
|
| 386 | - Message MCInteractive msg -> putStrSDoc msg
|
|
| 387 | - Message MCInfo msg -> printErrs msg
|
|
| 388 | - Message MCFatal msg -> printErrs msg
|
|
| 389 | - Message (MCDiagnostic _ SevIgnore _ _) _ -> pure () -- suppress the message
|
|
| 390 | - Message (MCDiagnostic _span _sev _rea _code) msg -> printErrs msg
|
|
| 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
|
|
| 391 | 352 | where
|
| 392 | 353 | printOut = defaultLogActionHPrintDoc logflags False out
|
| 393 | 354 | printErrs = defaultLogActionHPrintDoc logflags False err
|
| ... | ... | @@ -438,10 +399,10 @@ dumpSDocWithStyle dumps log_action sty logflags flag hdr doc = |
| 438 | 399 | |
| 439 | 400 | -- write the dump to stdout
|
| 440 | 401 | writeDump Nothing = do
|
| 441 | - let (doc', msg_class)
|
|
| 442 | - | null hdr = (doc, MCOutput)
|
|
| 443 | - | otherwise = (mkDumpDoc hdr doc, MCDump)
|
|
| 444 | - log_action logflags (Message msg_class (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
|
|
| 445 | 406 | |
| 446 | 407 | |
| 447 | 408 | -- | Run an action with the handle of a 'DumpFlag' if we are outputting to a
|
| ... | ... | @@ -534,9 +495,6 @@ defaultTraceAction logflags title doc x = |
| 534 | 495 | logMsg :: Logger -> Message -> IO ()
|
| 535 | 496 | logMsg logger = putLogMsg logger (logFlags logger)
|
| 536 | 497 | |
| 537 | -logJsonMsg :: Logger -> MessageClass -> JsonDoc -> IO ()
|
|
| 538 | -logJsonMsg logger mc = putJsonLogMsg logger (logFlags logger) mc
|
|
| 539 | - |
|
| 540 | 498 | -- | Dump something
|
| 541 | 499 | logDumpFile :: Logger -> PprStyle -> DumpFlag -> String -> DumpFormat -> SDoc -> IO ()
|
| 542 | 500 | logDumpFile logger = putDumpFile logger (logFlags logger)
|
| ... | ... | @@ -547,7 +505,7 @@ logTraceMsg logger hdr doc a = putTraceMsg logger (logFlags logger) hdr doc a |
| 547 | 505 | |
| 548 | 506 | -- | Log a dump message (not a dump file)
|
| 549 | 507 | logDumpMsg :: Logger -> String -> SDoc -> IO ()
|
| 550 | -logDumpMsg logger hdr doc = logMsg logger $ Message MCDump
|
|
| 508 | +logDumpMsg logger hdr doc = logMsg logger $ MCDump
|
|
| 551 | 509 | (withPprStyle defaultDumpStyle
|
| 552 | 510 | (mkDumpDoc hdr doc))
|
| 553 | 511 |
| ... | ... | @@ -836,7 +836,7 @@ ghciLogAction lastErrLocations old_log_action |
| 836 | 836 | dflags msg = do
|
| 837 | 837 | old_log_action dflags msg
|
| 838 | 838 | case msg of
|
| 839 | - Message (MCDiagnostic srcSpan SevError _reason _code) _ -> case srcSpan of
|
|
| 839 | + MCDiagnostic srcSpan SevError _reason _code -> case srcSpan of
|
|
| 840 | 840 | RealSrcSpan rsp _ -> modifyIORef lastErrLocations
|
| 841 | 841 | (++ [(srcLocFile (realSrcSpanStart rsp), srcLocLine (realSrcSpanStart rsp))])
|
| 842 | 842 | _ -> return ()
|
| ... | ... | @@ -24,7 +24,7 @@ compileInGhc targets handlerOutput = do |
| 24 | 24 | flags0 <- getSessionDynFlags
|
| 25 | 25 | let flags = flags0 {verbosity = 1 }
|
| 26 | 26 | setSessionDynFlags flags
|
| 27 | - let collectSrcError _flags (Message MCOutput msg)
|
|
| 27 | + let collectSrcError _flags (MCOutput msg)
|
|
| 28 | 28 | = handlerOutput $ GHC.showSDocForUser flags emptyUnitState alwaysQualify msg
|
| 29 | 29 | collectSrcError _ _
|
| 30 | 30 | = return ()
|