Draft: Reset solver state on failed defaulting proposal
This MR adds the function GHC.Tc.Solver.Monad.getResetTcSUnifications
which provides a mechanism for resetting any unifications that happened
within a call to solveSimpleWanteds
.
This function is generally useful for GHC API users (e.g. for typechecker plugins that require backtracking), but we also use it when giving up on a defaulting attempt to correctly revert any unification side-effects that might have taken place.
An alternative design, rather than resetting solver state, would be to clone any unfilled metavariables, so that none of the original metavariables ever get touched. However, such an approach does not handle the presence of Given constraints, as one would have to start a new solver run with cloned Givens as well.
TODO:
-
Add documentation to getResetTcSUnifications
. -
Add a Note explaining everything. -
Explain why I had to change substTy
tosubstTyUnchecked
inGHC.Tc.Solver.disambigMultiGroup
.