{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeApplications #-}
{-# OPTIONS_GHC -fno-warn-orphans #-} -- instance Diagnostic {DriverMessage, GhcMessage}

module GHC.Driver.Errors.Ppr (
  -- This module only exports Diagnostic instances.
  ) where

import GHC.Prelude

import GHC.Driver.Errors.Types
import GHC.Driver.Flags
import GHC.Driver.DynFlags
import GHC.HsToCore.Errors.Ppr () -- instance Diagnostic DsMessage
import GHC.Parser.Errors.Ppr () -- instance Diagnostic PsMessage
import GHC.Types.Error
import GHC.Types.Error.Codes
import GHC.Unit.Types
import GHC.Utils.Outputable
import GHC.Utils.Panic
import GHC.Unit.Module
import GHC.Unit.Module.Graph
import GHC.Unit.Module.ModSummary
import GHC.Unit.State
import GHC.Types.Hint
import GHC.Types.SrcLoc
import Data.Version

import Language.Haskell.Syntax.Decls (RuleDecl(..))
import GHC.Tc.Errors.Types (TcRnMessage)
import GHC.HsToCore.Errors.Types (DsMessage)
import GHC.Iface.Errors.Types
import GHC.Tc.Errors.Ppr () -- instance Diagnostic TcRnMessage
import GHC.Iface.Errors.Ppr () -- instance Diagnostic IfaceMessage
import GHC.CmmToLlvm.Version (llvmVersionStr, supportedLlvmVersionLowerBound, supportedLlvmVersionUpperBound)

--
-- Suggestions
--

-- | Suggests a list of 'InstantiationSuggestion' for the '.hsig' file to the user.
suggestInstantiatedWith :: ModuleName -> GenInstantiations UnitId -> [InstantiationSuggestion]
suggestInstantiatedWith :: ModuleName -> GenInstantiations UnitId -> [InstantiationSuggestion]
suggestInstantiatedWith ModuleName
pi_mod_name GenInstantiations UnitId
insts =
  [ ModuleName -> Module -> InstantiationSuggestion
InstantiationSuggestion ModuleName
k Module
v | (ModuleName
k,Module
v) <- ((ModuleName
pi_mod_name, ModuleName -> Module
forall u. ModuleName -> GenModule (GenUnit u)
mkHoleModule ModuleName
pi_mod_name) (ModuleName, Module)
-> GenInstantiations UnitId -> GenInstantiations UnitId
forall a. a -> [a] -> [a]
: GenInstantiations UnitId
insts) ]

instance HasDefaultDiagnosticOpts GhcMessageOpts where
  defaultOpts :: GhcMessageOpts
defaultOpts = DiagnosticOpts PsMessage
-> DiagnosticOpts TcRnMessage
-> DiagnosticOpts DsMessage
-> DiagnosticOpts DriverMessage
-> GhcMessageOpts
GhcMessageOpts (forall opts.
HasDefaultDiagnosticOpts (DiagnosticOpts opts) =>
DiagnosticOpts opts
defaultDiagnosticOpts @PsMessage)
                                         (forall opts.
HasDefaultDiagnosticOpts (DiagnosticOpts opts) =>
DiagnosticOpts opts
defaultDiagnosticOpts @TcRnMessage)
                                         (forall opts.
HasDefaultDiagnosticOpts (DiagnosticOpts opts) =>
DiagnosticOpts opts
defaultDiagnosticOpts @DsMessage)
                                         (forall opts.
HasDefaultDiagnosticOpts (DiagnosticOpts opts) =>
DiagnosticOpts opts
defaultDiagnosticOpts @DriverMessage)

instance Diagnostic GhcMessage where
  type DiagnosticOpts GhcMessage = GhcMessageOpts
  diagnosticMessage :: DiagnosticOpts GhcMessage -> GhcMessage -> DecoratedSDoc
diagnosticMessage DiagnosticOpts GhcMessage
opts = \case
    GhcPsMessage PsMessage
m
      -> DiagnosticOpts PsMessage -> PsMessage -> DecoratedSDoc
forall a. Diagnostic a => DiagnosticOpts a -> a -> DecoratedSDoc
diagnosticMessage (GhcMessageOpts -> DiagnosticOpts PsMessage
psMessageOpts DiagnosticOpts GhcMessage
GhcMessageOpts
opts) PsMessage
m
    GhcTcRnMessage TcRnMessage
m
      -> DiagnosticOpts TcRnMessage -> TcRnMessage -> DecoratedSDoc
forall a. Diagnostic a => DiagnosticOpts a -> a -> DecoratedSDoc
diagnosticMessage (GhcMessageOpts -> DiagnosticOpts TcRnMessage
tcMessageOpts DiagnosticOpts GhcMessage
GhcMessageOpts
opts) TcRnMessage
m
    GhcDsMessage DsMessage
m
      -> DiagnosticOpts DsMessage -> DsMessage -> DecoratedSDoc
forall a. Diagnostic a => DiagnosticOpts a -> a -> DecoratedSDoc
diagnosticMessage (GhcMessageOpts -> DiagnosticOpts DsMessage
dsMessageOpts DiagnosticOpts GhcMessage
GhcMessageOpts
opts) DsMessage
m
    GhcDriverMessage DriverMessage
m
      -> DiagnosticOpts DriverMessage -> DriverMessage -> DecoratedSDoc
forall a. Diagnostic a => DiagnosticOpts a -> a -> DecoratedSDoc
diagnosticMessage (GhcMessageOpts -> DiagnosticOpts DriverMessage
driverMessageOpts DiagnosticOpts GhcMessage
GhcMessageOpts
opts) DriverMessage
m
    GhcUnknownMessage (UnknownDiagnostic DiagnosticOpts GhcMessage -> DiagnosticOpts a
f a
m)
      -> DiagnosticOpts a -> a -> DecoratedSDoc
forall a. Diagnostic a => DiagnosticOpts a -> a -> DecoratedSDoc
diagnosticMessage (DiagnosticOpts GhcMessage -> DiagnosticOpts a
f DiagnosticOpts GhcMessage
opts) a
m

  diagnosticReason :: GhcMessage -> DiagnosticReason
diagnosticReason = \case
    GhcPsMessage PsMessage
m
      -> PsMessage -> DiagnosticReason
forall a. Diagnostic a => a -> DiagnosticReason
diagnosticReason PsMessage
m
    GhcTcRnMessage TcRnMessage
m
      -> TcRnMessage -> DiagnosticReason
forall a. Diagnostic a => a -> DiagnosticReason
diagnosticReason TcRnMessage
m
    GhcDsMessage DsMessage
m
      -> DsMessage -> DiagnosticReason
forall a. Diagnostic a => a -> DiagnosticReason
diagnosticReason DsMessage
m
    GhcDriverMessage DriverMessage
m
      -> DriverMessage -> DiagnosticReason
forall a. Diagnostic a => a -> DiagnosticReason
diagnosticReason DriverMessage
m
    GhcUnknownMessage UnknownDiagnostic (DiagnosticOpts GhcMessage)
m
      -> UnknownDiagnostic GhcMessageOpts -> DiagnosticReason
forall a. Diagnostic a => a -> DiagnosticReason
diagnosticReason UnknownDiagnostic (DiagnosticOpts GhcMessage)
UnknownDiagnostic GhcMessageOpts
m

  diagnosticHints :: GhcMessage -> [GhcHint]
diagnosticHints = \case
    GhcPsMessage PsMessage
m
      -> PsMessage -> [GhcHint]
forall a. Diagnostic a => a -> [GhcHint]
diagnosticHints PsMessage
m
    GhcTcRnMessage TcRnMessage
m
      -> TcRnMessage -> [GhcHint]
forall a. Diagnostic a => a -> [GhcHint]
diagnosticHints TcRnMessage
m
    GhcDsMessage DsMessage
m
      -> DsMessage -> [GhcHint]
forall a. Diagnostic a => a -> [GhcHint]
diagnosticHints DsMessage
m
    GhcDriverMessage DriverMessage
m
      -> DriverMessage -> [GhcHint]
forall a. Diagnostic a => a -> [GhcHint]
diagnosticHints DriverMessage
m
    GhcUnknownMessage UnknownDiagnostic (DiagnosticOpts GhcMessage)
m
      -> UnknownDiagnostic GhcMessageOpts -> [GhcHint]
forall a. Diagnostic a => a -> [GhcHint]
diagnosticHints UnknownDiagnostic (DiagnosticOpts GhcMessage)
UnknownDiagnostic GhcMessageOpts
m

  diagnosticCode :: GhcMessage -> Maybe DiagnosticCode
diagnosticCode = GhcMessage -> Maybe DiagnosticCode
forall diag.
(Generic diag, GDiagnosticCode (Rep diag)) =>
diag -> Maybe DiagnosticCode
constructorCode

instance HasDefaultDiagnosticOpts DriverMessageOpts where
  defaultOpts :: DriverMessageOpts
defaultOpts = DiagnosticOpts PsMessage
-> DiagnosticOpts IfaceMessage -> DriverMessageOpts
DriverMessageOpts (forall opts.
HasDefaultDiagnosticOpts (DiagnosticOpts opts) =>
DiagnosticOpts opts
defaultDiagnosticOpts @PsMessage) (forall opts.
HasDefaultDiagnosticOpts (DiagnosticOpts opts) =>
DiagnosticOpts opts
defaultDiagnosticOpts @IfaceMessage)

instance Diagnostic DriverMessage where
  type DiagnosticOpts DriverMessage = DriverMessageOpts
  diagnosticMessage :: DiagnosticOpts DriverMessage -> DriverMessage -> DecoratedSDoc
diagnosticMessage DiagnosticOpts DriverMessage
opts = \case
    DriverUnknownMessage (UnknownDiagnostic DiagnosticOpts DriverMessage -> DiagnosticOpts a
f a
m)
      -> DiagnosticOpts a -> a -> DecoratedSDoc
forall a. Diagnostic a => DiagnosticOpts a -> a -> DecoratedSDoc
diagnosticMessage (DiagnosticOpts DriverMessage -> DiagnosticOpts a
f DiagnosticOpts DriverMessage
opts) a
m
    DriverPsHeaderMessage PsMessage
m
      -> DiagnosticOpts PsMessage -> PsMessage -> DecoratedSDoc
forall a. Diagnostic a => DiagnosticOpts a -> a -> DecoratedSDoc
diagnosticMessage (DriverMessageOpts -> DiagnosticOpts PsMessage
psDiagnosticOpts DiagnosticOpts DriverMessage
DriverMessageOpts
opts) PsMessage
m
    DriverMissingHomeModules UnitId
uid [ModuleName]
missing BuildingCabalPackage
buildingCabalPackage
      -> let msg :: SDoc
msg | BuildingCabalPackage
buildingCabalPackage BuildingCabalPackage -> BuildingCabalPackage -> Bool
forall a. Eq a => a -> a -> Bool
== BuildingCabalPackage
YesBuildingCabalPackage
                 = SDoc -> Int -> SDoc -> SDoc
hang
                     (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"These modules are needed for compilation but not listed in your .cabal file's other-modules for" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (UnitId -> SDoc
forall a. Outputable a => a -> SDoc
ppr UnitId
uid) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
":")
                     Int
4
                     ([SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
sep ((ModuleName -> SDoc) -> [ModuleName] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr [ModuleName]
missing))
                 | Bool
otherwise
                 =
                   SDoc -> Int -> SDoc -> SDoc
hang
                     (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Modules are not listed in options for"
                        SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (UnitId -> SDoc
forall a. Outputable a => a -> SDoc
ppr UnitId
uid) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"but needed for compilation:")
                     Int
4
                     ([SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
sep ((ModuleName -> SDoc) -> [ModuleName] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr [ModuleName]
missing))
         in SDoc -> DecoratedSDoc
mkSimpleDecorated SDoc
msg
    DriverUnknownHiddenModules UnitId
uid [ModuleName]
missing
      -> let msg :: SDoc
msg = SDoc -> Int -> SDoc -> SDoc
hang
                     (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Modules are listed as hidden in options for" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (UnitId -> SDoc
forall a. Outputable a => a -> SDoc
ppr UnitId
uid) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"but not part of the unit:")
                     Int
4
                     ([SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
sep ((ModuleName -> SDoc) -> [ModuleName] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr [ModuleName]
missing))
         in SDoc -> DecoratedSDoc
mkSimpleDecorated SDoc
msg
    DriverUnknownReexportedModules UnitId
uid [ReexportedModule]
missing
      -> let msg :: SDoc
msg = SDoc -> Int -> SDoc -> SDoc
hang
                     (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Modules are listed as reexported in options for" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (UnitId -> SDoc
forall a. Outputable a => a -> SDoc
ppr UnitId
uid) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"but can't be found in any dependency:")
                     Int
4
                     ([SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
sep ((ReexportedModule -> SDoc) -> [ReexportedModule] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map ReexportedModule -> SDoc
forall a. Outputable a => a -> SDoc
ppr [ReexportedModule]
missing))
         in SDoc -> DecoratedSDoc
mkSimpleDecorated SDoc
msg
    DriverUnusedPackages [(UnitId, PackageName, Version, PackageArg)]
unusedArgs
      -> let msg :: SDoc
msg = [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"The following packages were specified" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+>
                          String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"via -package or -package-id flags,"
                        , String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"but were not needed for compilation:"
                        , Int -> SDoc -> SDoc
nest Int
2 ([SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat (((UnitId, PackageName, Version, PackageArg) -> SDoc)
-> [(UnitId, PackageName, Version, PackageArg)] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (SDoc -> SDoc
withDash (SDoc -> SDoc)
-> ((UnitId, PackageName, Version, PackageArg) -> SDoc)
-> (UnitId, PackageName, Version, PackageArg)
-> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UnitId, PackageName, Version, PackageArg) -> SDoc
forall {a} {a}. Outputable a => (a, a, Version, PackageArg) -> SDoc
displayOneUnused) [(UnitId, PackageName, Version, PackageArg)]
unusedArgs))
                        ]
         in SDoc -> DecoratedSDoc
mkSimpleDecorated SDoc
msg
         where
            withDash :: SDoc -> SDoc
            withDash :: SDoc -> SDoc
withDash = SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
(<+>) (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"-")

            displayOneUnused :: (a, a, Version, PackageArg) -> SDoc
displayOneUnused (a
_uid, a
pn , Version
v, PackageArg
f) =
              a -> SDoc
forall a. Outputable a => a -> SDoc
ppr a
pn SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"-"  SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> String -> SDoc
forall doc. IsLine doc => String -> doc
text (Version -> String
showVersion Version
v)
                     SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
parens (PackageArg -> SDoc
suffix PackageArg
f)

            suffix :: PackageArg -> SDoc
suffix PackageArg
f = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"exposed by flag" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> PackageArg -> SDoc
pprUnusedArg PackageArg
f

            pprUnusedArg :: PackageArg -> SDoc
            pprUnusedArg :: PackageArg -> SDoc
pprUnusedArg (PackageArg String
str) = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"-package" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
str
            pprUnusedArg (UnitIdArg Unit
uid) = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"-package-id" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Unit -> SDoc
forall a. Outputable a => a -> SDoc
ppr Unit
uid

    DriverUnnecessarySourceImports ModuleName
mod
      -> SDoc -> DecoratedSDoc
mkSimpleDecorated (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"{-# SOURCE #-} unnecessary in import of " SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr ModuleName
mod))
    DriverDuplicatedModuleDeclaration Module
mod [String]
files
      -> SDoc -> DecoratedSDoc
mkSimpleDecorated (SDoc -> DecoratedSDoc) -> SDoc -> DecoratedSDoc
forall a b. (a -> b) -> a -> b
$
           String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"module" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr Module
mod) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+>
           String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"is defined in multiple files:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+>
           [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
sep ((String -> SDoc) -> [String] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map String -> SDoc
forall doc. IsLine doc => String -> doc
text [String]
files)
    DriverModuleNotFound ModuleName
mod
      -> SDoc -> DecoratedSDoc
mkSimpleDecorated (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"module" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr ModuleName
mod) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"cannot be found locally")
    DriverFileModuleNameMismatch ModuleName
actual ModuleName
expected
      -> SDoc -> DecoratedSDoc
mkSimpleDecorated (SDoc -> DecoratedSDoc) -> SDoc -> DecoratedSDoc
forall a b. (a -> b) -> a -> b
$
           String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"File name does not match module name:"
           SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Saw     :" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr ModuleName
actual)
           SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Expected:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr ModuleName
expected)

    DriverUnexpectedSignature ModuleName
