Simon Hengel pushed to branch wip/sol/driver-diagnostics at Glasgow Haskell Compiler / GHC
Commits:
-
99e86cdb
by Simon Hengel at 2025-07-25T03:40:43+07:00
-
459bce88
by Simon Hengel at 2025-07-25T03:40:43+07:00
-
9d8559ce
by Simon Hengel at 2025-07-25T03:40:43+07:00
8 changed files:
- compiler/GHC/Core/Opt/Monad.hs
- compiler/GHC/Core/Opt/SpecConstr.hs
- compiler/GHC/Core/Opt/Specialise.hs
- compiler/GHC/Driver/Make.hs
- compiler/GHC/Linker/Loader.hs
- compiler/GHC/SysTools/Tasks.hs
- compiler/GHC/Utils/Error.hs
- testsuite/tests/corelint/T21115b.stderr
Changes:
| ... | ... | @@ -33,7 +33,7 @@ module GHC.Core.Opt.Monad ( |
| 33 | 33 | getAnnotations, getFirstAnnotations,
|
| 34 | 34 | |
| 35 | 35 | -- ** Screen output
|
| 36 | - putMsg, putMsgS, errorMsg, msg,
|
|
| 36 | + putMsg, putMsgS, errorMsg, msg, diagnostic,
|
|
| 37 | 37 | fatalErrorMsg, fatalErrorMsgS,
|
| 38 | 38 | debugTraceMsg, debugTraceMsgS,
|
| 39 | 39 | ) where
|
| ... | ... | @@ -41,6 +41,8 @@ module GHC.Core.Opt.Monad ( |
| 41 | 41 | import GHC.Prelude hiding ( read )
|
| 42 | 42 | |
| 43 | 43 | import GHC.Driver.DynFlags
|
| 44 | +import GHC.Driver.Errors ( reportDiagnostic, reportError )
|
|
| 45 | +import GHC.Driver.Config.Diagnostic ( initDiagOpts )
|
|
| 44 | 46 | import GHC.Driver.Env
|
| 45 | 47 | |
| 46 | 48 | import GHC.Core.Rules ( RuleBase, RuleEnv, mkRuleEnv )
|
| ... | ... | @@ -52,7 +54,6 @@ import GHC.Types.Name.Env |
| 52 | 54 | import GHC.Types.SrcLoc
|
| 53 | 55 | import GHC.Types.Error
|
| 54 | 56 | |
| 55 | -import GHC.Utils.Error ( errorDiagnostic )
|
|
| 56 | 57 | import GHC.Utils.Outputable as Outputable
|
| 57 | 58 | import GHC.Utils.Logger
|
| 58 | 59 | import GHC.Utils.Monad
|
| ... | ... | @@ -383,9 +384,22 @@ putMsgS = putMsg . text |
| 383 | 384 | putMsg :: SDoc -> CoreM ()
|
| 384 | 385 | putMsg = msg MCInfo
|
| 385 | 386 | |
| 387 | +diagnostic :: DiagnosticReason -> SDoc -> CoreM ()
|
|
| 388 | +diagnostic reason doc = do
|
|
| 389 | + logger <- getLogger
|
|
| 390 | + loc <- getSrcSpanM
|
|
| 391 | + name_ppr_ctx <- getNamePprCtx
|
|
| 392 | + diag_opts <- initDiagOpts <$> getDynFlags
|
|
| 393 | + liftIO $ reportDiagnostic logger name_ppr_ctx diag_opts loc reason doc
|
|
| 394 | + |
|
| 386 | 395 | -- | Output an error to the screen. Does not cause the compiler to die.
|
| 387 | 396 | errorMsg :: SDoc -> CoreM ()
|
| 388 | -errorMsg doc = msg errorDiagnostic doc
|
|
| 397 | +errorMsg doc = do
|
|
| 398 | + logger <- getLogger
|
|
| 399 | + loc <- getSrcSpanM
|
|
| 400 | + name_ppr_ctx <- getNamePprCtx
|
|
| 401 | + diag_opts <- initDiagOpts <$> getDynFlags
|
|
| 402 | + liftIO $ reportError logger name_ppr_ctx diag_opts loc doc
|
|
| 389 | 403 | |
| 390 | 404 | -- | Output a fatal error to the screen. Does not cause the compiler to die.
|
| 391 | 405 | fatalErrorMsgS :: String -> CoreM ()
|
| ... | ... | @@ -45,7 +45,7 @@ import GHC.Core.Make ( mkImpossibleExpr ) |
| 45 | 45 | import GHC.Unit.Module
|
| 46 | 46 | import GHC.Unit.Module.ModGuts
|
| 47 | 47 | |
| 48 | -import GHC.Types.Error (MessageClass(..), Severity(..), DiagnosticReason(WarningWithoutFlag), ResolvedDiagnosticReason (..))
|
|
| 48 | +import GHC.Types.Error (DiagnosticReason(..))
|
|
| 49 | 49 | import GHC.Types.Literal ( litIsLifted )
|
| 50 | 50 | import GHC.Types.Id
|
| 51 | 51 | import GHC.Types.Id.Info ( IdDetails(..) )
|
| ... | ... | @@ -783,12 +783,11 @@ specConstrProgram guts |
| 783 | 783 | ; let (_usg, binds', warnings) = initUs_ us $
|
| 784 | 784 | scTopBinds env0 (mg_binds guts)
|
| 785 | 785 | |
| 786 | - ; when (not (null warnings)) $ msg specConstr_warn_class (warn_msg warnings)
|
|
| 786 | + ; when (not (null warnings)) $ diagnostic WarningWithoutFlag (warn_msg warnings)
|
|
| 787 | 787 | |
| 788 | 788 | ; return (guts { mg_binds = binds' }) }
|
| 789 | 789 | |
| 790 | 790 | where
|
| 791 | - specConstr_warn_class = MCDiagnostic SevWarning (ResolvedDiagnosticReason WarningWithoutFlag) Nothing
|
|
| 792 | 791 | warn_msg :: SpecFailWarnings -> SDoc
|
| 793 | 792 | warn_msg warnings = text "SpecConstr encountered one or more function(s) with a SPEC argument that resulted in too many arguments," $$
|
| 794 | 793 | text "which resulted in no specialization being generated for these functions:" $$
|
| ... | ... | @@ -12,7 +12,6 @@ import GHC.Prelude |
| 12 | 12 | |
| 13 | 13 | import GHC.Driver.DynFlags
|
| 14 | 14 | import GHC.Driver.Config
|
| 15 | -import GHC.Driver.Config.Diagnostic
|
|
| 16 | 15 | import GHC.Driver.Config.Core.Rules ( initRuleOpts )
|
| 17 | 16 | |
| 18 | 17 | import GHC.Core.Type hiding( substTy, substCo, extendTvSubst, zapSubst )
|
| ... | ... | @@ -55,7 +54,6 @@ import GHC.Types.Id |
| 55 | 54 | import GHC.Types.Id.Info
|
| 56 | 55 | import GHC.Types.Error
|
| 57 | 56 | |
| 58 | -import GHC.Utils.Error ( mkMCDiagnostic )
|
|
| 59 | 57 | import GHC.Utils.Monad ( foldlM )
|
| 60 | 58 | import GHC.Utils.Misc
|
| 61 | 59 | import GHC.Utils.Outputable
|
| ... | ... | @@ -938,10 +936,12 @@ tryWarnMissingSpecs dflags callers fn calls_for_fn |
| 938 | 936 | | wopt Opt_WarnAllMissedSpecs dflags = doWarn $ WarningWithFlag Opt_WarnAllMissedSpecs
|
| 939 | 937 | | otherwise = return ()
|
| 940 | 938 | where
|
| 939 | + allCallersInlined :: Bool
|
|
| 941 | 940 | allCallersInlined = all (isAnyInlinePragma . idInlinePragma) callers
|
| 942 | - diag_opts = initDiagOpts dflags
|
|
| 941 | + |
|
| 942 | + doWarn :: DiagnosticReason -> CoreM ()
|
|
| 943 | 943 | doWarn reason =
|
| 944 | - msg (mkMCDiagnostic diag_opts reason Nothing)
|
|
| 944 | + diagnostic reason
|
|
| 945 | 945 | (vcat [ hang (text ("Could not specialise imported function") <+> quotes (ppr fn))
|
| 946 | 946 | 2 (vcat [ text "when specialising" <+> quotes (ppr caller)
|
| 947 | 947 | | caller <- callers])
|
| ... | ... | @@ -1552,7 +1552,7 @@ wrapAction msg_wrapper hsc_env k = do |
| 1552 | 1552 | -- ThreadKilled in particular needs to actually kill the thread.
|
| 1553 | 1553 | -- So rethrow that and the other async exceptions
|
| 1554 | 1554 | Just (err :: SomeAsyncException) -> throwIO err
|
| 1555 | - _ -> errorMsg lcl_logger (text (show exc))
|
|
| 1555 | + _ -> reportError lcl_logger neverQualify emptyDiagOpts noSrcSpan (text (show exc))
|
|
| 1556 | 1556 | return Nothing
|
| 1557 | 1557 | |
| 1558 | 1558 |
| ... | ... | @@ -43,6 +43,7 @@ import GHC.Settings |
| 43 | 43 | import GHC.Platform
|
| 44 | 44 | import GHC.Platform.Ways
|
| 45 | 45 | |
| 46 | +import GHC.Driver.Errors
|
|
| 46 | 47 | import GHC.Driver.Phases
|
| 47 | 48 | import GHC.Driver.Env
|
| 48 | 49 | import GHC.Driver.Session
|
| ... | ... | @@ -50,7 +51,7 @@ import GHC.Driver.Ppr |
| 50 | 51 | import GHC.Driver.Config.Diagnostic
|
| 51 | 52 | import GHC.Driver.Config.Finder
|
| 52 | 53 | |
| 53 | -import GHC.Tc.Utils.Monad
|
|
| 54 | +import GHC.Tc.Utils.Monad hiding (reportDiagnostic)
|
|
| 54 | 55 | |
| 55 | 56 | import GHC.Runtime.Interpreter
|
| 56 | 57 | import GHCi.BreakArray
|
| ... | ... | @@ -1307,9 +1308,9 @@ load_dyn interp hsc_env crash_early dll = do |
| 1307 | 1308 | then cmdLineErrorIO err
|
| 1308 | 1309 | else do
|
| 1309 | 1310 | when (diag_wopt Opt_WarnMissedExtraSharedLib diag_opts)
|
| 1310 | - $ logMsg logger
|
|
| 1311 | - (mkMCDiagnostic diag_opts (WarningWithFlag Opt_WarnMissedExtraSharedLib) Nothing)
|
|
| 1312 | - noSrcSpan $ withPprStyle defaultUserStyle (note err)
|
|
| 1311 | + $ reportDiagnostic logger
|
|
| 1312 | + neverQualify diag_opts
|
|
| 1313 | + noSrcSpan (WarningWithFlag Opt_WarnMissedExtraSharedLib) $ withPprStyle defaultUserStyle (note err)
|
|
| 1313 | 1314 | pure Nothing
|
| 1314 | 1315 | where
|
| 1315 | 1316 | diag_opts = initDiagOpts (hsc_dflags hsc_env)
|
| ... | ... | @@ -1497,8 +1498,7 @@ locateLib interp hsc_env is_hs lib_dirs gcc_dirs lib0 |
| 1497 | 1498 | , not loading_dynamic_hs_libs
|
| 1498 | 1499 | , interpreterProfiled interp
|
| 1499 | 1500 | = do
|
| 1500 | - let diag = mkMCDiagnostic diag_opts WarningWithoutFlag Nothing
|
|
| 1501 | - logMsg logger diag noSrcSpan $ withPprStyle defaultErrStyle $
|
|
| 1501 | + reportDiagnostic logger neverQualify diag_opts noSrcSpan WarningWithoutFlag $ withPprStyle defaultErrStyle $
|
|
| 1502 | 1502 | text "Interpreter failed to load profiled static library" <+> text lib <> char '.' $$
|
| 1503 | 1503 | text " \tTrying dynamic library instead. If this fails try to rebuild" <+>
|
| 1504 | 1504 | text "libraries with profiling support."
|
| ... | ... | @@ -55,7 +55,7 @@ import GHC.Driver.Config.Diagnostic |
| 55 | 55 | import GHC.Driver.Errors
|
| 56 | 56 | import GHC.Driver.Errors.Types (GhcMessage(..), DriverMessage (DriverNoConfiguredLLVMToolchain))
|
| 57 | 57 | import GHC.Driver.CmdLine (warnsToMessages)
|
| 58 | -import GHC.Types.SrcLoc (noLoc)
|
|
| 58 | +import GHC.Types.SrcLoc (noLoc, noSrcSpan)
|
|
| 59 | 59 | |
| 60 | 60 | {-
|
| 61 | 61 | ************************************************************************
|
| ... | ... | @@ -346,7 +346,7 @@ figureLlvmVersion logger dflags = traceSystoolCommand logger "llc" $ do |
| 346 | 346 | debugTraceMsg logger 2
|
| 347 | 347 | (text "Error (figuring out LLVM version):" <+>
|
| 348 | 348 | text (show err))
|
| 349 | - errorMsg logger $ vcat
|
|
| 349 | + reportError logger neverQualify emptyDiagOpts noSrcSpan $ vcat
|
|
| 350 | 350 | [ text "Warning:", nest 9 $
|
| 351 | 351 | text "Couldn't figure out LLVM version!" $$
|
| 352 | 352 | text ("Make sure you have installed LLVM between ["
|
| ... | ... | @@ -32,7 +32,7 @@ module GHC.Utils.Error ( |
| 32 | 32 | emptyMessages, mkDecorated, mkLocMessage,
|
| 33 | 33 | mkMsgEnvelope, mkPlainMsgEnvelope, mkPlainErrorMsgEnvelope,
|
| 34 | 34 | mkErrorMsgEnvelope,
|
| 35 | - mkMCDiagnostic, errorDiagnostic, diagReasonSeverity,
|
|
| 35 | + mkMCDiagnostic, diagReasonSeverity,
|
|
| 36 | 36 | |
| 37 | 37 | mkPlainError,
|
| 38 | 38 | mkPlainDiagnostic,
|
| ... | ... | @@ -46,7 +46,6 @@ module GHC.Utils.Error ( |
| 46 | 46 | -- * Issuing messages during compilation
|
| 47 | 47 | putMsg, printInfoForUser, printOutputForUser,
|
| 48 | 48 | logInfo, logOutput,
|
| 49 | - errorMsg,
|
|
| 50 | 49 | fatalErrorMsg,
|
| 51 | 50 | compilationProgressMsg,
|
| 52 | 51 | showPass,
|
| ... | ... | @@ -168,11 +167,6 @@ mkMCDiagnostic opts reason code = MCDiagnostic sev reason' code |
| 168 | 167 | where
|
| 169 | 168 | (sev, reason') = diag_reason_severity opts reason
|
| 170 | 169 | |
| 171 | --- | Varation of 'mkMCDiagnostic' which can be used when we are /sure/ the
|
|
| 172 | --- input 'DiagnosticReason' /is/ 'ErrorWithoutFlag' and there is no diagnostic code.
|
|
| 173 | -errorDiagnostic :: MessageClass
|
|
| 174 | -errorDiagnostic = MCDiagnostic SevError (ResolvedDiagnosticReason ErrorWithoutFlag) Nothing
|
|
| 175 | - |
|
| 176 | 170 | --
|
| 177 | 171 | -- Creating MsgEnvelope(s)
|
| 178 | 172 | --
|
| ... | ... | @@ -318,17 +312,12 @@ sortMsgBag mopts = maybeLimit . sortBy (cmp `on` errMsgSpan) . bagToList |
| 318 | 312 | ghcExit :: Logger -> Int -> IO ()
|
| 319 | 313 | ghcExit logger val
|
| 320 | 314 | | val == 0 = exitWith ExitSuccess
|
| 321 | - | otherwise = do errorMsg logger (text "\nCompilation had errors\n\n")
|
|
| 315 | + | otherwise = do fatalErrorMsg logger (text "\nCompilation had errors\n\n")
|
|
| 322 | 316 | exitWith (ExitFailure val)
|
| 323 | 317 | |
| 324 | 318 | -- -----------------------------------------------------------------------------
|
| 325 | 319 | -- Outputting messages from the compiler
|
| 326 | 320 | |
| 327 | -errorMsg :: Logger -> SDoc -> IO ()
|
|
| 328 | -errorMsg logger msg
|
|
| 329 | - = logMsg logger errorDiagnostic noSrcSpan $
|
|
| 330 | - withPprStyle defaultErrStyle msg
|
|
| 331 | - |
|
| 332 | 321 | fatalErrorMsg :: Logger -> SDoc -> IO ()
|
| 333 | 322 | fatalErrorMsg logger msg =
|
| 334 | 323 | logMsg logger MCFatal noSrcSpan $ withPprStyle defaultErrStyle msg
|
| ... | ... | @@ -30,6 +30,6 @@ end Rec } |
| 30 | 30 | |
| 31 | 31 | *** End of Offense ***
|
| 32 | 32 | |
| 33 | - |
|
| 34 | -<no location info>: error:
|
|
| 35 | 33 | Compilation had errors
|
| 34 | + |
|
| 35 | + |