summaryrefslogtreecommitdiff
path: root/compiler/GHC/Driver/Main.hs
diff options
context:
space:
mode:
authorAlfredo Di Napoli <alfredo@well-typed.com>2021-04-20 11:03:01 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-05-20 18:08:37 -0400
commitaac87bd388547e28aca1c19e7436ff5fa9245f04 (patch)
tree3c03ec7ad5336d45c4108483df0a2f5bce70de1f /compiler/GHC/Driver/Main.hs
parent7c066734705048edb5b5b0afc30acea0805ec18d (diff)
downloadhaskell-aac87bd388547e28aca1c19e7436ff5fa9245f04.tar.gz
Extensible Hints for diagnostic messages
This commit extends the GHC diagnostic hierarchy with a `GhcHint` type, modelling helpful suggestions emitted by GHC which can be used to deal with a particular warning or error. As a direct consequence of this, the `Diagnostic` typeclass has been extended with a `diagnosticHints` method, which returns a `[GhcHint]`. This means that now we can clearly separate out the printing of the diagnostic message with the suggested fixes. This is done by extending the `printMessages` function in `GHC.Driver.Errors`. On top of that, the old `PsHint` type has been superseded by the new `GhcHint` type, which de-duplicates some hints in favour of a general `SuggestExtension` constructor that takes a `GHC.LanguageExtensions.Extension`.
Diffstat (limited to 'compiler/GHC/Driver/Main.hs')
-rw-r--r--compiler/GHC/Driver/Main.hs26
1 files changed, 13 insertions, 13 deletions
diff --git a/compiler/GHC/Driver/Main.hs b/compiler/GHC/Driver/Main.hs
index 2d3e1e3925..8c09f4434c 100644
--- a/compiler/GHC/Driver/Main.hs
+++ b/compiler/GHC/Driver/Main.hs
@@ -570,7 +570,7 @@ tcRnModule' sum save_rn_syntax mod = do
logDiagnostics $ singleMessage $
mkPlainMsgEnvelope dflags (getLoc (hpm_module mod)) $
GhcDriverMessage $ DriverUnknownMessage $
- mkPlainDiagnostic reason warnMissingSafeHaskellMode
+ mkPlainDiagnostic reason noHints warnMissingSafeHaskellMode
tcg_res <- {-# SCC "Typecheck-Rename" #-}
ioMsgMaybe $ hoistTcRnMessage $
@@ -600,14 +600,14 @@ tcRnModule' sum save_rn_syntax mod = do
| otherwise -> (logDiagnostics $ singleMessage $
mkPlainMsgEnvelope dflags (warnSafeOnLoc dflags) $
GhcDriverMessage $ DriverUnknownMessage $
- mkPlainDiagnostic (WarningWithFlag Opt_WarnSafe) $
+ mkPlainDiagnostic (WarningWithFlag Opt_WarnSafe) noHints $
errSafe tcg_res')
False | safeHaskell dflags == Sf_Trustworthy &&
wopt Opt_WarnTrustworthySafe dflags ->
(logDiagnostics $ singleMessage $
mkPlainMsgEnvelope dflags (trustworthyOnLoc dflags) $
GhcDriverMessage $ DriverUnknownMessage $
- mkPlainDiagnostic (WarningWithFlag Opt_WarnTrustworthySafe) $
+ mkPlainDiagnostic (WarningWithFlag Opt_WarnTrustworthySafe) noHints $
errTwthySafe tcg_res')
False -> return ()
return tcg_res'
@@ -1201,7 +1201,7 @@ hscCheckSafeImports tcg_env = do
warnRules df (L loc (HsRule { rd_name = n })) =
mkPlainMsgEnvelope df (locA loc) $
DriverUnknownMessage $
- mkPlainDiagnostic WarningWithoutFlag $
+ mkPlainDiagnostic WarningWithoutFlag noHints $
text "Rule \"" <> ftext (snd $ unLoc n) <> text "\" ignored" $+$
text "User defined rules are disabled under Safe Haskell"
@@ -1279,7 +1279,7 @@ checkSafeImports tcg_env
| imv_is_safe v1 /= imv_is_safe v2
= throwOneError $
mkPlainErrorMsgEnvelope (imv_span v1) $
- GhcDriverMessage $ DriverUnknownMessage $ mkPlainError $
+ GhcDriverMessage $ DriverUnknownMessage $ mkPlainError noHints $
text "Module" <+> ppr (imv_name v1) <+>
(text $ "is imported both as a safe and unsafe import!")
| otherwise
@@ -1349,7 +1349,7 @@ hscCheckSafe' m l = do
-- can't load iface to check trust!
Nothing -> throwOneError $
mkPlainErrorMsgEnvelope l $
- GhcDriverMessage $ DriverUnknownMessage $ mkPlainError $
+ GhcDriverMessage $ DriverUnknownMessage $ mkPlainError noHints $
text "Can't load the interface file for" <+> ppr m
<> text ", to check that it can be safely imported"
@@ -1384,7 +1384,7 @@ hscCheckSafe' m l = do
inferredImportWarn dflags = singleMessage
$ mkMsgEnvelope dflags l (pkgQual state)
$ GhcDriverMessage $ DriverUnknownMessage
- $ mkPlainDiagnostic (WarningWithFlag Opt_WarnInferredSafeImports)
+ $ mkPlainDiagnostic (WarningWithFlag Opt_WarnInferredSafeImports) noHints
$ sep
[ text "Importing Safe-Inferred module "
<> ppr (moduleName m)
@@ -1393,7 +1393,7 @@ hscCheckSafe' m l = do
pkgTrustErr = singleMessage
$ mkErrorMsgEnvelope l (pkgQual state)
$ GhcDriverMessage $ DriverUnknownMessage
- $ mkPlainError
+ $ mkPlainError noHints
$ sep [ ppr (moduleName m)
<> text ": Can't be safely imported!"
, text "The package ("
@@ -1403,7 +1403,7 @@ hscCheckSafe' m l = do
modTrustErr = singleMessage
$ mkErrorMsgEnvelope l (pkgQual state)
$ GhcDriverMessage $ DriverUnknownMessage
- $ mkPlainError
+ $ mkPlainError noHints
$ sep [ ppr (moduleName m)
<> text ": Can't be safely imported!"
, text "The module itself isn't safe." ]
@@ -1453,7 +1453,7 @@ checkPkgTrust pkgs = do
$ mkErrorMsgEnvelope noSrcSpan (pkgQual state)
$ GhcDriverMessage
$ DriverUnknownMessage
- $ mkPlainError
+ $ mkPlainError noHints
$ pprWithUnitState state
$ text "The package ("
<> ppr pkg
@@ -1481,7 +1481,7 @@ markUnsafeInfer tcg_env whyUnsafe = do
(logDiagnostics $ singleMessage $
mkPlainMsgEnvelope dflags (warnUnsafeOnLoc dflags) $
GhcDriverMessage $ DriverUnknownMessage $
- mkPlainDiagnostic reason $
+ mkPlainDiagnostic reason noHints $
whyUnsafe' dflags)
liftIO $ writeIORef (tcg_safe_infer tcg_env) False
@@ -2079,7 +2079,7 @@ hscImport hsc_env str = runInteractiveHsc hsc_env $ do
[L _ i] -> return i
_ -> liftIO $ throwOneError $
mkPlainErrorMsgEnvelope noSrcSpan $
- GhcPsMessage $ PsUnknownMessage $ mkPlainError $
+ GhcPsMessage $ PsUnknownMessage $ mkPlainError noHints $
text "parse error in import declaration"
-- | Typecheck an expression (but don't run it)
@@ -2110,7 +2110,7 @@ hscParseExpr expr = do
Just (L _ (BodyStmt _ expr _ _)) -> return expr
_ -> throwOneError $
mkPlainErrorMsgEnvelope noSrcSpan $
- GhcPsMessage $ PsUnknownMessage $ mkPlainError $
+ GhcPsMessage $ PsUnknownMessage $ mkPlainError noHints $
text "not an expression:" <+> quotes (text expr)
hscParseStmt :: String -> Hsc (Maybe (GhciLStmt GhcPs))