pi_mod_name BuildingCabalPackage
_buildingCabalPackage GenInstantiations UnitId
_instantiations
      -> SDoc -> DecoratedSDoc
mkSimpleDecorated (SDoc -> DecoratedSDoc) -> SDoc -> DecoratedSDoc
forall a b. (a -> b) -> a -> b
$ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Unexpected signature:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr ModuleName
pi_mod_name)
    DriverFileNotFound String
hsFilePath
      -> SDoc -> DecoratedSDoc
mkSimpleDecorated (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Can't find" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
hsFilePath)
    DriverMessage
DriverStaticPointersNotSupported
      -> SDoc -> DecoratedSDoc
mkSimpleDecorated (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"StaticPointers is not supported in GHCi interactive expressions.")
    DriverBackpackModuleNotFound ModuleName
modname
      -> SDoc -> DecoratedSDoc
mkSimpleDecorated (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"module" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr ModuleName
modname SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"was not found")
    DriverUserDefinedRuleIgnored (HsRule { rd_name :: forall pass. RuleDecl pass -> XRec pass FastString
rd_name = XRec GhcTc FastString
n })
      -> SDoc -> DecoratedSDoc
mkSimpleDecorated (SDoc -> DecoratedSDoc) -> SDoc -> DecoratedSDoc
forall a b. (a -> b) -> a -> b
$
            String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Rule \"" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> FastString -> SDoc
