Note [When superclasses help]
First read Note [The superclass story] in GHC.Tc.Solver.Dict We expand superclasses and iterate only if there is at unsolved wanted for which expansion of superclasses (e.g. from given constraints) might actually help. The function superClassesMightHelp tells if doing this superclass expansion might help solve this constraint. Note that * We look inside implications; maybe it'll help to expand the Givens at level 2 to help solve an unsolved Wanted buried inside an implication. E.g. forall a. Ord a => forall b. [W] Eq a * We say "no" for implicit parameters. we have [W] ?x::ty, expanding superclasses won't help: - Superclasses can't be implicit parameters - If we have a [G] ?x:ty2, then we'll have another unsolved [W] ty ~ ty2 (from the functional dependency) which will trigger superclass expansion. It's a bit of a special case, but it's easy to do. The runtime cost is low because the unsolved set is usually empty anyway (errors aside), and the first non-implicit-parameter will terminate the search. The special case is worth it (#11480, comment:2) because it applies to CallStack constraints, which aren't type errors. If we have f :: (C a) => blah f x = ...undefined... we'll get a CallStack constraint. If that's the only unsolved constraint it'll eventually be solved by defaulting. So we don't want to emit warnings about hitting the simplifier's iteration limit. A CallStack constraint really isn't an unsolved constraint; it can always be solved by defaulting.
References 1
- The superclass story GHC.Tc.Solver.Dict
Referenced by 2
- The superclass story GHC.Tc.Solver.Dict
- GHC.Tc.Types.Constraint call site