Skip to content

Convert diagnostics in `GHC.Tc.Module` to proper `TcRnMessage`

See also #19905 and #18516.

Short Summary: Get rid of the usages of TcRnUnknownMessage in GHC.Tc.Module. Do so by creating new type constructors for the TcRnMessage type, specific to the errors you are converting.

Inside Ghc.Tc.Module we count 2 occurrences of TcRnUnknownMessage, one for the error message emitted as part of tcRnModule and one coming from mark_plugin_unsafe (which is a warning). We would like to replace these with two new type constructors to be added to the TcRnMessage type, which would give us a precise (and structured) semantic of the diagnostics in question.

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 inside GHC.Tc.Errors.Ppr is not complete. The diagnosticMessage, diagnosticReason and diagnosticHints will need to handle the new type constructors.

  • Implement diagnosticMessage by copying the original textual representation of the diagnostic message from the GHC.Tc.Module. If the textual representation is using external data (i.e. local binds in the GHC.Tc.Module) add the necessary type arguments to the constructor to "carry the data over". Again, follow the existing patterns.

  • Implement diagnosticReason by copying the original DiagnosticReason(s) from the original GHC.Tc.Module diagnostics.

  • Implement diagnosticHints by copying, once again, what the original diagnostic in GHC.Tc.Module is doing. In both cases, none of the diagnostics emitted hints, so noHints is enough here.

Edited by Alfredo Di Napoli
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information