forall doc. IsLine doc => FastString -> doc
ftext (GenLocated EpAnnCO FastString -> FastString
forall l e. GenLocated l e -> e
unLoc XRec GhcTc FastString
GenLocated EpAnnCO FastString
n) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"\" ignored" SDoc -> SDoc -> SDoc
$+$
            String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Defining user rules is disabled under Safe Haskell"
    DriverMixedSafetyImport ModuleName
modName
      -> SDoc -> DecoratedSDoc
mkSimpleDecorated (SDoc -> DecoratedSDoc) -> SDoc -> DecoratedSDoc
forall a b. (a -> b) -> a -> b
$
           String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Module" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr ModuleName
modName SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text (String
"is imported both as a safe and unsafe import!")
    DriverCannotLoadInterfaceFile Module
m
      -> SDoc -> DecoratedSDoc
mkSimpleDecorated (SDoc -> DecoratedSDoc) -> SDoc -> DecoratedSDoc
forall a b. (a -> b) -> a -> b
$
           String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Can't load the interface file for" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr Module
m
           SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
", to check that it can be safely imported"
    DriverInferredSafeModule Module
m
      -> SDoc -> DecoratedSDoc
mkSimpleDecorated (SDoc -> DecoratedSDoc) -> SDoc -> DecoratedSDoc
forall a b. (a -> b) -> a -> b
$
           SDoc -> SDoc
