Moduleghc-9.10.3GHC2021
GHC.Utils.Error
- 9 types
- 1 class
- 51 values
- Packageghc-9.10.3
- Exports61
- LanguageGHC2021
- LicenceBSD-3-Clause
- SourceError.hs
Basic types
6 declarationsMonomorphic version of Validity' specialised for SDocs.
If they aren't all valid, return the first
Used to describe warnings and errors o The message has a file/line/column heading, plus "warning:" or "error:", added by mkLocMessage o With SevIgnore the message is suppressed o Output is intended for end users
Constructors
SevIgnoreIgnore this message, for example in case of suppression of warnings users don't want to see. See Note [Suppressing Messages]
SevWarningSevError
Instances5Eq, Ord, Show, Outputable, ToJson
Messages
11 declarationsA class identifying a diagnostic. Dictionary.com defines a diagnostic as:
"a message output by a computer diagnosing an error in a computer program, computer system, or component device".
A Diagnostic carries the actual description of the message (which, in GHC's case, it can be an error or a warning) and the reason why such message was generated in the first place.
Associated types
type family DiagnosticOpts aType of configuration options for the diagnostic.
Methods
diagnosticMessage :: DiagnosticOpts a -> a -> DecoratedSDocExtract the error message text from a Diagnostic.
diagnosticReason :: a -> DiagnosticReasonExtract the reason for this diagnostic. For warnings, a DiagnosticReason includes the warning flag.
diagnosticHints :: a -> [GhcHint]Extract any hints a user might use to repair their code to avoid this diagnostic.
diagnosticCode :: a -> Maybe DiagnosticCodeGet the DiagnosticCode associated with this Diagnostic. This can return Nothing for at least two reasons:
The message might be from a plugin that does not supply codes.
The message might not yet have been assigned a code. See the Diagnostic instance for DiagnosticMessage.
Ideally, case (2) would not happen, but because some errors in GHC still use the old system of just writing the error message in-place (instead of using a dedicated error type and constructor), we do not have error codes for all errors. #18516 tracks our progress toward this goal.
Instances8Diagnostic, …
Diagnostic DriverMessageDefined in ghc-9.10.3 · GHC.Driver.Errors.Ppr · orphanDiagnostic GhcMessageDefined in ghc-9.10.3 · GHC.Driver.Errors.Ppr · orphanDiagnostic DsMessageDefined in ghc-9.10.3 · GHC.HsToCore.Errors.Ppr · orphanDiagnostic IfaceMessageDefined in ghc-9.10.3 · GHC.Iface.Errors.Ppr · orphanDiagnostic PsMessageDefined in ghc-9.10.3 · GHC.Parser.Errors.Ppr · orphanDiagnostic TcRnMessageDefined in ghc-9.10.3 · GHC.Tc.Errors.Ppr · orphanDiagnostic DiagnosticMessageDefined in ghc-9.10.3 · GHC.Types.ErrorHasDefaultDiagnosticOpts opts => Diagnostic (UnknownDiagnostic opts)Defined in ghc-9.10.3 · GHC.Types.Error
An envelope for GHC's facts about a running program, parameterised over the domain-specific (i.e. parsing, typecheck-renaming, etc) diagnostics.
To say things differently, GHC emits diagnostics about the running program, each of which is wrapped into a MsgEnvelope that carries specific information like where the error happened, etc. Finally, multiple MsgEnvelopes are aggregated into Messages that are returned to the user.
Constructors
MsgEnvelopeerrMsgSpan :: SrcSpanThe SrcSpan is used for sorting errors into line-number order
errMsgContext :: NamePprCtxerrMsgDiagnostic :: eerrMsgSeverity :: SeverityerrMsgReason :: ResolvedDiagnosticReasonThe actual reason caused this message
See Note [Warnings controlled by multiple flags]
Instances5Functor, Foldable, Traversable, Show, ToJson
Functor MsgEnvelopeDefined in ghc-9.10.3 · GHC.Types.ErrorFoldable MsgEnvelopeDefined in ghc-9.10.3 · GHC.Types.ErrorTraversable MsgEnvelopeDefined in ghc-9.10.3 · GHC.Types.ErrorShow (MsgEnvelope DiagnosticMessage)Defined in ghc-9.10.3 · GHC.Types.ErrorDiagnostic e => ToJson (MsgEnvelope e)Defined in ghc-9.10.3 · GHC.Types.Error
The class for a diagnostic message. The main purpose is to classify a message within GHC, to distinguish it from a debug/dump message vs a proper diagnostic, for which we include a DiagnosticReason.
Constructors
MCOutputMCFatalMCInteractiveMCDumpLog message intended for compiler developers No file/line/column stuff
MCInfoLog messages intended for end users. No file/line/column stuff.
MCDiagnostic Severity ResolvedDiagnosticReason (Maybe DiagnosticCode)Diagnostics from the compiler. This constructor is very powerful as it allows the construction of a MessageClass with a completely arbitrary permutation of Severity and DiagnosticReason. As such, users are encouraged to use the
mkMCDiagnosticsmart constructor instead. Use this constructor directly only if you need to construct and manipulate diagnostic messages directly, for example insideGHC.Utils.Error. In all the other circumstances, especially when emitting compiler diagnostics, use the smart constructor.The
Maybe DiagnosticCodefield carries a code (if available) for this diagnostic. If you are creating a message not tied to any error-message type, then use Nothing. In the long run, this really should always have a DiagnosticCode. See Note [Diagnostic codes].
Instances1ToJson
ToJson MessageClassDefined in ghc-9.10.3 · GHC.Types.Error
Represents a pretty-printable document.
To display an SDoc, use printSDoc, printSDocLn, bufLeftRenderSDoc, or renderWithContext. Avoid calling runSDoc directly as it breaks the abstraction layer.
Instances8IsString, Outputable, IsLine, IsDoc, IsOutput, JsRender, …
IsString SDocDefined in ghc-9.10.3 · GHC.Utils.OutputableOutputable SDocDefined in ghc-9.10.3 · GHC.Utils.OutputableIsLine SDocDefined in ghc-9.10.3 · GHC.Utils.OutputableIsDoc SDocDefined in ghc-9.10.3 · GHC.Utils.OutputableIsOutput SDocDefined in ghc-9.10.3 · GHC.Utils.OutputableJsRender SDocDefined in ghc-9.10.3 · GHC.JS.PprOutputableP env SDocDefined in ghc-9.10.3 · GHC.Utils.Outputabletype Line SDoc = SDocDefined in ghc-9.10.3 · GHC.Utils.Outputable
A DecoratedSDoc is isomorphic to a '[SDoc]' but it carries the
invariant that the input '[SDoc]' needs to be rendered decorated into its
final form, where the typical case would be adding bullets between each
elements of the list. The type of decoration depends on the formatting
function used, but in practice GHC uses the formatBulleted.
A collection of messages emitted by GHC during error reporting. A diagnostic message is typically a warning or an error. See Note [Messages].
INVARIANT: All the messages in this collection must be relevant, i.e. their Severity should not be SevIgnore. The smart constructor mkMessages will filter out any message which Severity is SevIgnore.
Instances7Functor, Foldable, Traversable, Semigroup, Monoid, Outputable, …
Functor MessagesDefined in ghc-9.10.3 · GHC.Types.ErrorFoldable MessagesDefined in ghc-9.10.3 · GHC.Types.ErrorTraversable MessagesDefined in ghc-9.10.3 · GHC.Types.ErrorSemigroup (Messages e)Defined in ghc-9.10.3 · GHC.Types.ErrorMonoid (Messages e)Defined in ghc-9.10.3 · GHC.Types.ErrorDiagnostic e => Outputable (Messages e)Defined in ghc-9.10.3 · GHC.Types.ErrorDiagnostic e => ToJson (Messages e)Defined in ghc-9.10.3 · GHC.Types.Error
Joins two collections of messages together. See Note [Discarding Messages].
Are there any hard errors here? -Werror warnings are not detected. If you want to check for -Werror warnings, use errorsOrFatalWarningsFound.
Formatting
Print the messages with the suitable default configuration, usually not what you want but sometimes you don't really care about what the configuration is (for example, if the message is in a panic).
Formats the input list of structured document, where each element of the list gets a bullet.
Construction
Constructors
DiagOptsdiag_warning_flags :: !EnumSet WarningFlagEnabled warnings
diag_fatal_warning_flags :: !EnumSet WarningFlagFatal warnings
diag_custom_warning_categories :: !WarningCategorySetEnabled custom warning categories
diag_fatal_custom_warning_categories :: !WarningCategorySetFatal custom warning categories
diag_warn_is_error :: !BoolTreat warnings as errors
diag_reverse_errors :: !BoolReverse error reporting order
diag_max_errors :: !Maybe IntMax reported error count
diag_ppr_ctx :: !SDocContextError printing context
Creates a new DecoratedSDoc out of a list of SDoc.
Wrap a Diagnostic in a MsgEnvelope, recording its location. If you know your Diagnostic is an error, consider using mkErrorMsgEnvelope, which does not require looking at the DiagOpts
Variant that doesn't care about qualified/unqualified names.
Variant of mkPlainMsgEnvelope which can be used when we are sure we are constructing a diagnostic with a ErrorWithoutFlag reason.
Wrap a Diagnostic in a MsgEnvelope, recording its location.
Precondition: the diagnostic is, in fact, an error. That is,
diagnosticReason msg == ErrorWithoutFlag.
Make a MessageClass for a given DiagnosticReason, consulting the DiagOpts.
Varation of mkMCDiagnostic which can be used when we are sure the input DiagnosticReason is ErrorWithoutFlag and there is no diagnostic code.
Computes the right Severity for the input DiagnosticReason out of
the 'DiagOpts. This function has to be called when a diagnostic is constructed,
i.e. with a 'DiagOpts "snapshot" taken as close as possible to where a
particular diagnostic message is built, otherwise the computed Severity might
not be correct, due to the mutable nature of the DynFlags in GHC.
Create an error DiagnosticMessage holding just a single SDoc
Create an error DiagnosticMessage from a list of bulleted SDocs
Create a DiagnosticMessage from a list of bulleted SDocs and a DiagnosticReason
Helper function to use when no hints can be provided. Currently this function can be used to construct plain DiagnosticMessage and add hints to them, but once #18516 will be fully executed, the main usage of this function would be in the implementation of the diagnosticHints typeclass method, to report the fact that a particular Diagnostic has no hints.
Utilities
1 declarationIssuing messages during compilation
17 declarationsLike logInfo but with SevOutput rather then SevInfo
withTiming Time a compilation phase.
When timings are enabled (e.g. with the -v2 flag), the allocations
and CPU time used by the phase will be reported to stderr. Consider
a typical usage:
withTiming getDynFlags (text "simplify") force PrintTimings pass.
When timings are enabled the following costs are included in the
produced accounting,
The cost of executing
passto a resultrin WHNFThe cost of evaluating
force rto WHNF (e.g.())
The choice of the force function depends upon the amount of forcing
desired; the goal here is to ensure that the cost of evaluating the result
is, to the greatest extent possible, included in the accounting provided by
withTiming. Often the pass already sufficiently forces its result during
construction; in this case const () is a reasonable choice.
In other cases, it is necessary to evaluate the result to normal form, in
which case something like Control.DeepSeq.rnf is appropriate.
To avoid adversely affecting compiler performance when timings are not requested, the result is only forced when timings are enabled.
See Note [withTiming] for more.
withTimingSilent Same as withTiming, but doesn't print timings in the
console (when given -vN, N >= 2 or -ddump-timings).
See Note [withTiming] for more.
Trace a command (when verbosity level >= 3)
Record in the eventlog when the given tool command starts and finishes, prepending the given String with "systool:", to easily be able to collect and process all the systool events.
For those events to show up in the eventlog, you need
to run GHC with -v2 or -ddump-timings.