Skip to content

Several fixes to "unused type variable" error messages in family instances

sheaf requested to merge sheaf/ghc:T23734 into master

This MR consists of four separate commits, all fixing bugs with the behaviour of unused type variables in (type & data) family instances.

  • Commit "Pass quantified tyvars in tcDefaultAssocDecl" fixes #23768 (closed), which means that we now get the appropriate error messages for associated type family default declarations. (We used to pass the wrong set of type variables in that case, which meant we never emitted an error message!).
  • Commit "Adjust reporting of unused tyvars in data FamInsts" fixes #23778 (closed), by changing which variables are considered to be free in the RHS in GHC.Tc.Validity.checkFamPatBinders for data family instances.
  • Commit "Unused tyvars in FamInst: only report user tyvars" fixes #23734 (closed), by keeping track of which type variables were user-written, and only reporting those in the error messages for unused type variables in family instances.
  • Commit "Avoid panic in mkGADTVars" fixes #23784 (closed), by not panicking when we encounter a type variable that is bound by a user-written forall but not actually used in a GADT-syntax data family instance (we will reject the program anyway for other reasons).

A final fifth commit implements some improvements to the error messages, simplifying away some of the complexity surrounding data family instances.

TODO:

  • The commit "Adjust reporting of unused tyvars in data FamInsts" adds a Bool to e.g. CoAxBranch to keep track of which type variables were user-written and which were filled in by the compiler. This is used only for error messages, but it seems this accounting is causing increases in allocations in the compiler, so I should find another way to proceed. Fixed: I refactored validity checking for closed type family equations to mirror associated type family default declarations. This allows us to pass on some information for validity checking without storing any extra information in CoAxBranch.
  • Add a Note explaining the change to the computation of the RHS free type variables for data family instances.
Edited by sheaf

Merge request reports