Convert diagnostics in `GHC.Iface.Rename` to proper `TcRnMessage`
Short Summary: Get rid of the usage of TcRnUnknownMessage
in GHC.Iface.Rename
. Do so by creating new type constructors for the TcRnMessage
type, specific to the errors you are converting. Modify failWithRn
to take a TcRnMessage
as input.
Inside Ghc.Iface.Rename
we count one occurrence of TcRnUnknownMessage
, inside failWithRn
. This function has type
failWithRn :: SDoc -> ShIfM a
, because it internally simply wraps the input SDoc
into the TcRnUnknownMessage
we want to remove. What we want to do is to change the type signature of failWithRn
to be failWithRn :: TcRnMessage -> ShIfM a
and
now change its invocations in rnIfaceGlobal
so that we would be passing a proper TcRnMessage
instead of an SDoc
. To
do so, we will need to add two new type constructors to the TcRnMessage
type.
What follows is a possible plan of action, to guide the developer working on this:
-
Add two new type constructors to
GHC.Tc.Errors.Types.TcRnMessage
. If possible, try to document these following the schema used for the existing ones. -
This is a good time to
grep
the codebase for the text of the diagnostics, which should hopefully yield a number of test cases. You can later run the testsuite on those tests locally (e.g../hadrian/build test --only=...
), to verify the final output didn't change. Occasionally the final output might change, for example if new hints are added, but it shouldn't be the case for this ticket. -
GHC will now complain that the
instance Diagnostic TcRnMessage
insideGHC.Tc.Errors.Ppr
is not complete. ThediagnosticMessage
,diagnosticReason
anddiagnosticHints
will need to handle the new type constructors. -
Implement
diagnosticMessage
by copying the original textual representation of the diagnostic message from theGHC.Iface.Rename
. If the textual representation is using external data (i.e. local binds in theGHC.Iface.Rename
) add the necessary type arguments to the constructor to "carry the data over". Again, follow the existing patterns, but pay attention todiagnosticHints
(see below). -
Implement
diagnosticReason
by copying the originalDiagnosticReason
(s) from the originalGHC.Tc.Module
diagnostics. In this case both should be errors, i.e.diagnosticReason
should beErrorWithoutFlag
. -
Implementing
diagnosticHints
is slightly more complicated, because both existing messages emitted byfailWithRn
are bundling the hint ("Try adding it to the export list in that hsig file.") with thediagnosticMessage
. What needs to happen is that this hint should be outsourced into a new type constructor of theGHC.Types.Hint
type: it's possible once again to see the pattern used for existingGhcHint
constructors. Also, pretty-printing modules likeGHC.Parser.Errors.Ppr
have examples on how to actually emit hints (i.e. anything which is not a boringnoHints
).