Note [Add signature contexts as wanteds]
Consider this (#11016): f2 :: (?x :: Int) => _ f2 = ?x or this class C a b | a -> b g :: C p q => p -> q f3 :: C Int b => _ f3 = g (3::Int) We'll use plan InferGen because there are holes in the type. But: * For f2 we want to have the (?x :: Int) constraint floating around so that the functional dependencies kick in. Otherwise the occurrence of ?x on the RHS produces constraint (?x :: alpha), and we won't unify alpha:=Int. * For f3 want the (C Int b) constraint from the partial signature to meet the (C Int beta) constraint we get from the call to g; again, fundeps Solution: in simplifyInfer, we add the constraints from the signature as extra Wanteds. Why Wanteds? Wouldn't it be neater to treat them as Givens? Alas that would mess up (GivenInv) in Note [TcLevel invariants]. Consider f :: (Eq a, _) => blah1 f = ....g... g :: (Eq b, _) => blah2 g = ...f... Then we have two psig_theta constraints (Eq a[tv], Eq b[tv]), both with TyVarTvs inside. Ultimately a[tv] := b[tv], but only when we've solved all those constraints. And both have level 1, so we can't put them as Givens when solving at level 1. Best to treat them as Wanteds. But see also #20076, which would be solved if they were Givens. ************************************************************************ * * Quantification * * ************************************************************************
References 1
- TcLevel invariants GHC.Tc.Utils.TcType
Referenced by 1
- GHC.Tc.Solver call site