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

Commits:

13 changed files:

Changes:

  • changelog.d/remove-ddump-json-flag
    1
    +section: compiler
    
    2
    +synopsis: Remove deprecated flag `-ddump-json`
    
    3
    +issues: #24113
    
    4
    +mrs: !16258

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

  • compiler/GHC/Driver/Session.hs
    ... ... @@ -1694,9 +1694,6 @@ dynamic_flags_deps = [
    1694 1694
             (NoArg (setGeneralFlag Opt_NoBignumRules))
    
    1695 1695
       , make_ord_flag defGhcFlag "ddump-debug"
    
    1696 1696
             (setDumpFlag Opt_D_dump_debug)
    
    1697
    -  , make_dep_flag defGhcFlag "ddump-json"
    
    1698
    -        (setDumpFlag Opt_D_dump_json)
    
    1699
    -        "Use `-fdiagnostics-as-json` instead"
    
    1700 1697
       , make_ord_flag defGhcFlag "dppr-debug"
    
    1701 1698
             (setDumpFlag Opt_D_ppr_debug)
    
    1702 1699
       , make_ord_flag defGhcFlag "ddebug-output"
    

  • compiler/GHC/Types/Error.hs
    ... ... @@ -549,15 +549,6 @@ instance ToJson Severity where
    549 549
       json SevWarning = JSString "Warning"
    
    550 550
       json SevError = JSString "Error"
    
    551 551
     
    
    552
    -instance ToJson MessageClass where
    
    553
    -  json MCOutput = JSString "MCOutput"
    
    554
    -  json MCFatal  = JSString "MCFatal"
    
    555
    -  json MCInteractive = JSString "MCInteractive"
    
    556
    -  json MCDump = JSString "MCDump"
    
    557
    -  json MCInfo = JSString "MCInfo"
    
    558
    -  json (MCDiagnostic sev reason code) =
    
    559
    -    JSString $ renderWithContext defaultSDocContext (ppr $ text "MCDiagnostic" <+> ppr sev <+> ppr reason <+> ppr code)
    
    560
    -
    
    561 552
     instance ToJson DiagnosticCode where
    
    562 553
       json c = JSInt (fromIntegral (diagnosticCodeNumber c))
    
    563 554
     
    

  • compiler/GHC/Utils/Logger.hs
    ... ... @@ -95,7 +95,6 @@ import GHC.Utils.Panic
    95 95
     
    
    96 96
     import GHC.Data.EnumSet (EnumSet)
    
    97 97
     import qualified GHC.Data.EnumSet as EnumSet
    
    98
    -import GHC.Data.FastString
    
    99 98
     
    
    100 99
     import System.Directory
    
    101 100
     import System.FilePath  ( takeDirectory, (</>) )
    
    ... ... @@ -360,7 +359,6 @@ makeThreadSafe logger = do
    360 359
                $ pushTraceHook trc
    
    361 360
                $ logger
    
    362 361
     
    
    363
    --- See Note [JSON Error Messages]
    
    364 362
     defaultLogJsonAction :: LogJsonAction
    
    365 363
     defaultLogJsonAction logflags msg_class jsdoc =
    
    366 364
       case msg_class of
    
    ... ... @@ -377,33 +375,6 @@ defaultLogJsonAction logflags msg_class jsdoc =
    377 375
         putStrSDoc = defaultLogActionHPutStrDoc logflags False stdout
    
    378 376
         msg = renderJSON jsdoc
    
    379 377
     
    
    380
    --- See Note [JSON Error Messages]
    
    381
    --- this is to be removed
    
    382
    -jsonLogActionWithHandle :: Handle {-^ Standard out -} -> LogAction
    
    383
    -jsonLogActionWithHandle _ _ (MCDiagnostic SevIgnore _ _) _ _ = return () -- suppress the message
    
    384
    -jsonLogActionWithHandle out logflags msg_class srcSpan msg
    
    385
    -  =
    
    386
    -    defaultLogActionHPutStrDoc logflags True out
    
    387
    -      (withPprStyle PprCode (doc $$ text ""))
    
    388
    -    where
    
    389
    -      str = renderWithContext (log_default_user_context logflags) msg
    
    390
    -      doc = renderJSON $
    
    391
    -              JSObject [ ( "span", spanToDumpJSON srcSpan )
    
    392
    -                       , ( "doc" , JSString str )
    
    393
    -                       , ( "messageClass", json msg_class )
    
    394
    -                       ]
    
    395
    -      spanToDumpJSON :: SrcSpan -> JsonDoc
    
    396
    -      spanToDumpJSON s = case s of
    
    397
    -                 (RealSrcSpan rss _) -> JSObject [ ("file", json file)
    
    398
    -                                                , ("startLine", json $ srcSpanStartLine rss)
    
    399
    -                                                , ("startCol", json $ srcSpanStartCol rss)
    
    400
    -                                                , ("endLine", json $ srcSpanEndLine rss)
    
    401
    -                                                , ("endCol", json $ srcSpanEndCol rss)
    
    402
    -                                                ]
    
    403
    -                   where file = unpackFS $ srcSpanFile rss
    
    404
    -                 GeneratedSrcSpan{} -> JSNull
    
    405
    -                 UnhelpfulSpan{} -> JSNull
    
    406
    -
    
    407 378
     -- | The default 'LogAction' prints to 'stdout' and 'stderr'.
    
    408 379
     --
    
    409 380
     -- To replicate the default log action behaviour with different @out@ and @err@
    
    ... ... @@ -415,8 +386,7 @@ defaultLogAction = defaultLogActionWithHandles stdout stderr
    415 386
     -- Allows clients to replicate the log message formatting of GHC with custom handles.
    
    416 387
     defaultLogActionWithHandles :: Handle {-^ Handle for standard output -} -> Handle {-^ Handle for standard errors -} -> LogAction
    
    417 388
     defaultLogActionWithHandles out err logflags msg_class srcSpan msg
    
    418
    -  | log_dopt Opt_D_dump_json logflags = jsonLogActionWithHandle out logflags msg_class srcSpan msg
    
    419
    -  | otherwise = case msg_class of
    
    389
    +  = case msg_class of
    
    420 390
           MCOutput                     -> printOut msg
    
    421 391
           MCDump                       -> printOut (msg $$ blankLine)
    
    422 392
           MCInteractive                -> putStrSDoc msg
    
    ... ... @@ -442,10 +412,6 @@ defaultLogActionWithHandles out err logflags msg_class srcSpan msg
    442 412
     -- 2. GHC uses two different code paths for JSON and non-JSON diagnostics.  For
    
    443 413
     --    that reason we can not decorate the message in `defaultLogActionWithHandles`.
    
    444 414
     --
    
    445
    ---    See also Note [JSON Error Messages]:
    
    446
    ---
    
    447
    ---      `jsonLogAction` should be removed along with -ddump-json
    
    448
    ---
    
    449 415
     -- Also note that (1) is the reason why some parts of the compiler produce
    
    450 416
     -- diagnostics that don't respect `-fdiagnostics-as-json`.
    
    451 417
     --
    
    ... ... @@ -493,28 +459,6 @@ defaultLogActionHPutStrDoc logflags asciiSpace h d
    493 459
       -- calls to this log-action can output all on the same line
    
    494 460
       = printSDoc (log_default_user_context logflags) (Pretty.PageMode asciiSpace) h d
    
    495 461
     
    
    496
    ---
    
    497
    --- Note [JSON Error Messages]
    
    498
    --- ~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    499
    ---
    
    500
    --- When the user requests the compiler output to be dumped as json
    
    501
    --- we used to collect them all in an IORef and then print them at the end.
    
    502
    --- This doesn't work very well with GHCi. (See #14078) So instead we now
    
    503
    --- use the simpler method of just outputting a JSON document inplace to
    
    504
    --- stdout.
    
    505
    ---
    
    506
    --- Before the compiler calls log_action, it has already turned the `ErrMsg`
    
    507
    --- into a formatted message. This means that we lose some possible
    
    508
    --- information to provide to the user but refactoring log_action is quite
    
    509
    --- invasive as it is called in many places. So, for now I left it alone
    
    510
    --- and we can refine its behaviour as users request different output.
    
    511
    ---
    
    512
    --- The recent work here replaces the purpose of flag -ddump-json with
    
    513
    --- -fdiagnostics-as-json. For temporary backwards compatibility while
    
    514
    --- -ddump-json is being deprecated, `jsonLogAction` has been added in, but
    
    515
    --- it should be removed along with -ddump-json. Similarly, the guard in
    
    516
    --- `defaultLogAction` should be removed. This cleanup is tracked in #24113.
    
    517
    -
    
    518 462
     -- | Default action for 'dumpAction' hook
    
    519 463
     defaultDumpAction :: DumpCache -> LogAction -> DumpAction
    
    520 464
     defaultDumpAction dumps log_action logflags sty flag title _fmt doc =
    

  • 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
    ... ... @@ -508,8 +508,6 @@ interactiveUI config baseDFlags srcs maybe_exprs = do
    508 508
     
    
    509 509
        installInteractiveHomeUnits baseDFlags
    
    510 510
     
    
    511
    -   -- Update the LogAction. Ensure we don't override the user's log action lest
    
    512
    -   -- we break -ddump-json (#14078)
    
    513 511
        lastErrLocationsRef <- liftIO $ newIORef []
    
    514 512
        pushLogHookM (ghciLogAction lastErrLocationsRef)
    
    515 513
     
    

  • testsuite/tests/driver/T16167.stderr
    1
    -*** Exception: ExitFailure 1
    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":[]}

  • 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
    ... ... @@ -271,12 +271,10 @@ test('T12752pass', normal, compile, ['-DSHOULD_PASS=1 -Wcpp-undef'])
    271 271
     test('T12955', normal, makefile_test, [])
    
    272 272
     
    
    273 273
     test('T12971', [when(opsys('mingw32'), fragile(17945)), ignore_stdout], makefile_test, [])
    
    274
    -test('json_dump', normal, compile_fail, ['-ddump-json'])
    
    275 274
     test('json', normalise_version('ghc'), compile_fail, ['-fdiagnostics-as-json'])
    
    276 275
     test('json_warn', normalise_version('ghc'), compile, ['-fdiagnostics-as-json -Wunused-matches -Wx-partial'])
    
    277
    -test('json2', normalise_version('ghc-internal', 'base','ghc-prim'), compile, ['-ddump-types -ddump-json -Wno-unsupported-llvm-version'])
    
    278
    -test('T16167', [normalise_version('ghc'),req_interp,exit_code(1)], run_command,
    
    279
    -     ['{compiler} -x hs -e ":set prog T16167.hs" -ddump-json T16167.hs'])
    
    276
    +test('json2', normalise_version('ghc-internal', 'base','ghc-prim'), compile, ['-ddump-types -fdiagnostics-as-json -Wno-unsupported-llvm-version'])
    
    277
    +test('T16167', normalise_version('ghc'), compile_fail, ['-fdiagnostics-as-json'])
    
    280 278
     test('T13604', [], makefile_test, [])
    
    281 279
     test('T13604a',
    
    282 280
       [ 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"}