From 7d18e1bace3f3a85eae177654690d91b688c0e8f Mon Sep 17 00:00:00 2001 From: Alfredo Di Napoli Date: Tue, 6 Apr 2021 16:27:14 +0200 Subject: Add GhcMessage and ancillary types This commit adds GhcMessage and ancillary (PsMessage, TcRnMessage, ..) types. These types will be expanded to represent more errors generated by different subsystems within GHC. Right now, they are underused, but more will come in the glorious future. See https://gitlab.haskell.org/ghc/ghc/-/wikis/Errors-as-(structured)-values for a design overview. Along the way, lots of other things had to happen: * Adds Semigroup and Monoid instance for Bag * Fixes #19746 by parsing OPTIONS_GHC pragmas into Located Strings. See GHC.Parser.Header.toArgs (moved from GHC.Utils.Misc, where it didn't belong anyway). * Addresses (but does not completely fix) #19709, now reporting desugarer warnings and errors appropriately for TH splices. Not done: reporting type-checker warnings for TH splices. * Some small refactoring around Safe Haskell inference, in order to keep separate classes of messages separate. * Some small refactoring around initDsTc, in order to keep separate classes of messages separate. * Separate out the generation of messages (that is, the construction of the text block) from the wrapping of messages (that is, assigning a SrcSpan). This is more modular than the previous design, which mixed the two. Close #19746. This was a collaborative effort by Alfredo di Napoli and Richard Eisenberg, with a key assist on #19746 by Iavor Diatchki. Metric Increase: MultiLayerModules --- compiler/GHC/Tc/Errors/Ppr.hs | 10 ++++++++++ compiler/GHC/Tc/Errors/Types.hs | 12 ++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 compiler/GHC/Tc/Errors/Ppr.hs create mode 100644 compiler/GHC/Tc/Errors/Types.hs (limited to 'compiler/GHC/Tc/Errors') diff --git a/compiler/GHC/Tc/Errors/Ppr.hs b/compiler/GHC/Tc/Errors/Ppr.hs new file mode 100644 index 0000000000..c6da9f1b9b --- /dev/null +++ b/compiler/GHC/Tc/Errors/Ppr.hs @@ -0,0 +1,10 @@ +{-# OPTIONS_GHC -fno-warn-orphans #-} -- instance Diagnostic TcRnMessage + +module GHC.Tc.Errors.Ppr where + +import GHC.Tc.Errors.Types +import GHC.Types.Error + +instance Diagnostic TcRnMessage where + diagnosticMessage (TcRnUnknownMessage m) = diagnosticMessage m + diagnosticReason (TcRnUnknownMessage m) = diagnosticReason m diff --git a/compiler/GHC/Tc/Errors/Types.hs b/compiler/GHC/Tc/Errors/Types.hs new file mode 100644 index 0000000000..1241735191 --- /dev/null +++ b/compiler/GHC/Tc/Errors/Types.hs @@ -0,0 +1,12 @@ +module GHC.Tc.Errors.Types ( + -- * Main types + TcRnMessage(..) + ) where + +import GHC.Types.Error + +-- | An error which might arise during typechecking/renaming. +data TcRnMessage + = TcRnUnknownMessage !DiagnosticMessage + -- ^ Simply rewraps a generic 'DiagnosticMessage'. More + -- constructors will be added in the future (#18516). -- cgit v1.2.1