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
TcReportMsg
datatype (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 toSolverReport
and defined inGHC.Tc.Errors.Types
), which is printed after the context info. See the documentation toSolverReport
. - A new
TcRnMessage
constructor which stores the above messages,TcRnSolverReport
. - A few smaller datatypes:
-
HoleError
for errors reported bymkHoleError
, -
NotInScopeError
for various "not-in-scope" errors, -
CoercibleMsg
for some additional informative messages relating to representational equality, -
ValidHoleFits
to keep track of suggestions from the hole-fits mechanism, -
ImportSuggestion
for informational messages about whether names are available to be imported from, - ...
-
- A few other new
TcRnMessage
s:-
TcRnRedundantConstraints
, -
TcRnInaccessibleCode
, -
TcRnNotInScope
, -
TcRnUntickedPromotedConstructor
, -
TcRnIllegalBuiltinSyntax
.
-
- A few new
GhcHint
s:-
SuggestDumpSplices
for Template Haskell exact name errors, -
SugestAddTick
, -
SuggestMoveToDeclarationSite
, -
SuggestSimilarNames
, - a slight modification to
SuggestUseTypeFromDataKind
to accomodate other places which printed a similar message.
-
- Two sum types defined in
GHC.Tc.Types.Origin
to avoidSDoc
s,TypeEqThing
andBinderThing
(happy to take suggestions for renaming these, but I do genuinely think it's much better than havingSDoc
s).
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 TcReportMsg
are missing documentation, examples or relevant test cases. -
Some constructors of GhcHint
are 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-boot
and seems to have greatly increased the number of dependencies of the parser. -
Update the notes around StarIsType
inGHC.Types.Name.Reader
. -
Remove the use of TcRnUnknownMessage
inGHC.Rename.HsType
. It callswithHsDocContext
which I wasn't immediately sure how to handle; happy to take suggestions. -
Remove SDoc
fromTcRnIllegalBuiltinSyntax
. -
Remove SDoc
fromMissingBinding
constructor ofNotInScopeError
. -
Remove SDoc
fromUnknownSubordinate
constructor 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