Skip to content

Always use rnImplicitBndrs to bring implicit tyvars into scope

Ryan Scott requested to merge wip/always-use-rnImplicitBndrs into master

This implements a first step towards #16762 (closed) by changing the renamer to always use rnImplicitBndrs to bring implicitly bound type variables into scope. The main change is in rnFamInstEqn and bindHsQTyVars, which previously used ad hoc methods of binding their implicit tyvars.

There are a number of knock-on consequences:

  • One of the reasons that rnFamInstEqn used an ad hoc binding mechanism was to give more precise source locations in -Wunused-type-patterns warnings. (See #16762 (closed) (comment 273343) for an example of this.) However, these warnings are actually a little too precise, since implicitly bound type variables don't have exact binding sites like explicitly bound type variables do. A similar problem existed for "Different names for the same type variable" errors involving implicit tyvars bound by bindHsQTyVars. Therefore, we simply accept the less precise (but more accurate) source locations from rnImplicitBndrs in rnFamInstEqn and bindHsQTyVars. See Note [Source locations for implicitly bound type variables] in GHC.Rename.HsType for the full story.
  • In order for rnImplicitBndrs to work in rnFamInstEqn, it needs to be able to look up names from the parent class (in the event that we are renaming an associated type family instance). As a result, rnImplicitBndrs now takes an argument of type Maybe assoc, which is Just in the event that a type family instance is associated with a class.
  • Previously, GHC kept track of three type synonyms for free type variables in the renamer: FreeKiTyVars, FreeKiTyVarsDups (which are allowed to contain duplicates), and FreeKiTyVarsNoDups (which contain no duplicates). However, making is a distinction between -Dups and -NoDups is now pointless, as all code that returns FreeKiTyVars{,Dups,NoDups} will eventually end up being passed to rnImplicitBndrs, which removes duplicates. As a result, I decided to just get rid of FreeKiTyVarsDups and FreeKiTyVarsNoDups, leaving only FreeKiTyVars.
  • The bindLRdrNames and deleteBys functions are now dead code, so I took the liberty of removing them.
Edited by Ryan Scott

Merge request reports