Refactor solver to leave breadcrumbs
Today, the solver works hard to find how givens can imply wanteds. If it fails, it exits with unsolved wanteds. These wanteds are then scrutinized carefully in the TcErrors module in order to produce nice, user-readable error messages. However, the current design means that TcErrors needs to do much work trying to analyze the tea leaves that the solver has left behind. That is, it must reconstruct why a constraint was failed to be solved. This involves some duplicate code and duplicate work (such as looking in instance environments).
Instead, we can imagine a structure, stored within a CtLoc
, that records the solver's movements, including movements it failed to make (such as "tried to unify, but hit an occurs-check failure"). This structure could then be consumed in TcErrors. Effectively, this means that the solver could more directly communicate with users and explain its reasoning. We might also imagine a future where users can query GHC for information about even type-correct programs.
This ticket is to track this refactoring opportunity.