Always use rnImplicitBndrs to bring implicit tyvars into scope
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 bybindHsQTyVars
. Therefore, we simply accept the less precise (but more accurate) source locations fromrnImplicitBndrs
inrnFamInstEqn
andbindHsQTyVars
. SeeNote [Source locations for implicitly bound type variables]
inGHC.Rename.HsType
for the full story. - In order for
rnImplicitBndrs
to work inrnFamInstEqn
, 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 typeMaybe assoc
, which isJust
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), andFreeKiTyVarsNoDups
(which contain no duplicates). However, making is a distinction between-Dups
and-NoDups
is now pointless, as all code that returnsFreeKiTyVars{,Dups,NoDups}
will eventually end up being passed tornImplicitBndrs
, which removes duplicates. As a result, I decided to just get rid ofFreeKiTyVarsDups
andFreeKiTyVarsNoDups
, leaving onlyFreeKiTyVars
. - The
bindLRdrNames
anddeleteBys
functions are now dead code, so I took the liberty of removing them.