Simon Hengel pushed to branch wip/sol/remove-ddump-json at Glasgow Haskell Compiler / GHC
Commits:
-
08b2d89a
by Simon Hengel at 2025-07-28T14:58:41+07:00
-
acb24033
by Simon Hengel at 2025-07-28T14:59:11+07:00
22 changed files:
- compiler/GHC/Core/Lint.hs
- compiler/GHC/Driver/Errors.hs
- compiler/GHC/Driver/Flags.hs
- compiler/GHC/Driver/Main.hs
- compiler/GHC/Driver/Pipeline.hs
- compiler/GHC/Driver/Session.hs
- compiler/GHC/HsToCore/Monad.hs
- compiler/GHC/Stg/Lint.hs
- compiler/GHC/Tc/Errors.hs
- compiler/GHC/Tc/Utils/Monad.hs
- compiler/GHC/Types/Error.hs
- compiler/GHC/Types/SourceError.hs
- compiler/GHC/Utils/Error.hs
- compiler/GHC/Utils/Logger.hs
- docs/users_guide/debugging.rst
- ghc/GHCi/UI.hs
- testsuite/tests/driver/T16167.stderr
- − testsuite/tests/driver/T16167.stdout
- testsuite/tests/driver/all.T
- testsuite/tests/driver/json2.stderr
- − testsuite/tests/driver/json_dump.hs
- − testsuite/tests/driver/json_dump.stderr
Changes:
| ... | ... | @@ -3418,7 +3418,7 @@ addMsg show_context env msgs msg |
| 3418 | 3418 | [] -> noSrcSpan
|
| 3419 | 3419 | (s:_) -> s
|
| 3420 | 3420 | !diag_opts = le_diagOpts env
|
| 3421 | - mk_msg msg = mkLocMessage (mkMCDiagnostic diag_opts WarningWithoutFlag Nothing) msg_span
|
|
| 3421 | + mk_msg msg = mkLocMessage (unsafeMCDiagnostic diag_opts WarningWithoutFlag Nothing) msg_span
|
|
| 3422 | 3422 | (msg $$ context)
|
| 3423 | 3423 | |
| 3424 | 3424 | addLoc :: LintLocInfo -> LintM a -> LintM a
|
| ... | ... | @@ -67,7 +67,7 @@ printMessage logger msg_opts opts message |
| 67 | 67 | doc = updSDocContext (\_ -> ctx) (messageWithHints diagnostic)
|
| 68 | 68 | |
| 69 | 69 | messageClass :: MessageClass
|
| 70 | - messageClass = MCDiagnostic severity (errMsgReason message) (diagnosticCode diagnostic)
|
|
| 70 | + messageClass = UnsafeMCDiagnostic severity (errMsgReason message) (diagnosticCode diagnostic)
|
|
| 71 | 71 | |
| 72 | 72 | style :: PprStyle
|
| 73 | 73 | style = mkErrStyle (errMsgContext message)
|
| ... | ... | @@ -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
|
| ... | ... | @@ -1829,7 +1829,7 @@ markUnsafeInfer tcg_env whyUnsafe = do |
| 1829 | 1829 | , nest 4 $ (vcat $ badFlags df) $+$
|
| 1830 | 1830 | -- MP: Using defaultDiagnosticOpts here is not right but it's also not right to handle these
|
| 1831 | 1831 | -- unsafety error messages in an unstructured manner.
|
| 1832 | - (vcat $ pprMsgEnvelopeBagWithLoc (defaultDiagnosticOpts @e) (getMessages whyUnsafe)) $+$
|
|
| 1832 | + (vcat $ unsafePprMsgEnvelopeBagWithLoc (defaultDiagnosticOpts @e) (getMessages whyUnsafe)) $+$
|
|
| 1833 | 1833 | (vcat $ badInsts $ tcg_insts tcg_env)
|
| 1834 | 1834 | ]
|
| 1835 | 1835 | badFlags df = concatMap (badFlag df) unsafeFlagsForInfer
|
| ... | ... | @@ -163,7 +163,7 @@ preprocess hsc_env input_fn mb_input_buf mb_phase = |
| 163 | 163 | to_driver_messages msgs = case traverse to_driver_message msgs of
|
| 164 | 164 | Nothing -> pprPanic "non-driver message in preprocess"
|
| 165 | 165 | -- MP: Default config is fine here as it's just in a panic.
|
| 166 | - (vcat $ pprMsgEnvelopeBagWithLoc (defaultDiagnosticOpts @GhcMessage) (getMessages msgs))
|
|
| 166 | + (vcat $ unsafePprMsgEnvelopeBagWithLoc (defaultDiagnosticOpts @GhcMessage) (getMessages msgs))
|
|
| 167 | 167 | Just msgs' -> msgs'
|
| 168 | 168 | |
| 169 | 169 | to_driver_message = \case
|
| ... | ... | @@ -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"
|
| ... | ... | @@ -376,7 +376,7 @@ initTcDsForSolver thing_inside |
| 376 | 376 | thing_inside
|
| 377 | 377 | ; case mb_ret of
|
| 378 | 378 | Just ret -> pure ret
|
| 379 | - Nothing -> pprPanic "initTcDsForSolver" (vcat $ pprMsgEnvelopeBagWithLocDefault (getErrorMessages msgs)) }
|
|
| 379 | + Nothing -> pprPanic "initTcDsForSolver" (vcat $ unsafePprMsgEnvelopeBagWithLocDefault (getErrorMessages msgs)) }
|
|
| 380 | 380 | |
| 381 | 381 | mkDsEnvs :: UnitEnv -> Module -> GlobalRdrEnv -> TypeEnv -> FamInstEnv
|
| 382 | 382 | -> PromotionTickContext
|
| ... | ... | @@ -540,7 +540,7 @@ addErr diag_opts errs_so_far msg locs |
| 540 | 540 | = errs_so_far `snocBag` mk_msg locs
|
| 541 | 541 | where
|
| 542 | 542 | mk_msg (loc:_) = let (l,hdr) = dumpLoc loc
|
| 543 | - in mkLocMessage (Err.mkMCDiagnostic diag_opts WarningWithoutFlag Nothing)
|
|
| 543 | + in mkLocMessage (Err.unsafeMCDiagnostic diag_opts WarningWithoutFlag Nothing)
|
|
| 544 | 544 | l (hdr $$ msg)
|
| 545 | 545 | mk_msg [] = msg
|
| 546 | 546 |
| ... | ... | @@ -65,7 +65,7 @@ import GHC.Core.InstEnv |
| 65 | 65 | import GHC.Core.TyCon
|
| 66 | 66 | import GHC.Core.DataCon
|
| 67 | 67 | |
| 68 | -import GHC.Utils.Error (diagReasonSeverity, pprLocMsgEnvelope )
|
|
| 68 | +import GHC.Utils.Error (diagReasonSeverity, unsafePprLocMsgEnvelope )
|
|
| 69 | 69 | import GHC.Utils.Misc
|
| 70 | 70 | import GHC.Utils.Outputable as O
|
| 71 | 71 | import GHC.Utils.Panic
|
| ... | ... | @@ -1294,7 +1294,7 @@ mkErrorTerm ct_loc ty ctxt msg supp hints |
| 1294 | 1294 | hints
|
| 1295 | 1295 | -- This will be reported at runtime, so we always want "error:" in the report, never "warning:"
|
| 1296 | 1296 | ; dflags <- getDynFlags
|
| 1297 | - ; let err_msg = pprLocMsgEnvelope (initTcMessageOpts dflags) msg
|
|
| 1297 | + ; let err_msg = unsafePprLocMsgEnvelope (initTcMessageOpts dflags) msg
|
|
| 1298 | 1298 | err_str = showSDoc dflags $
|
| 1299 | 1299 | err_msg $$ text "(deferred type error)"
|
| 1300 | 1300 |
| ... | ... | @@ -1146,7 +1146,7 @@ reportDiagnostics = mapM_ reportDiagnostic |
| 1146 | 1146 | |
| 1147 | 1147 | reportDiagnostic :: MsgEnvelope TcRnMessage -> TcRn ()
|
| 1148 | 1148 | reportDiagnostic msg
|
| 1149 | - = do { traceTc "Adding diagnostic:" (pprLocMsgEnvelopeDefault msg) ;
|
|
| 1149 | + = do { traceTc "Adding diagnostic:" (unsafePprLocMsgEnvelopeDefault msg) ;
|
|
| 1150 | 1150 | errs_var <- getErrsVar ;
|
| 1151 | 1151 | msgs <- readTcRef errs_var ;
|
| 1152 | 1152 | writeTcRef errs_var (msg `addMessage` msgs) }
|
| ... | ... | @@ -26,7 +26,7 @@ module GHC.Types.Error |
| 26 | 26 | |
| 27 | 27 | -- * Classifying Messages
|
| 28 | 28 | |
| 29 | - , MessageClass (..)
|
|
| 29 | + , MessageClass (MCDiagnostic, ..)
|
|
| 30 | 30 | , Severity (..)
|
| 31 | 31 | , Diagnostic (..)
|
| 32 | 32 | , UnknownDiagnostic (..)
|
| ... | ... | @@ -491,11 +491,11 @@ data MessageClass |
| 491 | 491 | -- ^ Log messages intended for end users.
|
| 492 | 492 | -- No file\/line\/column stuff.
|
| 493 | 493 | |
| 494 | - | MCDiagnostic Severity ResolvedDiagnosticReason (Maybe DiagnosticCode)
|
|
| 494 | + | UnsafeMCDiagnostic Severity ResolvedDiagnosticReason (Maybe DiagnosticCode)
|
|
| 495 | 495 | -- ^ Diagnostics from the compiler. This constructor is very powerful as
|
| 496 | 496 | -- it allows the construction of a 'MessageClass' with a completely
|
| 497 | 497 | -- arbitrary permutation of 'Severity' and 'DiagnosticReason'. As such,
|
| 498 | - -- users are encouraged to use the 'mkMCDiagnostic' smart constructor
|
|
| 498 | + -- users are encouraged to use the 'unsafeMCDiagnostic' smart constructor
|
|
| 499 | 499 | -- instead. Use this constructor directly only if you need to construct
|
| 500 | 500 | -- and manipulate diagnostic messages directly, for example inside
|
| 501 | 501 | -- 'GHC.Utils.Error'. In all the other circumstances, /especially/ when
|
| ... | ... | @@ -506,6 +506,10 @@ data MessageClass |
| 506 | 506 | -- error-message type, then use Nothing. In the long run, this really
|
| 507 | 507 | -- should always have a 'DiagnosticCode'. See Note [Diagnostic codes].
|
| 508 | 508 | |
| 509 | +{-# COMPLETE MCOutput, MCFatal, MCInteractive, MCDump, MCInfo, MCDiagnostic #-}
|
|
| 510 | +pattern MCDiagnostic :: Severity -> ResolvedDiagnosticReason -> Maybe DiagnosticCode -> MessageClass
|
|
| 511 | +pattern MCDiagnostic severity reason code <- UnsafeMCDiagnostic severity reason code
|
|
| 512 | + |
|
| 509 | 513 | {-
|
| 510 | 514 | Note [Suppressing Messages]
|
| 511 | 515 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| ... | ... | @@ -14,7 +14,7 @@ import GHC.Types.Error |
| 14 | 14 | import GHC.Utils.Monad
|
| 15 | 15 | import GHC.Utils.Panic
|
| 16 | 16 | import GHC.Utils.Exception
|
| 17 | -import GHC.Utils.Error (pprMsgEnvelopeBagWithLocDefault)
|
|
| 17 | +import GHC.Utils.Error (unsafePprMsgEnvelopeBagWithLocDefault)
|
|
| 18 | 18 | import GHC.Utils.Outputable
|
| 19 | 19 | |
| 20 | 20 | import GHC.Driver.Errors.Ppr () -- instance Diagnostic GhcMessage
|
| ... | ... | @@ -59,7 +59,7 @@ instance Show SourceError where |
| 59 | 59 | show (SourceError msgs) =
|
| 60 | 60 | renderWithContext defaultSDocContext
|
| 61 | 61 | . vcat
|
| 62 | - . pprMsgEnvelopeBagWithLocDefault
|
|
| 62 | + . unsafePprMsgEnvelopeBagWithLocDefault
|
|
| 63 | 63 | . getMessages
|
| 64 | 64 | $ msgs
|
| 65 | 65 |
| ... | ... | @@ -22,9 +22,8 @@ module GHC.Utils.Error ( |
| 22 | 22 | errorsFound, isEmptyMessages,
|
| 23 | 23 | |
| 24 | 24 | -- ** Formatting
|
| 25 | - pprMessageBag, pprMsgEnvelopeBagWithLoc, pprMsgEnvelopeBagWithLocDefault,
|
|
| 26 | - pprMessages,
|
|
| 27 | - pprLocMsgEnvelope, pprLocMsgEnvelopeDefault,
|
|
| 25 | + pprMessageBag, unsafePprMsgEnvelopeBagWithLoc, unsafePprMsgEnvelopeBagWithLocDefault,
|
|
| 26 | + unsafePprLocMsgEnvelope, unsafePprLocMsgEnvelopeDefault,
|
|
| 28 | 27 | formatBulleted,
|
| 29 | 28 | |
| 30 | 29 | -- ** Construction
|
| ... | ... | @@ -32,7 +31,7 @@ module GHC.Utils.Error ( |
| 32 | 31 | emptyMessages, mkDecorated, mkLocMessage,
|
| 33 | 32 | mkMsgEnvelope, mkPlainMsgEnvelope, mkPlainErrorMsgEnvelope,
|
| 34 | 33 | mkErrorMsgEnvelope,
|
| 35 | - mkMCDiagnostic, diagReasonSeverity,
|
|
| 34 | + unsafeMCDiagnostic, diagReasonSeverity,
|
|
| 36 | 35 | |
| 37 | 36 | mkPlainError,
|
| 38 | 37 | mkPlainDiagnostic,
|
| ... | ... | @@ -162,8 +161,8 @@ diag_reason_severity opts reason = fmap ResolvedDiagnosticReason $ case reason o |
| 162 | 161 | |
| 163 | 162 | -- | Make a 'MessageClass' for a given 'DiagnosticReason', consulting the
|
| 164 | 163 | -- 'DiagOpts'.
|
| 165 | -mkMCDiagnostic :: DiagOpts -> DiagnosticReason -> Maybe DiagnosticCode -> MessageClass
|
|
| 166 | -mkMCDiagnostic opts reason code = MCDiagnostic sev reason' code
|
|
| 164 | +unsafeMCDiagnostic :: DiagOpts -> DiagnosticReason -> Maybe DiagnosticCode -> MessageClass
|
|
| 165 | +unsafeMCDiagnostic opts reason code = UnsafeMCDiagnostic sev reason' code
|
|
| 167 | 166 | where
|
| 168 | 167 | (sev, reason') = diag_reason_severity opts reason
|
| 169 | 168 | |
| ... | ... | @@ -267,29 +266,26 @@ formatBulleted (unDecorated -> docs) |
| 267 | 266 | msgs ctx = filter (not . Outputable.isEmpty ctx) docs
|
| 268 | 267 | starred = (bullet<+>)
|
| 269 | 268 | |
| 270 | -pprMessages :: Diagnostic e => DiagnosticOpts e -> Messages e -> SDoc
|
|
| 271 | -pprMessages e = vcat . pprMsgEnvelopeBagWithLoc e . getMessages
|
|
| 272 | - |
|
| 273 | -pprMsgEnvelopeBagWithLoc :: Diagnostic e => DiagnosticOpts e -> Bag (MsgEnvelope e) -> [SDoc]
|
|
| 274 | -pprMsgEnvelopeBagWithLoc e bag = [ pprLocMsgEnvelope e item | item <- sortMsgBag Nothing bag ]
|
|
| 269 | +unsafePprMsgEnvelopeBagWithLoc :: Diagnostic e => DiagnosticOpts e -> Bag (MsgEnvelope e) -> [SDoc]
|
|
| 270 | +unsafePprMsgEnvelopeBagWithLoc e bag = [ unsafePprLocMsgEnvelope e item | item <- sortMsgBag Nothing bag ]
|
|
| 275 | 271 | |
| 276 | 272 | -- | Print the messages with the suitable default configuration, usually not what you want but sometimes you don't really
|
| 277 | 273 | -- care about what the configuration is (for example, if the message is in a panic).
|
| 278 | -pprMsgEnvelopeBagWithLocDefault :: forall e . Diagnostic e => Bag (MsgEnvelope e) -> [SDoc]
|
|
| 279 | -pprMsgEnvelopeBagWithLocDefault bag = [ pprLocMsgEnvelopeDefault item | item <- sortMsgBag Nothing bag ]
|
|
| 274 | +unsafePprMsgEnvelopeBagWithLocDefault :: forall e . Diagnostic e => Bag (MsgEnvelope e) -> [SDoc]
|
|
| 275 | +unsafePprMsgEnvelopeBagWithLocDefault bag = [ unsafePprLocMsgEnvelopeDefault item | item <- sortMsgBag Nothing bag ]
|
|
| 280 | 276 | |
| 281 | -pprLocMsgEnvelopeDefault :: forall e . Diagnostic e => MsgEnvelope e -> SDoc
|
|
| 282 | -pprLocMsgEnvelopeDefault = pprLocMsgEnvelope (defaultDiagnosticOpts @e)
|
|
| 277 | +unsafePprLocMsgEnvelopeDefault :: forall e . Diagnostic e => MsgEnvelope e -> SDoc
|
|
| 278 | +unsafePprLocMsgEnvelopeDefault = unsafePprLocMsgEnvelope (defaultDiagnosticOpts @e)
|
|
| 283 | 279 | |
| 284 | -pprLocMsgEnvelope :: Diagnostic e => DiagnosticOpts e -> MsgEnvelope e -> SDoc
|
|
| 285 | -pprLocMsgEnvelope opts (MsgEnvelope { errMsgSpan = s
|
|
| 280 | +unsafePprLocMsgEnvelope :: Diagnostic e => DiagnosticOpts e -> MsgEnvelope e -> SDoc
|
|
| 281 | +unsafePprLocMsgEnvelope opts (MsgEnvelope { errMsgSpan = s
|
|
| 286 | 282 | , errMsgDiagnostic = e
|
| 287 | 283 | , errMsgSeverity = sev
|
| 288 | 284 | , errMsgContext = name_ppr_ctx
|
| 289 | 285 | , errMsgReason = reason })
|
| 290 | 286 | = withErrStyle name_ppr_ctx $
|
| 291 | 287 | mkLocMessage
|
| 292 | - (MCDiagnostic sev reason (diagnosticCode e))
|
|
| 288 | + (UnsafeMCDiagnostic sev reason (diagnosticCode e))
|
|
| 293 | 289 | s
|
| 294 | 290 | (formatBulleted $ diagnosticMessage opts e)
|
| 295 | 291 |
| ... | ... | @@ -94,7 +94,6 @@ import GHC.Utils.Panic |
| 94 | 94 | |
| 95 | 95 | import GHC.Data.EnumSet (EnumSet)
|
| 96 | 96 | import qualified GHC.Data.EnumSet as EnumSet
|
| 97 | -import GHC.Data.FastString
|
|
| 98 | 97 | |
| 99 | 98 | import System.Directory
|
| 100 | 99 | import System.FilePath ( takeDirectory, (</>) )
|
| ... | ... | @@ -359,7 +358,6 @@ makeThreadSafe logger = do |
| 359 | 358 | $ pushTraceHook trc
|
| 360 | 359 | $ logger
|
| 361 | 360 | |
| 362 | --- See Note [JSON Error Messages]
|
|
| 363 | 361 | defaultLogJsonAction :: LogJsonAction
|
| 364 | 362 | defaultLogJsonAction logflags msg_class jsdoc =
|
| 365 | 363 | case msg_class of
|
| ... | ... | @@ -376,32 +374,6 @@ defaultLogJsonAction logflags msg_class jsdoc = |
| 376 | 374 | putStrSDoc = defaultLogActionHPutStrDoc logflags False stdout
|
| 377 | 375 | msg = renderJSON jsdoc
|
| 378 | 376 | |
| 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 | 377 | -- | The default 'LogAction' prints to 'stdout' and 'stderr'.
|
| 406 | 378 | --
|
| 407 | 379 | -- To replicate the default log action behaviour with different @out@ and @err@
|
| ... | ... | @@ -413,8 +385,7 @@ defaultLogAction = defaultLogActionWithHandles stdout stderr |
| 413 | 385 | -- Allows clients to replicate the log message formatting of GHC with custom handles.
|
| 414 | 386 | defaultLogActionWithHandles :: Handle {-^ Handle for standard output -} -> Handle {-^ Handle for standard errors -} -> LogAction
|
| 415 | 387 | 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
|
|
| 388 | + = case msg_class of
|
|
| 418 | 389 | MCOutput -> printOut msg
|
| 419 | 390 | MCDump -> printOut (msg $$ blankLine)
|
| 420 | 391 | MCInteractive -> putStrSDoc msg
|
| ... | ... | @@ -491,28 +462,6 @@ defaultLogActionHPutStrDoc logflags asciiSpace h d |
| 491 | 462 | -- calls to this log-action can output all on the same line
|
| 492 | 463 | = printSDoc (log_default_user_context logflags) (Pretty.PageMode asciiSpace) h d
|
| 493 | 464 | |
| 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 | 465 | -- | Default action for 'dumpAction' hook
|
| 517 | 466 | defaultDumpAction :: DumpCache -> LogAction -> DumpAction
|
| 518 | 467 | defaultDumpAction dumps log_action logflags sty flag title _fmt doc =
|
| ... | ... | @@ -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
|
| ... | ... | @@ -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 |
| 1 | +{"version":"1.1","ghcVersion":"ghc-9.13.20250627","span":{"file":"T16167.hs","start":{"line":1,"column":8},"end":{"line":1,"column":9}},"severity":"Error","code":58481,"message":["parse error on input \u2018f\u2019"],"hints":[]}
|
|
| 1 | 2 | *** Exception: ExitFailure 1 |
| 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"} |
| ... | ... | @@ -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
|
| 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)] |
| 1 | -module Foo where
|
|
| 2 | - |
|
| 3 | -import Data.List
|
|
| 4 | - |
|
| 5 | -id1 :: a -> a
|
|
| 6 | -id1 = 5 |
| 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"} |