Use diagnostic infrastructure in GHC.Tc.Errors
This MR changes GHC.Tc.Errors to use the diagnostic infrastructure instead of directly handling SDocs.
Currently, this is achieved as follows:
- introduce the
TcReportMsgdatatype (defined inGHC.Tc.Errors.Types), whose constructors correspond to the various different errors we would throw. (The constructors can still be improved, so please let me know how you would like me to change things.) - Define
TcReportInfo, which contains extra information that is attached to aReportMsg. Note that this is different from the supplementary info contained in aReport(now renamed toSolverReportand defined inGHC.Tc.Errors.Types), which is printed after the context info. See the documentation toSolverReport. - A new
TcRnMessageconstructor which stores the above messages,TcRnSolverReport. - A few smaller datatypes:
-
HoleErrorfor errors reported bymkHoleError, -
NotInScopeErrorfor various "not-in-scope" errors, -
CoercibleMsgfor some additional informative messages relating to representational equality, -
ValidHoleFitsto keep track of suggestions from the hole-fits mechanism, -
ImportSuggestionfor informational messages about whether names are available to be imported from, - ...
-
- A few other new
TcRnMessages:-
TcRnRedundantConstraints, -
TcRnInaccessibleCode, -
TcRnNotInScope, -
TcRnUntickedPromotedConstructor, -
TcRnIllegalBuiltinSyntax.
-
- A few new
GhcHints:-
SuggestDumpSplicesfor Template Haskell exact name errors, -
SugestAddTick, -
SuggestMoveToDeclarationSite, -
SuggestSimilarNames, - a slight modification to
SuggestUseTypeFromDataKindto accomodate other places which printed a similar message.
-
- Two sum types defined in
GHC.Tc.Types.Originto avoidSDocs,TypeEqThingandBinderThing(happy to take suggestions for renaming these, but I do genuinely think it's much better than havingSDocs).
TODOs:
-
Rebase on top of !6943 (closed) once that is merged. -
The "inaccessible code" message is missing some information, although I think it is also somewhat improved. See e.g. T7293. -
Some constructors of TcReportMsgare missing documentation, examples or relevant test cases. -
Some constructors of GhcHintare missing documentation. -
The "redundant constraints" message seems to be missing some constraints, see e.g. T20602. -
Figure out how to avoid the import cycle that lead me to create GHC.Tc.Errors.hs-bootand seems to have greatly increased the number of dependencies of the parser. -
Update the notes around StarIsTypeinGHC.Types.Name.Reader. -
Remove the use of TcRnUnknownMessageinGHC.Rename.HsType. It callswithHsDocContextwhich I wasn't immediately sure how to handle; happy to take suggestions. -
Remove SDocfromTcRnIllegalBuiltinSyntax. -
Remove SDocfromMissingBindingconstructor ofNotInScopeError. -
Remove SDocfromUnknownSubordinateconstructor ofNotInScopeError.
The above are concrete things that I have yet to address, but there is still a fair bit of iteration left to do on the design too, I think. Some of the code might look a bit strange because I'm contorting myself to avoid changing the existing error messages as much as possible. I think once this is in place we will be in a much better shape to refactor some of these errors in a robust way.
Happy to hear what you all think @rae @simonpj @adinapoli (and others).
Edited by sheaf