Note [When to build an implication]
Suppose we have some 'skolems' and some 'givens', and we are considering whether to wrap the constraints in their scope into an implication. We must /always/ do so if either 'skolems' or 'givens' are non-empty. But what if both are empty? You might think we could always drop the implication. Other things being equal, the fewer implications the better. Less clutter and overhead. But we must take care: * If we have an unsolved [W] g :: a ~# b, and -fdefer-type-errors, we'll make a /term-level/ evidence binding for 'g = error "blah"'. We must have an EvBindsVar those bindings!, otherwise they end up as top-level unlifted bindings, which are verboten. This only matters at top level, so we check for that See also Note [Deferred errors for coercion holes] in GHC.Tc.Errors. cf #14149 for an example of what goes wrong. * This is /necessary/ for top level but may be /desirable/ even for nested bindings, because if the deferred coercion is bound too far out it will be reported even if that thunk (say) is not evaluated. * If you have f :: Int; f = f_blah g :: Bool; g = g_blah If we don't build an implication for f or g (no tyvars, no givens), the constraints for f_blah and g_blah are solved together. And that can yield /very/ confusing error messages, because we can get [W] C Int b1 -- from f_blah [W] C Int b2 -- from g_blan and fundeps can yield [W] b1 ~ b2, even though the two functions have literally nothing to do with each other. #14185 is an example. Building an implication keeps them separate.
References 1
- Deferred errors for coercion holes GHC.Tc.Errors
Referenced by 5
- GHC.Tc.Utils.Unify call site ×3
- Setting the argument context GHC.Tc.Utils.Unify
- Skolemisation overview GHC.Tc.Utils.Unify