diff options
author | Matthew Pickering <matthewtpickering@gmail.com> | 2023-03-14 17:34:30 +0000 |
---|---|---|
committer | GHC GitLab CI <ghc-ci@gitlab-haskell.org> | 2023-04-17 14:57:04 +0100 |
commit | ec9b7dd7b80b9637a84e60ce9425bfd223b4c379 (patch) | |
tree | 62e79864d016a6e5105e395ee19a2202d4892ce6 /compiler/GHC/Driver/Errors | |
parent | 1532a8b2b222fee73959a0760ac8867be7f19ce6 (diff) | |
download | haskell-wip/interface-loading-errs.tar.gz |
Convert interface file loading errors into proper diagnosticswip/interface-loading-errs
This patch converts all the errors to do with loading interface files
into proper structured diagnostics.
* DriverMessage: Sometimes in the driver we attempt to load an interface
file so we embed the IfaceMessage into the DriverMessage.
* TcRnMessage: Most the time we are loading interface files during
typechecking, so we embed the IfaceMessage
This patch also removes the TcRnInterfaceLookupError constructor which
is superceded by the IfaceMessage, which is now structured compared to
just storing an SDoc before.
Diffstat (limited to 'compiler/GHC/Driver/Errors')
-rw-r--r-- | compiler/GHC/Driver/Errors/Ppr.hs | 9 | ||||
-rw-r--r-- | compiler/GHC/Driver/Errors/Types.hs | 18 |
2 files changed, 15 insertions, 12 deletions
diff --git a/compiler/GHC/Driver/Errors/Ppr.hs b/compiler/GHC/Driver/Errors/Ppr.hs index 9e3822e460..a89e7992b1 100644 --- a/compiler/GHC/Driver/Errors/Ppr.hs +++ b/compiler/GHC/Driver/Errors/Ppr.hs @@ -16,7 +16,6 @@ import GHC.Driver.Flags import GHC.Driver.Session import GHC.HsToCore.Errors.Ppr () import GHC.Parser.Errors.Ppr () -import GHC.Tc.Errors.Ppr () import GHC.Types.Error import GHC.Types.Error.Codes ( constructorCode ) import GHC.Unit.Types @@ -30,6 +29,9 @@ 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 () +import GHC.Iface.Errors.Ppr () -- -- Suggestions @@ -86,7 +88,7 @@ instance Diagnostic GhcMessage where instance Diagnostic DriverMessage where type DiagnosticOpts DriverMessage = DriverMessageOpts - defaultDiagnosticOpts = DriverMessageOpts (defaultDiagnosticOpts @PsMessage) + defaultDiagnosticOpts = DriverMessageOpts (defaultDiagnosticOpts @PsMessage) (defaultDiagnosticOpts @IfaceMessage) diagnosticMessage opts = \case DriverUnknownMessage (UnknownDiagnostic @e m) -> diagnosticMessage (defaultDiagnosticOpts @e) m @@ -218,6 +220,7 @@ instance Diagnostic DriverMessage where -> mkSimpleDecorated $ vcat ([text "Home units are not closed." , text "It is necessary to also load the following units:" ] ++ map (\uid -> text "-" <+> ppr uid) needed_unit_ids) + DriverInterfaceError reason -> diagnosticMessage (ifaceDiagnosticOpts opts) reason diagnosticReason = \case DriverUnknownMessage m @@ -272,6 +275,7 @@ instance Diagnostic DriverMessage where -> ErrorWithoutFlag DriverHomePackagesNotClosed {} -> ErrorWithoutFlag + DriverInterfaceError reason -> diagnosticReason reason diagnosticHints = \case DriverUnknownMessage m @@ -328,5 +332,6 @@ instance Diagnostic DriverMessage where -> noHints DriverHomePackagesNotClosed {} -> noHints + DriverInterfaceError reason -> diagnosticHints reason diagnosticCode = constructorCode diff --git a/compiler/GHC/Driver/Errors/Types.hs b/compiler/GHC/Driver/Errors/Types.hs index c2ec9cbb0c..cbf0622025 100644 --- a/compiler/GHC/Driver/Errors/Types.hs +++ b/compiler/GHC/Driver/Errors/Types.hs @@ -8,7 +8,6 @@ module GHC.Driver.Errors.Types ( , DriverMessage(..) , DriverMessageOpts(..) , DriverMessages, PsMessage(PsHeaderMessage) - , BuildingCabalPackage(..) , WarningMessages , ErrorMessages , WarnMsg @@ -32,7 +31,6 @@ import GHC.Unit.Module import GHC.Unit.State import GHC.Parser.Errors.Types ( PsMessage(PsHeaderMessage) ) -import GHC.Tc.Errors.Types ( TcRnMessage ) import GHC.HsToCore.Errors.Types ( DsMessage ) import GHC.Hs.Extension (GhcTc) @@ -40,6 +38,9 @@ import Language.Haskell.Syntax.Decls (RuleDecl) import GHC.Generics ( Generic ) +import GHC.Tc.Errors.Types +import GHC.Iface.Errors.Types + -- | A collection of warning messages. -- /INVARIANT/: Each 'GhcMessage' in the collection should have 'SevWarning' severity. type WarningMessages = Messages GhcMessage @@ -369,21 +370,18 @@ data DriverMessage where DriverHomePackagesNotClosed :: ![UnitId] -> DriverMessage + DriverInterfaceError :: !IfaceMessage -> DriverMessage + deriving instance Generic DriverMessage data DriverMessageOpts = - DriverMessageOpts { psDiagnosticOpts :: DiagnosticOpts PsMessage } + DriverMessageOpts { psDiagnosticOpts :: DiagnosticOpts PsMessage + , ifaceDiagnosticOpts :: DiagnosticOpts IfaceMessage } --- | Pass to a 'DriverMessage' the information whether or not the --- '-fbuilding-cabal-package' flag is set. -data BuildingCabalPackage - = YesBuildingCabalPackage - | NoBuildingCabalPackage - deriving Eq -- | Checks if we are building a cabal package by consulting the 'DynFlags'. checkBuildingCabalPackage :: DynFlags -> BuildingCabalPackage checkBuildingCabalPackage dflags = if gopt Opt_BuildingCabalPackage dflags then YesBuildingCabalPackage - else NoBuildingCabalPackage + else NoBuildingCabalPackage
\ No newline at end of file |