+-- |All free meta type variables *including* the coercion variables of
+-- equalities
+--
+tcTyVarsOfInst :: Inst -> TyVarSet
+tcTyVarsOfInst (LitInst {tci_ty = ty}) = tcTyVarsOfType ty
+tcTyVarsOfInst (Dict {tci_pred = pred}) = tcTyVarsOfPred pred
+tcTyVarsOfInst (Method {tci_oid = id, tci_tys = tys})
+ = tcTyVarsOfTypes tys `unionVarSet` varTypeTcTyVars id
+ -- The id might have free type variables; in the case of
+ -- locally-overloaded class methods, for example
+tcTyVarsOfInst (ImplicInst {tci_tyvars = tvs, tci_given = givens,
+ tci_wanted = wanteds})
+ = (tcTyVarsOfInsts givens `unionVarSet` tcTyVarsOfInsts wanteds)
+ `minusVarSet` mkVarSet tvs
+ `unionVarSet` unionVarSets (map varTypeTcTyVars tvs)
+ -- Remember the free tyvars of a coercion
+tcTyVarsOfInst (EqInst {tci_co = co, tci_left = ty1, tci_right = ty2})
+ = either unitVarSet tcTyVarsOfType co `unionVarSet` -- include covars
+ tcTyVarsOfType ty1 `unionVarSet` tcTyVarsOfType ty2
+
+tyVarsOfInsts :: [Inst] -> TyVarSet