quotes (ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr (ModuleName -> SDoc) -> ModuleName -> SDoc
forall a b. (a -> b) -> a -> b
$ Module -> ModuleName
forall unit. GenModule unit -> ModuleName
moduleName Module
m) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"has been inferred as safe!"
    DriverInferredSafeImport Module
m
      -> SDoc -> DecoratedSDoc
mkSimpleDecorated (SDoc -> DecoratedSDoc) -> SDoc -> DecoratedSDoc
forall a b. (a -> b) -> a -> b
$
           [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
sep
             [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Importing Safe-Inferred module "
                 SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr (Module -> ModuleName
forall unit. GenModule unit -> ModuleName
moduleName Module
m)
                 SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
" from explicitly Safe module"
             ]
    DriverMarkedTrustworthyButInferredSafe Module
m
      -> SDoc -> DecoratedSDoc
mkSimpleDecorated (SDoc -> DecoratedSDoc) -> SDoc -> DecoratedSDoc
forall a b. (a -> b) -> a -> b
$
           SDoc -> SDoc
quotes (ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr (ModuleName -> SDoc) -> ModuleName -> SDoc
forall a b. (a -> b) -> a -> b
$ Module -> ModuleName
forall unit. GenModule unit -> ModuleName
moduleName Module
m) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"is marked as Trustworthy but has been inferred as safe!"
    DriverCannotImportUnsafeModule Module
m
      -> SDoc -> DecoratedSDoc
mkSimpleDecorated (SDoc -> DecoratedSDoc) -> SDoc -> DecoratedSDoc
forall a b. (a -> b) -> a -> b
$
           [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
sep [ ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr (Module -> ModuleName
forall unit. GenModule unit -> ModuleName
moduleName Module
m)
                   SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
": Can't be safely imported!"
               , String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"The module itself isn't safe." ]
    DriverMissingSafeHaskellMode Module
modName
      -> SDoc -> DecoratedSDoc
mkSimpleDecorated (SDoc -> DecoratedSDoc) -> SDoc -> DecoratedSDoc
forall a b. (a -> b) -> a -> b
$
           Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr Module
modName SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"is missing Safe Haskell mode"
    DriverPackageNotTrusted UnitState
state UnitId
pkg
      -> SDoc -> DecoratedSDoc
mkSimpleDecorated (SDoc -> DecoratedSDoc) -> SDoc -> DecoratedSDoc
forall a b. (a -> b) -> a -> b
$
           UnitState -> SDoc -> SDoc
pprWithUnitState UnitState
state
             (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"The package ("
                SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> UnitId -> SDoc
forall a. Outputable a => a -> SDoc
ppr UnitId
pkg
                SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
") is required to be trusted but it isn't!"
    DriverCannotImportFromUntrustedPackage UnitState
state Module
m
      -> SDoc -> DecoratedSDoc
mkSimpleDecorated (SDoc -> DecoratedSDoc) -> SDoc -> DecoratedSDoc
forall a b. (a -> b) -> a -> b
$
           [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
sep [ ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr (Module -> ModuleName
forall unit. GenModule unit -> ModuleName
moduleName Module
m)
                   SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
": Can't be safely imported!"
               , String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"The package ("
                   SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> (UnitState -> SDoc -> SDoc
pprWithUnitState UnitState
state (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$ Unit -> SDoc
forall a. Outputable a => a -> SDoc
ppr (Module -> Unit
forall unit. GenModule unit -> unit
moduleUnit Module
m))
                   SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
") the module resides in isn't trusted."
               ]
    DriverRedirectedNoMain ModuleName
mod_name
      -> SDoc -> DecoratedSDoc
mkSimpleDecorated (SDoc -> DecoratedSDoc) -> SDoc -> DecoratedSDoc
forall a b. (a -> b) -> a -> b
$ (String -> SDoc
forall doc. IsLine doc => String -> doc
text
                       (String
"Output was redirected with -o, " String -> String -> String
forall a. [a] -> [a] -> [a]
++
                       String
"but no output will be generated.") SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$
                       (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"There is no module named" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+>
                       SDoc -> SDoc
quotes (ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr ModuleName
mod_name) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"."))
    DriverHomePackagesNotClosed [UnitId]
needed_unit_ids
      -> SDoc -> DecoratedSDoc
mkSimpleDecorated (SDoc -> DecoratedSDoc) -> SDoc -> DecoratedSDoc
forall a b. (a -> b) -> a -> b
$ [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat ([String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Home units are not closed."
                                  , String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"It is necessary to also load the following units:" ]
                                  [SDoc] -> [SDoc] -> [SDoc]
forall a. [a] -> [a] -> [a]
++ (UnitId -> SDoc) -> [UnitId] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (\UnitId
uid -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"-" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> UnitId -> SDoc
forall a. Outputable a => a -> SDoc
ppr UnitId
uid) [UnitId]
needed_unit_ids)
    DriverInterfaceError IfaceMessage
reason -> DiagnosticOpts IfaceMessage -> IfaceMessage -> DecoratedSDoc
forall a. Diagnostic a => DiagnosticOpts a -> a -> DecoratedSDoc
diagnosticMessage (DriverMessageOpts -> DiagnosticOpts IfaceMessage
ifaceDiagnosticOpts DiagnosticOpts DriverMessage
DriverMessageOpts
opts) IfaceMessage
reason

    DriverInconsistentDynFlags String
msg
      -> SDoc -> DecoratedSDoc
mkSimpleDecorated (SDoc -> DecoratedSDoc) -> SDoc -> DecoratedSDoc
forall a b. (a -> b) -> a -> b
$ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
msg
    DriverSafeHaskellIgnoredExtension Extension
ext
      -> let arg :: SDoc
arg = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"-X" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> Extension -> SDoc
forall a. Outputable a => a -> SDoc
ppr Extension
ext
         in SDoc -> DecoratedSDoc
mkSimpleDecorated (SDoc -> DecoratedSDoc) -> SDoc -> DecoratedSDoc
forall a b. (a -> b) -> a -> b
$ SDoc
arg SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"is not allowed in Safe Haskell; ignoring" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
arg
    DriverMessage
DriverPackageTrustIgnored
      -> SDoc -> DecoratedSDoc
mkSimpleDecorated (SDoc -> DecoratedSDoc) -> SDoc -> DecoratedSDoc
forall a b. (a -> b) -> a -> b
$ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"-fpackage-trust ignored; must be specified with a Safe Haskell flag"

    DriverUnrecognisedFlag String
arg
      -> SDoc -> DecoratedSDoc
mkSimpleDecorated (SDoc -> DecoratedSDoc) -> SDoc -> DecoratedSDoc
forall a b. (a -> b) -> a -> b
$ String -> SDoc
forall doc. IsLine doc => String -> doc
text (String -> SDoc) -> String -> SDoc
forall a b. (a -> b) -> a -> b
$ String
"unrecognised warning flag: -" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
arg
    DriverDeprecatedFlag String
arg String
msg
      -> SDoc -> DecoratedSDoc
mkSimpleDecorated (SDoc -> DecoratedSDoc) -> SDoc -> DecoratedSDoc
forall a b. (a -> b) -> a -> b
$ String -> SDoc
forall doc. IsLine doc => String -> doc
text (String -> SDoc) -> String -> SDoc
forall a b. (a -> b) -> a -> b
$ String
arg String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" is deprecated: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
msg
    DriverModuleGraphCycle [ModuleGraphNode]
path
      -> SDoc -> DecoratedSDoc
mkSimpleDecorated (SDoc -> DecoratedSDoc) -> SDoc -> DecoratedSDoc
forall a b. (a -> b) -> a -> b
$ [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat
        [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Module graph contains a cycle:"
        , Int -> SDoc -> SDoc
nest Int
2 ([ModuleGraphNode] -> SDoc
show_path [ModuleGraphNode]
path) ]
      where
        show_path :: [ModuleGraphNode] -> SDoc
        show_path :: [ModuleGraphNode] -> SDoc
show_path []  = String -> SDoc
forall a. HasCallStack => String -> a
panic String
"show_path"
        show_path [ModuleGraphNode
m] = ModuleGraphNode -> SDoc
ppr_node ModuleGraphNode
m SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"imports itself"
        show_path (ModuleGraphNode
m1:ModuleGraphNode
m2:[ModuleGraphNode]
ms) = [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat ( Int -> SDoc -> SDoc
nest Int
14 (ModuleGraphNode -> SDoc
ppr_node ModuleGraphNode
m1)
                                    SDoc -> [SDoc] -> [SDoc]
forall a. a -> [a] -> [a]
: Int -> SDoc -> SDoc
nest Int
6 (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"imports" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> ModuleGraphNode -> SDoc
ppr_node ModuleGraphNode
m2)
                                    SDoc -> [SDoc] -> [SDoc]
forall a. a -> [a] -> [a]
: [ModuleGraphNode] -> [SDoc]
go [ModuleGraphNode]
ms )
           where
             go :: [ModuleGraphNode] -> [SDoc]
go []     = [String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"which imports" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> ModuleGraphNode -> SDoc
ppr_node ModuleGraphNode
m1]
             go (ModuleGraphNode
m:[ModuleGraphNode]
ms) = (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"which imports" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> ModuleGraphNode -> SDoc
ppr_node ModuleGraphNode
m) SDoc -> [SDoc] -> [SDoc]
forall a. a -> [a] -> [a]
: [ModuleGraphNode] -> [SDoc]
go [ModuleGraphNode]
ms

        ppr_node :: ModuleGraphNode -> SDoc
        ppr_node :: ModuleGraphNode -> SDoc
ppr_node (ModuleNode [NodeKey]
_deps ModSummary
m) = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"module" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> ModSummary -> SDoc
ppr_ms ModSummary
m
        ppr_node (InstantiationNode UnitId
_uid InstantiatedUnit
u) = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"instantiated unit" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> InstantiatedUnit -> SDoc
forall a. Outputable a => a -> SDoc
ppr InstantiatedUnit
u
        ppr_node (LinkNode [NodeKey]
uid UnitId
_) = String -> SDoc -> SDoc
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"LinkNode should not be in a cycle" ([NodeKey] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [NodeKey]
uid)

        ppr_ms :: ModSummary -> SDoc
        ppr_ms :: ModSummary -> SDoc
ppr_ms ModSummary
ms = SDoc -> SDoc
quotes (ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr (Module -> ModuleName
forall unit. GenModule unit -> ModuleName
moduleName (ModSummary -> Module
ms_mod ModSummary
ms))) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+>
                    (SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
parens (String -> SDoc
forall doc. IsLine doc => String -> doc
text (ModSummary -> String
msHsFilePath ModSummary
ms)))
    DriverInstantiationNodeInDependencyGeneration InstantiatedUnit
node ->
      SDoc -> DecoratedSDoc
mkSimpleDecorated (SDoc -> DecoratedSDoc) -> SDoc -> DecoratedSDoc
forall a b. (a -> b) -> a -> b
$
        [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Unexpected backpack instantiation in dependency graph while constructing Makefile:"
             , Int -> SDoc -> SDoc
nest Int
2 (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$ InstantiatedUnit -> SDoc
forall a. Outputable a => a -> SDoc
ppr InstantiatedUnit
node ]
    DriverMessage
DriverNoConfiguredLLVMToolchain ->
      SDoc -> DecoratedSDoc
mkSimpleDecorated (SDoc -> DecoratedSDoc) -> SDoc -> DecoratedSDoc
forall a b. (a -> b) -> a -> b
$
        String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"GHC was not configured with a supported LLVM toolchain" SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$
          String -> SDoc
forall doc. IsLine doc => String -> doc
text (String
"Make sure you have installed LLVM between ["
            String -> String -> String
forall a. [a] -> [a] -> [a]
++ LlvmVersion -> String
llvmVersionStr LlvmVersion
supportedLlvmVersionLowerBound
            String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" and "
            String -> String -> String
forall a. [a] -> [a] -> [a]
++ LlvmVersion -> String
llvmVersionStr LlvmVersion
supportedLlvmVersionUpperBound
            String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
") and reinstall GHC to make -fllvm work")

  diagnosticReason :: DriverMessage -> DiagnosticReason
diagnosticReason = \case
    DriverUnknownMessage UnknownDiagnostic (DiagnosticOpts DriverMessage)
m
      -> UnknownDiagnostic DriverMessageOpts -> DiagnosticReason
forall a. Diagnostic a => a -> DiagnosticReason
diagnosticReason UnknownDiagnostic (DiagnosticOpts DriverMessage)
UnknownDiagnostic DriverMessageOpts
m
    DriverPsHeaderMessage {}
      -> DiagnosticReason
ErrorWithoutFlag
    DriverMissingHomeModules{}
      -> WarningFlag -> DiagnosticReason
WarningWithFlag WarningFlag
Opt_WarnMissingHomeModules
    DriverUnknownHiddenModules {}
      -> DiagnosticReason
ErrorWithoutFlag
    DriverUnknownReexportedModules {}
      -> DiagnosticReason
ErrorWithoutFlag
    DriverUnusedPackages{}
      -> WarningFlag -> DiagnosticReason
WarningWithFlag WarningFlag
Opt_WarnUnusedPackages
    DriverUnnecessarySourceImports{}
      -> WarningFlag -> DiagnosticReason
WarningWithFlag WarningFlag
Opt_WarnUnusedImports
    DriverDuplicatedModuleDeclaration{}
      -> DiagnosticReason
ErrorWithoutFlag
    DriverModuleNotFound{}
      -> DiagnosticReason
ErrorWithoutFlag
    DriverFileModuleNameMismatch{}
      -> DiagnosticReason
ErrorWithoutFlag
    DriverUnexpectedSignature{}
      -> DiagnosticReason
ErrorWithoutFlag
    DriverFileNotFound{}
      -> DiagnosticReason
ErrorWithoutFlag
    DriverMessage
DriverStaticPointersNotSupported
      -> DiagnosticReason
WarningWithoutFlag
    DriverBackpackModuleNotFound{}
      -> DiagnosticReason
ErrorWithoutFlag
    DriverUserDefinedRuleIgnored{}
      -> DiagnosticReason
WarningWithoutFlag
    DriverMixedSafetyImport{}
      -> DiagnosticReason
ErrorWithoutFlag
    DriverCannotLoadInterfaceFile{}
      -> DiagnosticReason
ErrorWithoutFlag
    DriverInferredSafeModule{}
      -> WarningFlag -> DiagnosticReason
WarningWithFlag WarningFlag
Opt_WarnSafe
    DriverMarkedTrustworthyButInferredSafe{}
      ->WarningFlag -> DiagnosticReason
WarningWithFlag WarningFlag
Opt_WarnTrustworthySafe
    DriverInferredSafeImport{}
      -> WarningFlag -> DiagnosticReason
WarningWithFlag WarningFlag
Opt_WarnInferredSafeImports
    DriverCannotImportUnsafeModule{}
      -> DiagnosticReason
ErrorWithoutFlag
    DriverMissingSafeHaskellMode{}
      -> WarningFlag -> DiagnosticReason
WarningWithFlag WarningFlag
Opt_WarnMissingSafeHaskellMode
    DriverPackageNotTrusted{}
      -> DiagnosticReason
ErrorWithoutFlag
    DriverCannotImportFromUntrustedPackage{}
      -> DiagnosticReason
ErrorWithoutFlag
    DriverRedirectedNoMain {}
      -> DiagnosticReason
ErrorWithoutFlag
    DriverHomePackagesNotClosed {}
      -> DiagnosticReason
ErrorWithoutFlag
    DriverInterfaceError IfaceMessage
reason -> IfaceMessage -> DiagnosticReason
forall a. Diagnostic a => a -> DiagnosticReason
diagnosticReason IfaceMessage
reason
    DriverInconsistentDynFlags {}
      -> WarningFlag -> DiagnosticReason
WarningWithFlag WarningFlag
Opt_WarnInconsistentFlags
    DriverSafeHaskellIgnoredExtension {}
      -> DiagnosticReason
WarningWithoutFlag
    DriverPackageTrustIgnored {}
      -> DiagnosticReason
WarningWithoutFlag
    DriverUnrecognisedFlag {}
      -> WarningFlag -> DiagnosticReason
WarningWithFlag WarningFlag
Opt_WarnUnrecognisedWarningFlags
    DriverDeprecatedFlag {}
      -> WarningFlag -> DiagnosticReason
WarningWithFlag WarningFlag
Opt_WarnDeprecatedFlags
    DriverModuleGraphCycle {}
      -> DiagnosticReason
ErrorWithoutFlag
    DriverInstantiationNodeInDependencyGeneration {}
      -> DiagnosticReason
ErrorWithoutFlag
    DriverMessage
DriverNoConfiguredLLVMToolchain
      -> DiagnosticReason
ErrorWithoutFlag

  diagnosticHints :: DriverMessage -> [GhcHint]
diagnosticHints = \case
    DriverUnknownMessage UnknownDiagnostic (DiagnosticOpts DriverMessage)
m
      -> UnknownDiagnostic DriverMessageOpts -> [GhcHint]
forall a. Diagnostic a => a -> [GhcHint]
diagnosticHints UnknownDiagnostic (DiagnosticOpts DriverMessage)
UnknownDiagnostic DriverMessageOpts
m
    DriverPsHeaderMessage PsMessage
psMsg
      -> PsMessage -> [GhcHint]
forall a. Diagnostic a => a -> [GhcHint]
diagnosticHints PsMessage
psMsg
    DriverMissingHomeModules{}
      -> [GhcHint]
noHints
    DriverUnknownHiddenModules {}
      -> [GhcHint]
noHints
    DriverUnknownReexportedModules {}
      -> [GhcHint]
noHints
    DriverUnusedPackages{}
      -> [GhcHint]
noHints
    DriverUnnecessarySourceImports{}
      -> [GhcHint]
noHints
    DriverDuplicatedModuleDeclaration{}
      -> [GhcHint]
noHints
    DriverModuleNotFound{}
      -> [GhcHint]
noHints
    DriverFileModuleNameMismatch{}
      -> [GhcHint]
noHints
    DriverUnexpectedSignature ModuleName
pi_mod_name BuildingCabalPackage
buildingCabalPackage GenInstantiations UnitId
instantiations
      -> if BuildingCabalPackage
buildingCabalPackage BuildingCabalPackage -> BuildingCabalPackage -> Bool
forall a. Eq a => a -> a -> Bool
== BuildingCabalPackage
YesBuildingCabalPackage
           then [ModuleName -> GhcHint
SuggestAddSignatureCabalFile ModuleName
pi_mod_name]
           else [ModuleName -> [InstantiationSuggestion] -> GhcHint
SuggestSignatureInstantiations ModuleName
pi_mod_name (ModuleName -> GenInstantiations UnitId -> [InstantiationSuggestion]
suggestInstantiatedWith ModuleName
pi_mod_name GenInstantiations UnitId
instantiations)]
    DriverFileNotFound{}
      -> [GhcHint]
noHints
    DriverMessage
DriverStaticPointersNotSupported
      -> [GhcHint]
noHints
    DriverBackpackModuleNotFound{}
      -> [GhcHint]
noHints
    DriverUserDefinedRuleIgnored{}
      -> [GhcHint]
noHints
    DriverMixedSafetyImport{}
      -> [GhcHint]
noHints
    DriverCannotLoadInterfaceFile{}
      -> [GhcHint]
noHints
    DriverInferredSafeModule{}
      -> [GhcHint]
noHints
    DriverInferredSafeImport{}
      -> [GhcHint]
noHints
    DriverCannotImportUnsafeModule{}
      -> [GhcHint]
noHints
    DriverMissingSafeHaskellMode{}
      -> [GhcHint]
noHints
    DriverPackageNotTrusted{}
      -> [GhcHint]
noHints
    DriverMarkedTrustworthyButInferredSafe{}
      -> [GhcHint]
noHints
    DriverCannotImportFromUntrustedPackage{}
      -> [GhcHint]
noHints
    DriverRedirectedNoMain {}
      -> [GhcHint]
noHints
    DriverHomePackagesNotClosed {}
      -> [GhcHint]
noHints
    DriverInterfaceError IfaceMessage
reason -> IfaceMessage -> [GhcHint]
forall a. Diagnostic a => a -> [GhcHint]
diagnosticHints IfaceMessage
reason
    DriverInconsistentDynFlags {}
      -> [GhcHint]
noHints
    DriverSafeHaskellIgnoredExtension {}
      -> [GhcHint]
noHints
    DriverPackageTrustIgnored {}
      -> [GhcHint]
noHints
    DriverUnrecognisedFlag {}
      -> [GhcHint]
noHints
    DriverDeprecatedFlag {}
      -> [GhcHint]
noHints
    DriverModuleGraphCycle {}
      -> [GhcHint]
noHints
    DriverInstantiationNodeInDependencyGeneration {}
      -> [GhcHint]
noHints
    DriverMessage
DriverNoConfiguredLLVMToolchain
      -> [GhcHint]
noHints

  diagnosticCode :: DriverMessage -> Maybe DiagnosticCode
diagnosticCode = DriverMessage -> Maybe DiagnosticCode
forall diag.
(Generic diag, GDiagnosticCode (Rep diag)) =>
diag -> Maybe DiagnosticCode
constructorCode